Passed
Push — master ( 3b5782...9f8a09 )
by Brian
186:14 queued 100:17
created
ayecode/wp-ayecode-ui/includes/components/class-aui-component-input.php 3 patches
Indentation   +871 added lines, -871 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if ( ! defined( 'ABSPATH' ) ) {
4
-	exit; // Exit if accessed directly
4
+    exit; // Exit if accessed directly
5 5
 }
6 6
 
7 7
 /**
@@ -11,238 +11,238 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class AUI_Component_Input {
13 13
 
14
-	/**
15
-	 * Build the component.
16
-	 *
17
-	 * @param array $args
18
-	 *
19
-	 * @return string The rendered component.
20
-	 */
21
-	public static function input($args = array()){
22
-		$defaults = array(
23
-			'type'       => 'text',
24
-			'name'       => '',
25
-			'class'      => '',
26
-			'id'         => '',
27
-			'placeholder'=> '',
28
-			'title'      => '',
29
-			'value'      => '',
30
-			'required'   => false,
31
-			'label'      => '',
32
-			'label_after'=> false,
33
-			'label_class'=> '',
34
-			'label_type' => '', // sets the lable type, horizontal
35
-			'help_text'  => '',
36
-			'validation_text'   => '',
37
-			'validation_pattern' => '',
38
-			'no_wrap'    => false,
39
-			'input_group_right' => '',
40
-			'input_group_left' => '',
41
-			'input_group_right_inside' => false, // forces the input group inside the input
42
-			'input_group_left_inside' => false, // forces the input group inside the input
43
-			'step'       => '',
44
-			'switch'     => false, // to show checkbox as a switch
45
-			'checked'   => false, // set a checkbox or radio as selected
46
-			'password_toggle' => true, // toggle view/hide password
47
-			'extra_attributes'  => array() // an array of extra attributes
48
-		);
49
-
50
-		/**
51
-		 * Parse incoming $args into an array and merge it with $defaults
52
-		 */
53
-		$args   = wp_parse_args( $args, $defaults );
54
-		$output = '';
55
-		if ( ! empty( $args['type'] ) ) {
56
-			$type = sanitize_html_class( $args['type'] );
57
-
58
-			$help_text = '';
59
-			$label = '';
60
-			$label_after = $args['label_after'];
61
-			$label_args = array(
62
-				'title'=> $args['label'],
63
-				'for'=> $args['id'],
64
-				'class' => $args['label_class']." ",
65
-				'label_type' => $args['label_type']
66
-			);
67
-
68
-			// Some special sauce for files
69
-			if($type=='file' ){
70
-				$label_after = true; // if type file we need the label after
71
-				$args['class'] .= ' custom-file-input ';
72
-			}elseif($type=='checkbox'){
73
-				$label_after = true; // if type file we need the label after
74
-				$args['class'] .= ' custom-control-input ';
75
-			}elseif($type=='datepicker' || $type=='timepicker'){
76
-				$type = 'text';
77
-				$args['class'] .= ' aui-flatpickr bg-initial ';
78
-
79
-				// enqueue the script
80
-				$aui_settings = AyeCode_UI_Settings::instance();
81
-				$aui_settings->enqueue_flatpickr();
82
-			}
83
-
84
-
85
-			// open/type
86
-			$output .= '<input type="' . $type . '" ';
87
-
88
-			// name
89
-			if(!empty($args['name'])){
90
-				$output .= ' name="'.esc_attr($args['name']).'" ';
91
-			}
92
-
93
-			// id
94
-			if(!empty($args['id'])){
95
-				$output .= ' id="'.sanitize_html_class($args['id']).'" ';
96
-			}
97
-
98
-			// placeholder
99
-			if(!empty($args['placeholder'])){
100
-				$output .= ' placeholder="'.esc_attr($args['placeholder']).'" ';
101
-			}
102
-
103
-			// title
104
-			if(!empty($args['title'])){
105
-				$output .= ' title="'.esc_attr($args['title']).'" ';
106
-			}
107
-
108
-			// value
109
-			if(!empty($args['value'])){
110
-				$output .= ' value="'.sanitize_text_field($args['value']).'" ';
111
-			}
112
-
113
-			// checked, for radio and checkboxes
114
-			if( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ){
115
-				$output .= ' checked ';
116
-			}
117
-
118
-			// validation text
119
-			if(!empty($args['validation_text'])){
120
-				$output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" ';
121
-				$output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" ';
122
-			}
123
-
124
-			// validation_pattern
125
-			if(!empty($args['validation_pattern'])){
126
-				$output .= ' pattern="'.$args['validation_pattern'].'" ';
127
-			}
128
-
129
-			// step (for numbers)
130
-			if(!empty($args['step'])){
131
-				$output .= ' step="'.$args['step'].'" ';
132
-			}
133
-
134
-			// required
135
-			if(!empty($args['required'])){
136
-				$output .= ' required ';
137
-			}
138
-
139
-			// class
140
-			$class = !empty($args['class']) ? $args['class'] : '';
141
-			$output .= ' class="form-control '.$class.'" ';
142
-
143
-			// data-attributes
144
-			$output .= AUI_Component_Helper::data_attributes($args);
145
-
146
-			// extra attributes
147
-			if(!empty($args['extra_attributes'])){
148
-				$output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']);
149
-			}
150
-
151
-			// close
152
-			$output .= ' >';
153
-
154
-
155
-			// label
156
-			if(!empty($args['label'])){
157
-				if($type == 'file'){$label_args['class'] .= 'custom-file-label';}
158
-				elseif($type == 'checkbox'){$label_args['class'] .= 'custom-control-label';}
159
-				$label = self::label( $label_args, $type );
160
-			}
161
-
162
-			// help text
163
-			if(!empty($args['help_text'])){
164
-				$help_text = AUI_Component_Helper::help_text($args['help_text']);
165
-			}
166
-
167
-
168
-			// set help text in the correct possition
169
-			if($label_after){
170
-				$output .= $label . $help_text;
171
-			}
172
-
173
-
174
-
14
+    /**
15
+     * Build the component.
16
+     *
17
+     * @param array $args
18
+     *
19
+     * @return string The rendered component.
20
+     */
21
+    public static function input($args = array()){
22
+        $defaults = array(
23
+            'type'       => 'text',
24
+            'name'       => '',
25
+            'class'      => '',
26
+            'id'         => '',
27
+            'placeholder'=> '',
28
+            'title'      => '',
29
+            'value'      => '',
30
+            'required'   => false,
31
+            'label'      => '',
32
+            'label_after'=> false,
33
+            'label_class'=> '',
34
+            'label_type' => '', // sets the lable type, horizontal
35
+            'help_text'  => '',
36
+            'validation_text'   => '',
37
+            'validation_pattern' => '',
38
+            'no_wrap'    => false,
39
+            'input_group_right' => '',
40
+            'input_group_left' => '',
41
+            'input_group_right_inside' => false, // forces the input group inside the input
42
+            'input_group_left_inside' => false, // forces the input group inside the input
43
+            'step'       => '',
44
+            'switch'     => false, // to show checkbox as a switch
45
+            'checked'   => false, // set a checkbox or radio as selected
46
+            'password_toggle' => true, // toggle view/hide password
47
+            'extra_attributes'  => array() // an array of extra attributes
48
+        );
49
+
50
+        /**
51
+         * Parse incoming $args into an array and merge it with $defaults
52
+         */
53
+        $args   = wp_parse_args( $args, $defaults );
54
+        $output = '';
55
+        if ( ! empty( $args['type'] ) ) {
56
+            $type = sanitize_html_class( $args['type'] );
57
+
58
+            $help_text = '';
59
+            $label = '';
60
+            $label_after = $args['label_after'];
61
+            $label_args = array(
62
+                'title'=> $args['label'],
63
+                'for'=> $args['id'],
64
+                'class' => $args['label_class']." ",
65
+                'label_type' => $args['label_type']
66
+            );
67
+
68
+            // Some special sauce for files
69
+            if($type=='file' ){
70
+                $label_after = true; // if type file we need the label after
71
+                $args['class'] .= ' custom-file-input ';
72
+            }elseif($type=='checkbox'){
73
+                $label_after = true; // if type file we need the label after
74
+                $args['class'] .= ' custom-control-input ';
75
+            }elseif($type=='datepicker' || $type=='timepicker'){
76
+                $type = 'text';
77
+                $args['class'] .= ' aui-flatpickr bg-initial ';
78
+
79
+                // enqueue the script
80
+                $aui_settings = AyeCode_UI_Settings::instance();
81
+                $aui_settings->enqueue_flatpickr();
82
+            }
83
+
84
+
85
+            // open/type
86
+            $output .= '<input type="' . $type . '" ';
87
+
88
+            // name
89
+            if(!empty($args['name'])){
90
+                $output .= ' name="'.esc_attr($args['name']).'" ';
91
+            }
92
+
93
+            // id
94
+            if(!empty($args['id'])){
95
+                $output .= ' id="'.sanitize_html_class($args['id']).'" ';
96
+            }
97
+
98
+            // placeholder
99
+            if(!empty($args['placeholder'])){
100
+                $output .= ' placeholder="'.esc_attr($args['placeholder']).'" ';
101
+            }
102
+
103
+            // title
104
+            if(!empty($args['title'])){
105
+                $output .= ' title="'.esc_attr($args['title']).'" ';
106
+            }
107
+
108
+            // value
109
+            if(!empty($args['value'])){
110
+                $output .= ' value="'.sanitize_text_field($args['value']).'" ';
111
+            }
112
+
113
+            // checked, for radio and checkboxes
114
+            if( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ){
115
+                $output .= ' checked ';
116
+            }
117
+
118
+            // validation text
119
+            if(!empty($args['validation_text'])){
120
+                $output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" ';
121
+                $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" ';
122
+            }
123
+
124
+            // validation_pattern
125
+            if(!empty($args['validation_pattern'])){
126
+                $output .= ' pattern="'.$args['validation_pattern'].'" ';
127
+            }
128
+
129
+            // step (for numbers)
130
+            if(!empty($args['step'])){
131
+                $output .= ' step="'.$args['step'].'" ';
132
+            }
133
+
134
+            // required
135
+            if(!empty($args['required'])){
136
+                $output .= ' required ';
137
+            }
138
+
139
+            // class
140
+            $class = !empty($args['class']) ? $args['class'] : '';
141
+            $output .= ' class="form-control '.$class.'" ';
142
+
143
+            // data-attributes
144
+            $output .= AUI_Component_Helper::data_attributes($args);
145
+
146
+            // extra attributes
147
+            if(!empty($args['extra_attributes'])){
148
+                $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']);
149
+            }
150
+
151
+            // close
152
+            $output .= ' >';
153
+
154
+
155
+            // label
156
+            if(!empty($args['label'])){
157
+                if($type == 'file'){$label_args['class'] .= 'custom-file-label';}
158
+                elseif($type == 'checkbox'){$label_args['class'] .= 'custom-control-label';}
159
+                $label = self::label( $label_args, $type );
160
+            }
161
+
162
+            // help text
163
+            if(!empty($args['help_text'])){
164
+                $help_text = AUI_Component_Helper::help_text($args['help_text']);
165
+            }
166
+
167
+
168
+            // set help text in the correct possition
169
+            if($label_after){
170
+                $output .= $label . $help_text;
171
+            }
172
+
173
+
174
+
175 175
 
176 176
 
177
-			// some input types need a separate wrap
178
-			if($type == 'file') {
179
-				$output = self::wrap( array(
180
-					'content' => $output,
181
-					'class'   => 'form-group custom-file'
182
-				) );
183
-			}elseif($type == 'checkbox'){
184
-				$wrap_class = $args['switch'] ? 'custom-switch' : 'custom-checkbox';
185
-				$output = self::wrap( array(
186
-					'content' => $output,
187
-					'class'   => 'custom-control '.$wrap_class
188
-				) );
189
-
190
-				if($args['label_type']=='horizontal'){
191
-					$output = '<div class="col-sm-2 col-form-label"></div><div class="col-sm-10">' . $output . '</div>';
192
-				}
193
-			}elseif($type == 'password' && $args['password_toggle'] && !$args['input_group_right']){
194
-
177
+            // some input types need a separate wrap
178
+            if($type == 'file') {
179
+                $output = self::wrap( array(
180
+                    'content' => $output,
181
+                    'class'   => 'form-group custom-file'
182
+                ) );
183
+            }elseif($type == 'checkbox'){
184
+                $wrap_class = $args['switch'] ? 'custom-switch' : 'custom-checkbox';
185
+                $output = self::wrap( array(
186
+                    'content' => $output,
187
+                    'class'   => 'custom-control '.$wrap_class
188
+                ) );
189
+
190
+                if($args['label_type']=='horizontal'){
191
+                    $output = '<div class="col-sm-2 col-form-label"></div><div class="col-sm-10">' . $output . '</div>';
192
+                }
193
+            }elseif($type == 'password' && $args['password_toggle'] && !$args['input_group_right']){
194
+
195 195
 
196
-				// allow password field to toggle view
197
-				$args['input_group_right'] = '<span class="input-group-text c-pointer px-3" 
196
+                // allow password field to toggle view
197
+                $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" 
198 198
 onclick="var $el = jQuery(this).find(\'i\');$el.toggleClass(\'fa-eye fa-eye-slash\');
199 199
 var $eli = jQuery(this).parent().parent().find(\'input\');
200 200
 if($el.hasClass(\'fa-eye\'))
201 201
 {$eli.attr(\'type\',\'text\');}
202 202
 else{$eli.attr(\'type\',\'password\');}"
203 203
 ><i class="far fa-fw fa-eye-slash"></i></span>';
204
-			}
205
-
206
-			// input group wraps
207
-			if($args['input_group_left'] || $args['input_group_right']){
208
-				$w100 = strpos($args['class'], 'w-100') !== false ? ' w-100' : '';
209
-				if($args['input_group_left']){
210
-					$output = self::wrap( array(
211
-						'content' => $output,
212
-						'class'   => $args['input_group_left_inside'] ? 'input-group-inside'.$w100  : 'input-group',
213
-						'input_group_left' => $args['input_group_left'],
214
-						'input_group_left_inside'    => $args['input_group_left_inside']
215
-					) );
216
-				}
217
-				if($args['input_group_right']){
218
-					$output = self::wrap( array(
219
-						'content' => $output,
220
-						'class'   => $args['input_group_right_inside'] ? 'input-group-inside'.$w100 : 'input-group',
221
-						'input_group_right' => $args['input_group_right'],
222
-						'input_group_right_inside'    => $args['input_group_right_inside']
223
-					) );
224
-				}
225
-
226
-				// Labels need to be on the outside of the wrap
204
+            }
205
+
206
+            // input group wraps
207
+            if($args['input_group_left'] || $args['input_group_right']){
208
+                $w100 = strpos($args['class'], 'w-100') !== false ? ' w-100' : '';
209
+                if($args['input_group_left']){
210
+                    $output = self::wrap( array(
211
+                        'content' => $output,
212
+                        'class'   => $args['input_group_left_inside'] ? 'input-group-inside'.$w100  : 'input-group',
213
+                        'input_group_left' => $args['input_group_left'],
214
+                        'input_group_left_inside'    => $args['input_group_left_inside']
215
+                    ) );
216
+                }
217
+                if($args['input_group_right']){
218
+                    $output = self::wrap( array(
219
+                        'content' => $output,
220
+                        'class'   => $args['input_group_right_inside'] ? 'input-group-inside'.$w100 : 'input-group',
221
+                        'input_group_right' => $args['input_group_right'],
222
+                        'input_group_right_inside'    => $args['input_group_right_inside']
223
+                    ) );
224
+                }
225
+
226
+                // Labels need to be on the outside of the wrap
227 227
 //				$label = self::label( $label_args, $type );
228 228
 //				$output = $label . str_replace($label,"",$output);
229
-			}
229
+            }
230 230
 
231
-			if(!$label_after){
232
-				$output .= $help_text;
233
-			}
231
+            if(!$label_after){
232
+                $output .= $help_text;
233
+            }
234 234
 
235 235
 
236
-			if($args['label_type']=='horizontal' && $type != 'checkbox'){
237
-				$output = self::wrap( array(
238
-					'content' => $output,
239
-					'class'   => 'col-sm-10',
240
-				) );
241
-			}
236
+            if($args['label_type']=='horizontal' && $type != 'checkbox'){
237
+                $output = self::wrap( array(
238
+                    'content' => $output,
239
+                    'class'   => 'col-sm-10',
240
+                ) );
241
+            }
242 242
 
243
-			if(!$label_after){
244
-				$output = $label . $output;
245
-			}
243
+            if(!$label_after){
244
+                $output = $label . $output;
245
+            }
246 246
 
247 247
 //			// maybe horizontal label
248 248
 //			if($args['label_type']=='horizontal' && $type != 'checkbox'){
@@ -253,662 +253,662 @@  discard block
 block discarded – undo
253 253
 //				$output .= '</div>';
254 254
 //			}
255 255
 
256
-			// wrap
257
-			if(!$args['no_wrap']){
258
-				$wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group';
259
-				$output = self::wrap(array(
260
-					'content' => $output,
261
-					'class'   => $wrap_class,
262
-				));
263
-			}
264
-
265
-
266
-
267
-		}
268
-
269
-		return $output;
270
-	}
271
-
272
-	/**
273
-	 * Build the component.
274
-	 *
275
-	 * @param array $args
276
-	 *
277
-	 * @return string The rendered component.
278
-	 */
279
-	public static function textarea($args = array()){
280
-		$defaults = array(
281
-			'name'       => '',
282
-			'class'      => '',
283
-			'id'         => '',
284
-			'placeholder'=> '',
285
-			'title'      => '',
286
-			'value'      => '',
287
-			'required'   => false,
288
-			'label'      => '',
289
-			'label_class'      => '',
290
-			'label_type' => '', // sets the lable type, horizontal
291
-			'help_text'  => '',
292
-			'validation_text'   => '',
293
-			'validation_pattern' => '',
294
-			'no_wrap'    => false,
295
-			'rows'      => '',
296
-			'wysiwyg'   => false,
297
-		);
298
-
299
-		/**
300
-		 * Parse incoming $args into an array and merge it with $defaults
301
-		 */
302
-		$args   = wp_parse_args( $args, $defaults );
303
-		$output = '';
304
-
305
-		// label
306
-		if(!empty($args['label']) && is_array($args['label'])){
307
-		}elseif(!empty($args['label'])){
308
-			$label_args = array(
309
-				'title'=> $args['label'],
310
-				'for'=> $args['id'],
311
-				'class' => $args['label_class']." ",
312
-				'label_type' => $args['label_type']
313
-			);
314
-			$output .= self::label( $label_args );
315
-		}
316
-
317
-		// maybe horizontal label
318
-		if($args['label_type']=='horizontal'){
319
-			$output .= '<div class="col-sm-10">';
320
-		}
321
-
322
-		if(!empty($args['wysiwyg'])){
323
-			ob_start();
324
-			$content = $args['value'];
325
-			$editor_id = !empty($args['id']) ? sanitize_html_class($args['id']) : 'wp_editor';
326
-			$settings = array(
327
-				'textarea_rows' => !empty(absint($args['rows'])) ? absint($args['rows']) : 4,
328
-				'quicktags'     => false,
329
-				'media_buttons' => false,
330
-				'editor_class'  => 'form-control',
331
-				'textarea_name' => !empty($args['name']) ? sanitize_html_class($args['name']) : sanitize_html_class($args['id']),
332
-				'teeny'         => true,
333
-			);
334
-
335
-			// maybe set settings if array
336
-			if(is_array($args['wysiwyg'])){
337
-				$settings  = wp_parse_args( $args['wysiwyg'], $settings );
338
-			}
339
-
340
-			wp_editor( $content, $editor_id, $settings );
341
-			$output .= ob_get_clean();
342
-		}else{
343
-
344
-			// open
345
-			$output .= '<textarea ';
346
-
347
-			// name
348
-			if(!empty($args['name'])){
349
-				$output .= ' name="'.sanitize_html_class($args['name']).'" ';
350
-			}
351
-
352
-			// id
353
-			if(!empty($args['id'])){
354
-				$output .= ' id="'.sanitize_html_class($args['id']).'" ';
355
-			}
356
-
357
-			// placeholder
358
-			if(!empty($args['placeholder'])){
359
-				$output .= ' placeholder="'.esc_attr($args['placeholder']).'" ';
360
-			}
361
-
362
-			// title
363
-			if(!empty($args['title'])){
364
-				$output .= ' title="'.esc_attr($args['title']).'" ';
365
-			}
366
-
367
-			// validation text
368
-			if(!empty($args['validation_text'])){
369
-				$output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" ';
370
-				$output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" ';
371
-			}
372
-
373
-			// validation_pattern
374
-			if(!empty($args['validation_pattern'])){
375
-				$output .= ' pattern="'.$args['validation_pattern'].'" ';
376
-			}
377
-
378
-			// required
379
-			if(!empty($args['required'])){
380
-				$output .= ' required ';
381
-			}
382
-
383
-			// rows
384
-			if(!empty($args['rows'])){
385
-				$output .= ' rows="'.absint($args['rows']).'" ';
386
-			}
387
-
388
-
389
-			// class
390
-			$class = !empty($args['class']) ? $args['class'] : '';
391
-			$output .= ' class="form-control '.$class.'" ';
392
-
393
-
394
-			// close tag
395
-			$output .= ' >';
396
-
397
-			// value
398
-			if(!empty($args['value'])){
399
-				$output .= sanitize_textarea_field($args['value']);
400
-			}
401
-
402
-			// closing tag
403
-			$output .= '</textarea>';
404
-
405
-		}
406
-
407
-		// help text
408
-		if(!empty($args['help_text'])){
409
-			$output .= AUI_Component_Helper::help_text($args['help_text']);
410
-		}
411
-
412
-		// maybe horizontal label
413
-		if($args['label_type']=='horizontal'){
414
-			$output .= '</div>';
415
-		}
416
-
417
-
418
-		// wrap
419
-		if(!$args['no_wrap']){
420
-			$wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group';
421
-			$output = self::wrap(array(
422
-				'content' => $output,
423
-				'class'   => $wrap_class,
424
-			));
425
-		}
426
-
427
-
428
-		return $output;
429
-	}
430
-
431
-	public static function label($args = array(), $type = ''){
432
-		//<label for="exampleInputEmail1">Email address</label>
433
-		$defaults = array(
434
-			'title'       => 'div',
435
-			'for'      => '',
436
-			'class'      => '',
437
-			'label_type'    => '', // horizontal
438
-		);
256
+            // wrap
257
+            if(!$args['no_wrap']){
258
+                $wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group';
259
+                $output = self::wrap(array(
260
+                    'content' => $output,
261
+                    'class'   => $wrap_class,
262
+                ));
263
+            }
264
+
265
+
266
+
267
+        }
268
+
269
+        return $output;
270
+    }
271
+
272
+    /**
273
+     * Build the component.
274
+     *
275
+     * @param array $args
276
+     *
277
+     * @return string The rendered component.
278
+     */
279
+    public static function textarea($args = array()){
280
+        $defaults = array(
281
+            'name'       => '',
282
+            'class'      => '',
283
+            'id'         => '',
284
+            'placeholder'=> '',
285
+            'title'      => '',
286
+            'value'      => '',
287
+            'required'   => false,
288
+            'label'      => '',
289
+            'label_class'      => '',
290
+            'label_type' => '', // sets the lable type, horizontal
291
+            'help_text'  => '',
292
+            'validation_text'   => '',
293
+            'validation_pattern' => '',
294
+            'no_wrap'    => false,
295
+            'rows'      => '',
296
+            'wysiwyg'   => false,
297
+        );
298
+
299
+        /**
300
+         * Parse incoming $args into an array and merge it with $defaults
301
+         */
302
+        $args   = wp_parse_args( $args, $defaults );
303
+        $output = '';
304
+
305
+        // label
306
+        if(!empty($args['label']) && is_array($args['label'])){
307
+        }elseif(!empty($args['label'])){
308
+            $label_args = array(
309
+                'title'=> $args['label'],
310
+                'for'=> $args['id'],
311
+                'class' => $args['label_class']." ",
312
+                'label_type' => $args['label_type']
313
+            );
314
+            $output .= self::label( $label_args );
315
+        }
316
+
317
+        // maybe horizontal label
318
+        if($args['label_type']=='horizontal'){
319
+            $output .= '<div class="col-sm-10">';
320
+        }
321
+
322
+        if(!empty($args['wysiwyg'])){
323
+            ob_start();
324
+            $content = $args['value'];
325
+            $editor_id = !empty($args['id']) ? sanitize_html_class($args['id']) : 'wp_editor';
326
+            $settings = array(
327
+                'textarea_rows' => !empty(absint($args['rows'])) ? absint($args['rows']) : 4,
328
+                'quicktags'     => false,
329
+                'media_buttons' => false,
330
+                'editor_class'  => 'form-control',
331
+                'textarea_name' => !empty($args['name']) ? sanitize_html_class($args['name']) : sanitize_html_class($args['id']),
332
+                'teeny'         => true,
333
+            );
334
+
335
+            // maybe set settings if array
336
+            if(is_array($args['wysiwyg'])){
337
+                $settings  = wp_parse_args( $args['wysiwyg'], $settings );
338
+            }
339
+
340
+            wp_editor( $content, $editor_id, $settings );
341
+            $output .= ob_get_clean();
342
+        }else{
343
+
344
+            // open
345
+            $output .= '<textarea ';
346
+
347
+            // name
348
+            if(!empty($args['name'])){
349
+                $output .= ' name="'.sanitize_html_class($args['name']).'" ';
350
+            }
351
+
352
+            // id
353
+            if(!empty($args['id'])){
354
+                $output .= ' id="'.sanitize_html_class($args['id']).'" ';
355
+            }
356
+
357
+            // placeholder
358
+            if(!empty($args['placeholder'])){
359
+                $output .= ' placeholder="'.esc_attr($args['placeholder']).'" ';
360
+            }
361
+
362
+            // title
363
+            if(!empty($args['title'])){
364
+                $output .= ' title="'.esc_attr($args['title']).'" ';
365
+            }
366
+
367
+            // validation text
368
+            if(!empty($args['validation_text'])){
369
+                $output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" ';
370
+                $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" ';
371
+            }
372
+
373
+            // validation_pattern
374
+            if(!empty($args['validation_pattern'])){
375
+                $output .= ' pattern="'.$args['validation_pattern'].'" ';
376
+            }
377
+
378
+            // required
379
+            if(!empty($args['required'])){
380
+                $output .= ' required ';
381
+            }
382
+
383
+            // rows
384
+            if(!empty($args['rows'])){
385
+                $output .= ' rows="'.absint($args['rows']).'" ';
386
+            }
387
+
388
+
389
+            // class
390
+            $class = !empty($args['class']) ? $args['class'] : '';
391
+            $output .= ' class="form-control '.$class.'" ';
392
+
393
+
394
+            // close tag
395
+            $output .= ' >';
396
+
397
+            // value
398
+            if(!empty($args['value'])){
399
+                $output .= sanitize_textarea_field($args['value']);
400
+            }
401
+
402
+            // closing tag
403
+            $output .= '</textarea>';
404
+
405
+        }
406
+
407
+        // help text
408
+        if(!empty($args['help_text'])){
409
+            $output .= AUI_Component_Helper::help_text($args['help_text']);
410
+        }
411
+
412
+        // maybe horizontal label
413
+        if($args['label_type']=='horizontal'){
414
+            $output .= '</div>';
415
+        }
416
+
417
+
418
+        // wrap
419
+        if(!$args['no_wrap']){
420
+            $wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group';
421
+            $output = self::wrap(array(
422
+                'content' => $output,
423
+                'class'   => $wrap_class,
424
+            ));
425
+        }
426
+
427
+
428
+        return $output;
429
+    }
430
+
431
+    public static function label($args = array(), $type = ''){
432
+        //<label for="exampleInputEmail1">Email address</label>
433
+        $defaults = array(
434
+            'title'       => 'div',
435
+            'for'      => '',
436
+            'class'      => '',
437
+            'label_type'    => '', // horizontal
438
+        );
439 439
 
440
-		/**
441
-		 * Parse incoming $args into an array and merge it with $defaults
442
-		 */
443
-		$args   = wp_parse_args( $args, $defaults );
444
-		$output = '';
440
+        /**
441
+         * Parse incoming $args into an array and merge it with $defaults
442
+         */
443
+        $args   = wp_parse_args( $args, $defaults );
444
+        $output = '';
445 445
 
446
-		if($args['title']){
446
+        if($args['title']){
447 447
 
448
-			// maybe hide labels //@todo set a global option for visibility class
449
-			if($type == 'file' || $type == 'checkbox' || $type == 'radio' || !empty($args['label_type']) ){
450
-				$class = $args['class'];
451
-			}else{
452
-				$class = 'sr-only '.$args['class'];
453
-			}
448
+            // maybe hide labels //@todo set a global option for visibility class
449
+            if($type == 'file' || $type == 'checkbox' || $type == 'radio' || !empty($args['label_type']) ){
450
+                $class = $args['class'];
451
+            }else{
452
+                $class = 'sr-only '.$args['class'];
453
+            }
454 454
 
455
-			// maybe horizontal
456
-			if($args['label_type']=='horizontal' && $type != 'checkbox'){
457
-				$class .= ' col-sm-2 col-form-label';
458
-			}
459
-
460
-			// open
461
-			$output .= '<label ';
462
-
463
-			// for
464
-			if(!empty($args['for'])){
465
-				$output .= ' for="'.sanitize_text_field($args['for']).'" ';
466
-			}
467
-
468
-			// class
469
-			$output .= ' class="'.$class.'" ';
470
-
471
-			// close
472
-			$output .= '>';
473
-
474
-
475
-			// title, don't escape fully as can contain html
476
-			if(!empty($args['title'])){
477
-				$output .= wp_kses_post($args['title']);
478
-			}
479
-
480
-			// close wrap
481
-			$output .= '</label>';
482
-
483
-
484
-		}
485
-
486
-
487
-		return $output;
488
-	}
489
-
490
-	public static function wrap($args = array()){
491
-		$defaults = array(
492
-			'type'       => 'div',
493
-			'class'      => 'form-group',
494
-			'content'   => '',
495
-			'input_group_left' => '',
496
-			'input_group_right' => '',
497
-			'input_group_left_inside' => false,
498
-			'input_group_right_inside' => false,
499
-		);
500
-
501
-		/**
502
-		 * Parse incoming $args into an array and merge it with $defaults
503
-		 */
504
-		$args   = wp_parse_args( $args, $defaults );
505
-		$output = '';
506
-		if($args['type']){
507
-
508
-			// open
509
-			$output .= '<'.sanitize_html_class($args['type']);
510
-
511
-			// class
512
-			$class = !empty($args['class']) ? $args['class'] : '';
513
-			$output .= ' class="'.$class.'" ';
514
-
515
-			// close wrap
516
-			$output .= ' >';
517
-
518
-
519
-			// Input group left
520
-			if(!empty($args['input_group_left'])){
521
-				$position_class = !empty($args['input_group_left_inside']) ? 'position-absolute' : '';
522
-				$input_group_left = strpos($args['input_group_left'], '<') !== false ? $args['input_group_left'] : '<span class="input-group-text">'.$args['input_group_left'].'</span>';
523
-				$output .= '<div class="input-group-prepend '.$position_class.'">'.$input_group_left.'</div>';
524
-			}
525
-
526
-			// content
527
-			$output .= $args['content'];
528
-
529
-			// Input group right
530
-			if(!empty($args['input_group_right'])){
531
-				$position_class = !empty($args['input_group_left_inside']) ? 'position-absolute' : '';
532
-				$input_group_right = strpos($args['input_group_right'], '<') !== false ? $args['input_group_right'] : '<span class="input-group-text">'.$args['input_group_right'].'</span>';
533
-				$output .= '<div class="input-group-append '.$position_class.'">'.$input_group_right.'</div>';
534
-			}
535
-
536
-
537
-			// close wrap
538
-			$output .= '</'.sanitize_html_class($args['type']).'>';
539
-
540
-
541
-		}else{
542
-			$output = $args['content'];
543
-		}
544
-
545
-		return $output;
546
-	}
547
-
548
-	/**
549
-	 * Build the component.
550
-	 *
551
-	 * @param array $args
552
-	 *
553
-	 * @return string The rendered component.
554
-	 */
555
-	public static function select($args = array()){
556
-		$defaults = array(
557
-			'class'      => '',
558
-			'id'         => '',
559
-			'title'      => '',
560
-			'value'      => '', // can be an array or a string
561
-			'required'   => false,
562
-			'label'      => '',
563
-			'label_class'      => '',
564
-			'label_type' => '', // sets the lable type, horizontal
565
-			'help_text'  => '',
566
-			'placeholder'=> '',
567
-			'options'    => array(),
568
-			'icon'       => '',
569
-			'multiple'   => false,
570
-			'select2'    => false,
571
-			'no_wrap'    => false,
572
-			'extra_attributes'  => array() // an array of extra attributes
573
-		);
574
-
575
-		/**
576
-		 * Parse incoming $args into an array and merge it with $defaults
577
-		 */
578
-		$args   = wp_parse_args( $args, $defaults );
579
-		$output = '';
580
-
581
-		// Maybe setup select2
582
-		$is_select2 = false;
583
-		if(!empty($args['select2'])){
584
-			$args['class'] .= ' aui-select2';
585
-			$is_select2 = true;
586
-		}elseif( strpos($args['class'], 'aui-select2') !== false){
587
-			$is_select2 = true;
588
-		}
589
-
590
-		// select2 tags
591
-		if( !empty($args['select2']) && $args['select2'] === 'tags'){ // triple equlas needed here for some reason
592
-			$args['data-tags'] = 'true';
593
-			$args['data-token-separators'] = "[',']";
594
-			$args['multiple'] = true;
595
-		}
596
-
597
-		// select2 placeholder
598
-		if($is_select2 && !empty($args['placeholder']) && empty($args['data-placeholder'])){
599
-			$args['data-placeholder'] = esc_attr($args['placeholder']);
600
-			$args['data-allow-clear'] = empty($args['data-allow-clear']) ? true : esc_attr($args['data-allow-clear']);
601
-		}
602
-
603
-		// label
604
-		if(!empty($args['label']) && is_array($args['label'])){
605
-		}elseif(!empty($args['label'])){
606
-			$label_args = array(
607
-				'title'=> $args['label'],
608
-				'for'=> $args['id'],
609
-				'class' => $args['label_class']." ",
610
-				'label_type' => $args['label_type']
611
-			);
612
-			$output .= self::label($label_args);
613
-		}
614
-
615
-		// maybe horizontal label
616
-		if($args['label_type']=='horizontal'){
617
-			$output .= '<div class="col-sm-10">';
618
-		}
619
-
620
-		// open/type
621
-		$output .= '<select ';
622
-
623
-		// style
624
-		if($is_select2){
625
-			$output .= " style='width:100%;' ";
626
-		}
627
-
628
-		// class
629
-		$class = !empty($args['class']) ? $args['class'] : '';
630
-		$output .= AUI_Component_Helper::class_attr('custom-select '.$class);
631
-
632
-		// name
633
-		if(!empty($args['name'])){
634
-			$output .= AUI_Component_Helper::name($args['name'],$args['multiple']);
635
-		}
636
-
637
-		// id
638
-		if(!empty($args['id'])){
639
-			$output .= AUI_Component_Helper::id($args['id']);
640
-		}
641
-
642
-		// title
643
-		if(!empty($args['title'])){
644
-			$output .= AUI_Component_Helper::title($args['title']);
645
-		}
646
-
647
-		// data-attributes
648
-		$output .= AUI_Component_Helper::data_attributes($args);
649
-
650
-		// aria-attributes
651
-		$output .= AUI_Component_Helper::aria_attributes($args);
652
-
653
-		// extra attributes
654
-		if(!empty($args['extra_attributes'])){
655
-			$output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']);
656
-		}
657
-
658
-		// required
659
-		if(!empty($args['required'])){
660
-			$output .= ' required ';
661
-		}
662
-
663
-		// multiple
664
-		if(!empty($args['multiple'])){
665
-			$output .= ' multiple ';
666
-		}
667
-
668
-		// close opening tag
669
-		$output .= ' >';
670
-
671
-		// placeholder
672
-		if(!empty($args['placeholder']) && !$is_select2){
673
-			$output .= '<option value="" disabled selected hidden>'.esc_attr($args['placeholder']).'</option>';
674
-		}
675
-
676
-		// Options
677
-		if(!empty($args['options'])){
678
-			foreach($args['options'] as $val => $name){
679
-				$selected = '';
680
-				if(is_array($name)){
681
-					if (isset($name['optgroup']) && ($name['optgroup'] == 'start' || $name['optgroup'] == 'end')) {
682
-						$option_label = isset($name['label']) ? $name['label'] : '';
683
-
684
-						$output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr($option_label) . '">' : '</optgroup>';
685
-					} else {
686
-						$option_label = isset($name['label']) ? $name['label'] : '';
687
-						$option_value = isset($name['value']) ? $name['value'] : '';
688
-						if(!empty($args['multiple']) && !empty($args['value'])){
689
-							$selected = in_array($option_value, stripslashes_deep($args['value'])) ? "selected" : "";
690
-						} elseif(!empty($args['value'])) {
691
-							$selected = selected($option_value,stripslashes_deep($args['value']), false);
692
-						}
693
-
694
-						$output .= '<option value="' . esc_attr($option_value) . '" ' . $selected . '>' . $option_label . '</option>';
695
-					}
696
-				}else{
697
-					if(!empty($args['value'])){
698
-						if(is_array($args['value'])){
699
-							$selected = in_array($val,$args['value']) ? 'selected="selected"' : '';
700
-						} elseif(!empty($args['value'])) {
701
-							$selected = selected( $args['value'], $val, false);
702
-						}
703
-					}
704
-					$output .= '<option value="'.esc_attr($val).'" '.$selected.'>'.esc_attr($name).'</option>';
705
-				}
706
-			}
707
-
708
-		}
709
-
710
-		// closing tag
711
-		$output .= '</select>';
712
-
713
-		// help text
714
-		if(!empty($args['help_text'])){
715
-			$output .= AUI_Component_Helper::help_text($args['help_text']);
716
-		}
717
-
718
-		// maybe horizontal label
719
-		if($args['label_type']=='horizontal'){
720
-			$output .= '</div>';
721
-		}
722
-
723
-
724
-		// wrap
725
-		if(!$args['no_wrap']){
726
-			$wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group';
727
-			$output = self::wrap(array(
728
-				'content' => $output,
729
-				'class'   => $wrap_class,
730
-			));
731
-		}
732
-
733
-
734
-		return $output;
735
-	}
736
-
737
-	/**
738
-	 * Build the component.
739
-	 *
740
-	 * @param array $args
741
-	 *
742
-	 * @return string The rendered component.
743
-	 */
744
-	public static function radio($args = array()){
745
-		$defaults = array(
746
-			'class'      => '',
747
-			'id'         => '',
748
-			'title'      => '',
749
-			'horizontal' => false, // sets the lable horizontal
750
-			'value'      => '',
751
-			'label'      => '',
752
-			'label_class'=> '',
753
-			'label_type' => '', // sets the lable type, horizontal
754
-			'inline'     => true,
755
-			'required'   => false,
756
-			'options'    => array(),
757
-			'icon'       => '',
758
-			'no_wrap'    => false,
759
-			'extra_attributes'  => array() // an array of extra attributes
760
-		);
761
-
762
-		/**
763
-		 * Parse incoming $args into an array and merge it with $defaults
764
-		 */
765
-		$args   = wp_parse_args( $args, $defaults );
766
-
767
-		$label_args = array(
768
-			'title'=> $args['label'],
769
-			'class' => $args['label_class']." pt-0 ",
770
-			'label_type' => $args['label_type']
771
-		);
772
-
773
-		$output = '';
774
-
775
-
776
-
777
-		// label before
778
-		if(!empty($args['label'])){
779
-			$output .= self::label( $label_args, 'radio' );
780
-		}
781
-
782
-		// maybe horizontal label
783
-		if($args['label_type']=='horizontal'){
784
-			$output .= '<div class="col-sm-10">';
785
-		}
786
-
787
-		if(!empty($args['options'])){
788
-			$count = 0;
789
-			foreach($args['options'] as $value => $label){
790
-				$option_args = $args;
791
-				$option_args['value'] = $value;
792
-				$option_args['label'] = $label;
793
-				$option_args['checked'] = $value == $args['value'] ? true : false;
794
-				$output .= self::radio_option($option_args,$count);
795
-				$count++;
796
-			}
797
-		}
798
-
799
-		// maybe horizontal label
800
-		if($args['label_type']=='horizontal'){
801
-			$output .= '</div>';
802
-		}
803
-
804
-
805
-		// wrap
806
-		$wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group';
807
-		$output = self::wrap(array(
808
-			'content' => $output,
809
-			'class'   => $wrap_class,
810
-		));
811
-
812
-
813
-		return $output;
814
-	}
815
-
816
-	/**
817
-	 * Build the component.
818
-	 *
819
-	 * @param array $args
820
-	 *
821
-	 * @return string The rendered component.
822
-	 */
823
-	public static function radio_option($args = array(),$count = ''){
824
-		$defaults = array(
825
-			'class'      => '',
826
-			'id'         => '',
827
-			'title'      => '',
828
-			'value'      => '',
829
-			'required'   => false,
830
-			'inline'     => true,
831
-			'label'      => '',
832
-			'options'    => array(),
833
-			'icon'       => '',
834
-			'no_wrap'    => false,
835
-			'extra_attributes'  => array() // an array of extra attributes
836
-		);
837
-
838
-		/**
839
-		 * Parse incoming $args into an array and merge it with $defaults
840
-		 */
841
-		$args   = wp_parse_args( $args, $defaults );
842
-
843
-		$output = '';
844
-
845
-		// open/type
846
-		$output .= '<input type="radio"';
847
-
848
-		// class
849
-		$output .= ' class="form-check-input" ';
850
-
851
-		// name
852
-		if(!empty($args['name'])){
853
-			$output .= AUI_Component_Helper::name($args['name']);
854
-		}
855
-
856
-		// id
857
-		if(!empty($args['id'])){
858
-			$output .= AUI_Component_Helper::id($args['id'].$count);
859
-		}
860
-
861
-		// title
862
-		if(!empty($args['title'])){
863
-			$output .= AUI_Component_Helper::title($args['title']);
864
-		}
865
-
866
-		// value
867
-		if(!empty($args['value'])){
868
-			$output .= ' value="'.sanitize_text_field($args['value']).'" ';
869
-		}
870
-
871
-		// checked, for radio and checkboxes
872
-		if( $args['checked'] ){
873
-			$output .= ' checked ';
874
-		}
875
-
876
-		// data-attributes
877
-		$output .= AUI_Component_Helper::data_attributes($args);
878
-
879
-		// aria-attributes
880
-		$output .= AUI_Component_Helper::aria_attributes($args);
881
-
882
-		// extra attributes
883
-		if(!empty($args['extra_attributes'])){
884
-			$output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']);
885
-		}
886
-
887
-		// required
888
-		if(!empty($args['required'])){
889
-			$output .= ' required ';
890
-		}
891
-
892
-		// close opening tag
893
-		$output .= ' >';
894
-
895
-		// label
896
-		if(!empty($args['label']) && is_array($args['label'])){
897
-		}elseif(!empty($args['label'])){
898
-			$output .= self::label(array('title'=>$args['label'],'for'=>$args['id'].$count,'class'=>'form-check-label'),'radio');
899
-		}
900
-
901
-		// wrap
902
-		if(!$args['no_wrap']){
903
-			$wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check';
904
-			$output = self::wrap(array(
905
-				'content' => $output,
906
-				'class' => $wrap_class
907
-			));
908
-		}
909
-
910
-
911
-		return $output;
912
-	}
455
+            // maybe horizontal
456
+            if($args['label_type']=='horizontal' && $type != 'checkbox'){
457
+                $class .= ' col-sm-2 col-form-label';
458
+            }
459
+
460
+            // open
461
+            $output .= '<label ';
462
+
463
+            // for
464
+            if(!empty($args['for'])){
465
+                $output .= ' for="'.sanitize_text_field($args['for']).'" ';
466
+            }
467
+
468
+            // class
469
+            $output .= ' class="'.$class.'" ';
470
+
471
+            // close
472
+            $output .= '>';
473
+
474
+
475
+            // title, don't escape fully as can contain html
476
+            if(!empty($args['title'])){
477
+                $output .= wp_kses_post($args['title']);
478
+            }
479
+
480
+            // close wrap
481
+            $output .= '</label>';
482
+
483
+
484
+        }
485
+
486
+
487
+        return $output;
488
+    }
489
+
490
+    public static function wrap($args = array()){
491
+        $defaults = array(
492
+            'type'       => 'div',
493
+            'class'      => 'form-group',
494
+            'content'   => '',
495
+            'input_group_left' => '',
496
+            'input_group_right' => '',
497
+            'input_group_left_inside' => false,
498
+            'input_group_right_inside' => false,
499
+        );
500
+
501
+        /**
502
+         * Parse incoming $args into an array and merge it with $defaults
503
+         */
504
+        $args   = wp_parse_args( $args, $defaults );
505
+        $output = '';
506
+        if($args['type']){
507
+
508
+            // open
509
+            $output .= '<'.sanitize_html_class($args['type']);
510
+
511
+            // class
512
+            $class = !empty($args['class']) ? $args['class'] : '';
513
+            $output .= ' class="'.$class.'" ';
514
+
515
+            // close wrap
516
+            $output .= ' >';
517
+
518
+
519
+            // Input group left
520
+            if(!empty($args['input_group_left'])){
521
+                $position_class = !empty($args['input_group_left_inside']) ? 'position-absolute' : '';
522
+                $input_group_left = strpos($args['input_group_left'], '<') !== false ? $args['input_group_left'] : '<span class="input-group-text">'.$args['input_group_left'].'</span>';
523
+                $output .= '<div class="input-group-prepend '.$position_class.'">'.$input_group_left.'</div>';
524
+            }
525
+
526
+            // content
527
+            $output .= $args['content'];
528
+
529
+            // Input group right
530
+            if(!empty($args['input_group_right'])){
531
+                $position_class = !empty($args['input_group_left_inside']) ? 'position-absolute' : '';
532
+                $input_group_right = strpos($args['input_group_right'], '<') !== false ? $args['input_group_right'] : '<span class="input-group-text">'.$args['input_group_right'].'</span>';
533
+                $output .= '<div class="input-group-append '.$position_class.'">'.$input_group_right.'</div>';
534
+            }
535
+
536
+
537
+            // close wrap
538
+            $output .= '</'.sanitize_html_class($args['type']).'>';
539
+
540
+
541
+        }else{
542
+            $output = $args['content'];
543
+        }
544
+
545
+        return $output;
546
+    }
547
+
548
+    /**
549
+     * Build the component.
550
+     *
551
+     * @param array $args
552
+     *
553
+     * @return string The rendered component.
554
+     */
555
+    public static function select($args = array()){
556
+        $defaults = array(
557
+            'class'      => '',
558
+            'id'         => '',
559
+            'title'      => '',
560
+            'value'      => '', // can be an array or a string
561
+            'required'   => false,
562
+            'label'      => '',
563
+            'label_class'      => '',
564
+            'label_type' => '', // sets the lable type, horizontal
565
+            'help_text'  => '',
566
+            'placeholder'=> '',
567
+            'options'    => array(),
568
+            'icon'       => '',
569
+            'multiple'   => false,
570
+            'select2'    => false,
571
+            'no_wrap'    => false,
572
+            'extra_attributes'  => array() // an array of extra attributes
573
+        );
574
+
575
+        /**
576
+         * Parse incoming $args into an array and merge it with $defaults
577
+         */
578
+        $args   = wp_parse_args( $args, $defaults );
579
+        $output = '';
580
+
581
+        // Maybe setup select2
582
+        $is_select2 = false;
583
+        if(!empty($args['select2'])){
584
+            $args['class'] .= ' aui-select2';
585
+            $is_select2 = true;
586
+        }elseif( strpos($args['class'], 'aui-select2') !== false){
587
+            $is_select2 = true;
588
+        }
589
+
590
+        // select2 tags
591
+        if( !empty($args['select2']) && $args['select2'] === 'tags'){ // triple equlas needed here for some reason
592
+            $args['data-tags'] = 'true';
593
+            $args['data-token-separators'] = "[',']";
594
+            $args['multiple'] = true;
595
+        }
596
+
597
+        // select2 placeholder
598
+        if($is_select2 && !empty($args['placeholder']) && empty($args['data-placeholder'])){
599
+            $args['data-placeholder'] = esc_attr($args['placeholder']);
600
+            $args['data-allow-clear'] = empty($args['data-allow-clear']) ? true : esc_attr($args['data-allow-clear']);
601
+        }
602
+
603
+        // label
604
+        if(!empty($args['label']) && is_array($args['label'])){
605
+        }elseif(!empty($args['label'])){
606
+            $label_args = array(
607
+                'title'=> $args['label'],
608
+                'for'=> $args['id'],
609
+                'class' => $args['label_class']." ",
610
+                'label_type' => $args['label_type']
611
+            );
612
+            $output .= self::label($label_args);
613
+        }
614
+
615
+        // maybe horizontal label
616
+        if($args['label_type']=='horizontal'){
617
+            $output .= '<div class="col-sm-10">';
618
+        }
619
+
620
+        // open/type
621
+        $output .= '<select ';
622
+
623
+        // style
624
+        if($is_select2){
625
+            $output .= " style='width:100%;' ";
626
+        }
627
+
628
+        // class
629
+        $class = !empty($args['class']) ? $args['class'] : '';
630
+        $output .= AUI_Component_Helper::class_attr('custom-select '.$class);
631
+
632
+        // name
633
+        if(!empty($args['name'])){
634
+            $output .= AUI_Component_Helper::name($args['name'],$args['multiple']);
635
+        }
636
+
637
+        // id
638
+        if(!empty($args['id'])){
639
+            $output .= AUI_Component_Helper::id($args['id']);
640
+        }
641
+
642
+        // title
643
+        if(!empty($args['title'])){
644
+            $output .= AUI_Component_Helper::title($args['title']);
645
+        }
646
+
647
+        // data-attributes
648
+        $output .= AUI_Component_Helper::data_attributes($args);
649
+
650
+        // aria-attributes
651
+        $output .= AUI_Component_Helper::aria_attributes($args);
652
+
653
+        // extra attributes
654
+        if(!empty($args['extra_attributes'])){
655
+            $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']);
656
+        }
657
+
658
+        // required
659
+        if(!empty($args['required'])){
660
+            $output .= ' required ';
661
+        }
662
+
663
+        // multiple
664
+        if(!empty($args['multiple'])){
665
+            $output .= ' multiple ';
666
+        }
667
+
668
+        // close opening tag
669
+        $output .= ' >';
670
+
671
+        // placeholder
672
+        if(!empty($args['placeholder']) && !$is_select2){
673
+            $output .= '<option value="" disabled selected hidden>'.esc_attr($args['placeholder']).'</option>';
674
+        }
675
+
676
+        // Options
677
+        if(!empty($args['options'])){
678
+            foreach($args['options'] as $val => $name){
679
+                $selected = '';
680
+                if(is_array($name)){
681
+                    if (isset($name['optgroup']) && ($name['optgroup'] == 'start' || $name['optgroup'] == 'end')) {
682
+                        $option_label = isset($name['label']) ? $name['label'] : '';
683
+
684
+                        $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr($option_label) . '">' : '</optgroup>';
685
+                    } else {
686
+                        $option_label = isset($name['label']) ? $name['label'] : '';
687
+                        $option_value = isset($name['value']) ? $name['value'] : '';
688
+                        if(!empty($args['multiple']) && !empty($args['value'])){
689
+                            $selected = in_array($option_value, stripslashes_deep($args['value'])) ? "selected" : "";
690
+                        } elseif(!empty($args['value'])) {
691
+                            $selected = selected($option_value,stripslashes_deep($args['value']), false);
692
+                        }
693
+
694
+                        $output .= '<option value="' . esc_attr($option_value) . '" ' . $selected . '>' . $option_label . '</option>';
695
+                    }
696
+                }else{
697
+                    if(!empty($args['value'])){
698
+                        if(is_array($args['value'])){
699
+                            $selected = in_array($val,$args['value']) ? 'selected="selected"' : '';
700
+                        } elseif(!empty($args['value'])) {
701
+                            $selected = selected( $args['value'], $val, false);
702
+                        }
703
+                    }
704
+                    $output .= '<option value="'.esc_attr($val).'" '.$selected.'>'.esc_attr($name).'</option>';
705
+                }
706
+            }
707
+
708
+        }
709
+
710
+        // closing tag
711
+        $output .= '</select>';
712
+
713
+        // help text
714
+        if(!empty($args['help_text'])){
715
+            $output .= AUI_Component_Helper::help_text($args['help_text']);
716
+        }
717
+
718
+        // maybe horizontal label
719
+        if($args['label_type']=='horizontal'){
720
+            $output .= '</div>';
721
+        }
722
+
723
+
724
+        // wrap
725
+        if(!$args['no_wrap']){
726
+            $wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group';
727
+            $output = self::wrap(array(
728
+                'content' => $output,
729
+                'class'   => $wrap_class,
730
+            ));
731
+        }
732
+
733
+
734
+        return $output;
735
+    }
736
+
737
+    /**
738
+     * Build the component.
739
+     *
740
+     * @param array $args
741
+     *
742
+     * @return string The rendered component.
743
+     */
744
+    public static function radio($args = array()){
745
+        $defaults = array(
746
+            'class'      => '',
747
+            'id'         => '',
748
+            'title'      => '',
749
+            'horizontal' => false, // sets the lable horizontal
750
+            'value'      => '',
751
+            'label'      => '',
752
+            'label_class'=> '',
753
+            'label_type' => '', // sets the lable type, horizontal
754
+            'inline'     => true,
755
+            'required'   => false,
756
+            'options'    => array(),
757
+            'icon'       => '',
758
+            'no_wrap'    => false,
759
+            'extra_attributes'  => array() // an array of extra attributes
760
+        );
761
+
762
+        /**
763
+         * Parse incoming $args into an array and merge it with $defaults
764
+         */
765
+        $args   = wp_parse_args( $args, $defaults );
766
+
767
+        $label_args = array(
768
+            'title'=> $args['label'],
769
+            'class' => $args['label_class']." pt-0 ",
770
+            'label_type' => $args['label_type']
771
+        );
772
+
773
+        $output = '';
774
+
775
+
776
+
777
+        // label before
778
+        if(!empty($args['label'])){
779
+            $output .= self::label( $label_args, 'radio' );
780
+        }
781
+
782
+        // maybe horizontal label
783
+        if($args['label_type']=='horizontal'){
784
+            $output .= '<div class="col-sm-10">';
785
+        }
786
+
787
+        if(!empty($args['options'])){
788
+            $count = 0;
789
+            foreach($args['options'] as $value => $label){
790
+                $option_args = $args;
791
+                $option_args['value'] = $value;
792
+                $option_args['label'] = $label;
793
+                $option_args['checked'] = $value == $args['value'] ? true : false;
794
+                $output .= self::radio_option($option_args,$count);
795
+                $count++;
796
+            }
797
+        }
798
+
799
+        // maybe horizontal label
800
+        if($args['label_type']=='horizontal'){
801
+            $output .= '</div>';
802
+        }
803
+
804
+
805
+        // wrap
806
+        $wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group';
807
+        $output = self::wrap(array(
808
+            'content' => $output,
809
+            'class'   => $wrap_class,
810
+        ));
811
+
812
+
813
+        return $output;
814
+    }
815
+
816
+    /**
817
+     * Build the component.
818
+     *
819
+     * @param array $args
820
+     *
821
+     * @return string The rendered component.
822
+     */
823
+    public static function radio_option($args = array(),$count = ''){
824
+        $defaults = array(
825
+            'class'      => '',
826
+            'id'         => '',
827
+            'title'      => '',
828
+            'value'      => '',
829
+            'required'   => false,
830
+            'inline'     => true,
831
+            'label'      => '',
832
+            'options'    => array(),
833
+            'icon'       => '',
834
+            'no_wrap'    => false,
835
+            'extra_attributes'  => array() // an array of extra attributes
836
+        );
837
+
838
+        /**
839
+         * Parse incoming $args into an array and merge it with $defaults
840
+         */
841
+        $args   = wp_parse_args( $args, $defaults );
842
+
843
+        $output = '';
844
+
845
+        // open/type
846
+        $output .= '<input type="radio"';
847
+
848
+        // class
849
+        $output .= ' class="form-check-input" ';
850
+
851
+        // name
852
+        if(!empty($args['name'])){
853
+            $output .= AUI_Component_Helper::name($args['name']);
854
+        }
855
+
856
+        // id
857
+        if(!empty($args['id'])){
858
+            $output .= AUI_Component_Helper::id($args['id'].$count);
859
+        }
860
+
861
+        // title
862
+        if(!empty($args['title'])){
863
+            $output .= AUI_Component_Helper::title($args['title']);
864
+        }
865
+
866
+        // value
867
+        if(!empty($args['value'])){
868
+            $output .= ' value="'.sanitize_text_field($args['value']).'" ';
869
+        }
870
+
871
+        // checked, for radio and checkboxes
872
+        if( $args['checked'] ){
873
+            $output .= ' checked ';
874
+        }
875
+
876
+        // data-attributes
877
+        $output .= AUI_Component_Helper::data_attributes($args);
878
+
879
+        // aria-attributes
880
+        $output .= AUI_Component_Helper::aria_attributes($args);
881
+
882
+        // extra attributes
883
+        if(!empty($args['extra_attributes'])){
884
+            $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']);
885
+        }
886
+
887
+        // required
888
+        if(!empty($args['required'])){
889
+            $output .= ' required ';
890
+        }
891
+
892
+        // close opening tag
893
+        $output .= ' >';
894
+
895
+        // label
896
+        if(!empty($args['label']) && is_array($args['label'])){
897
+        }elseif(!empty($args['label'])){
898
+            $output .= self::label(array('title'=>$args['label'],'for'=>$args['id'].$count,'class'=>'form-check-label'),'radio');
899
+        }
900
+
901
+        // wrap
902
+        if(!$args['no_wrap']){
903
+            $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check';
904
+            $output = self::wrap(array(
905
+                'content' => $output,
906
+                'class' => $wrap_class
907
+            ));
908
+        }
909
+
910
+
911
+        return $output;
912
+    }
913 913
 
914 914
 }
915 915
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +181 added lines, -181 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'ABSPATH' ) ) {
3
+if (!defined('ABSPATH')) {
4 4
 	exit; // Exit if accessed directly
5 5
 }
6 6
 
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 	 *
19 19
 	 * @return string The rendered component.
20 20
 	 */
21
-	public static function input($args = array()){
21
+	public static function input($args = array()) {
22 22
 		$defaults = array(
23 23
 			'type'       => 'text',
24 24
 			'name'       => '',
@@ -50,10 +50,10 @@  discard block
 block discarded – undo
50 50
 		/**
51 51
 		 * Parse incoming $args into an array and merge it with $defaults
52 52
 		 */
53
-		$args   = wp_parse_args( $args, $defaults );
53
+		$args   = wp_parse_args($args, $defaults);
54 54
 		$output = '';
55
-		if ( ! empty( $args['type'] ) ) {
56
-			$type = sanitize_html_class( $args['type'] );
55
+		if (!empty($args['type'])) {
56
+			$type = sanitize_html_class($args['type']);
57 57
 
58 58
 			$help_text = '';
59 59
 			$label = '';
@@ -61,18 +61,18 @@  discard block
 block discarded – undo
61 61
 			$label_args = array(
62 62
 				'title'=> $args['label'],
63 63
 				'for'=> $args['id'],
64
-				'class' => $args['label_class']." ",
64
+				'class' => $args['label_class'] . " ",
65 65
 				'label_type' => $args['label_type']
66 66
 			);
67 67
 
68 68
 			// Some special sauce for files
69
-			if($type=='file' ){
69
+			if ($type == 'file') {
70 70
 				$label_after = true; // if type file we need the label after
71 71
 				$args['class'] .= ' custom-file-input ';
72
-			}elseif($type=='checkbox'){
72
+			}elseif ($type == 'checkbox') {
73 73
 				$label_after = true; // if type file we need the label after
74 74
 				$args['class'] .= ' custom-control-input ';
75
-			}elseif($type=='datepicker' || $type=='timepicker'){
75
+			}elseif ($type == 'datepicker' || $type == 'timepicker') {
76 76
 				$type = 'text';
77 77
 				$args['class'] .= ' aui-flatpickr bg-initial ';
78 78
 
@@ -86,65 +86,65 @@  discard block
 block discarded – undo
86 86
 			$output .= '<input type="' . $type . '" ';
87 87
 
88 88
 			// name
89
-			if(!empty($args['name'])){
90
-				$output .= ' name="'.esc_attr($args['name']).'" ';
89
+			if (!empty($args['name'])) {
90
+				$output .= ' name="' . esc_attr($args['name']) . '" ';
91 91
 			}
92 92
 
93 93
 			// id
94
-			if(!empty($args['id'])){
95
-				$output .= ' id="'.sanitize_html_class($args['id']).'" ';
94
+			if (!empty($args['id'])) {
95
+				$output .= ' id="' . sanitize_html_class($args['id']) . '" ';
96 96
 			}
97 97
 
98 98
 			// placeholder
99
-			if(!empty($args['placeholder'])){
100
-				$output .= ' placeholder="'.esc_attr($args['placeholder']).'" ';
99
+			if (!empty($args['placeholder'])) {
100
+				$output .= ' placeholder="' . esc_attr($args['placeholder']) . '" ';
101 101
 			}
102 102
 
103 103
 			// title
104
-			if(!empty($args['title'])){
105
-				$output .= ' title="'.esc_attr($args['title']).'" ';
104
+			if (!empty($args['title'])) {
105
+				$output .= ' title="' . esc_attr($args['title']) . '" ';
106 106
 			}
107 107
 
108 108
 			// value
109
-			if(!empty($args['value'])){
110
-				$output .= ' value="'.sanitize_text_field($args['value']).'" ';
109
+			if (!empty($args['value'])) {
110
+				$output .= ' value="' . sanitize_text_field($args['value']) . '" ';
111 111
 			}
112 112
 
113 113
 			// checked, for radio and checkboxes
114
-			if( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ){
114
+			if (($type == 'checkbox' || $type == 'radio') && $args['checked']) {
115 115
 				$output .= ' checked ';
116 116
 			}
117 117
 
118 118
 			// validation text
119
-			if(!empty($args['validation_text'])){
120
-				$output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" ';
119
+			if (!empty($args['validation_text'])) {
120
+				$output .= ' oninvalid="setCustomValidity(\'' . esc_attr($args['validation_text']) . '\')" ';
121 121
 				$output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" ';
122 122
 			}
123 123
 
124 124
 			// validation_pattern
125
-			if(!empty($args['validation_pattern'])){
126
-				$output .= ' pattern="'.$args['validation_pattern'].'" ';
125
+			if (!empty($args['validation_pattern'])) {
126
+				$output .= ' pattern="' . $args['validation_pattern'] . '" ';
127 127
 			}
128 128
 
129 129
 			// step (for numbers)
130
-			if(!empty($args['step'])){
131
-				$output .= ' step="'.$args['step'].'" ';
130
+			if (!empty($args['step'])) {
131
+				$output .= ' step="' . $args['step'] . '" ';
132 132
 			}
133 133
 
134 134
 			// required
135
-			if(!empty($args['required'])){
135
+			if (!empty($args['required'])) {
136 136
 				$output .= ' required ';
137 137
 			}
138 138
 
139 139
 			// class
140 140
 			$class = !empty($args['class']) ? $args['class'] : '';
141
-			$output .= ' class="form-control '.$class.'" ';
141
+			$output .= ' class="form-control ' . $class . '" ';
142 142
 
143 143
 			// data-attributes
144 144
 			$output .= AUI_Component_Helper::data_attributes($args);
145 145
 
146 146
 			// extra attributes
147
-			if(!empty($args['extra_attributes'])){
147
+			if (!empty($args['extra_attributes'])) {
148 148
 				$output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']);
149 149
 			}
150 150
 
@@ -153,20 +153,20 @@  discard block
 block discarded – undo
153 153
 
154 154
 
155 155
 			// label
156
-			if(!empty($args['label'])){
157
-				if($type == 'file'){$label_args['class'] .= 'custom-file-label';}
158
-				elseif($type == 'checkbox'){$label_args['class'] .= 'custom-control-label';}
159
-				$label = self::label( $label_args, $type );
156
+			if (!empty($args['label'])) {
157
+				if ($type == 'file') {$label_args['class'] .= 'custom-file-label'; }
158
+				elseif ($type == 'checkbox') {$label_args['class'] .= 'custom-control-label'; }
159
+				$label = self::label($label_args, $type);
160 160
 			}
161 161
 
162 162
 			// help text
163
-			if(!empty($args['help_text'])){
163
+			if (!empty($args['help_text'])) {
164 164
 				$help_text = AUI_Component_Helper::help_text($args['help_text']);
165 165
 			}
166 166
 
167 167
 
168 168
 			// set help text in the correct possition
169
-			if($label_after){
169
+			if ($label_after) {
170 170
 				$output .= $label . $help_text;
171 171
 			}
172 172
 
@@ -175,22 +175,22 @@  discard block
 block discarded – undo
175 175
 
176 176
 
177 177
 			// some input types need a separate wrap
178
-			if($type == 'file') {
179
-				$output = self::wrap( array(
178
+			if ($type == 'file') {
179
+				$output = self::wrap(array(
180 180
 					'content' => $output,
181 181
 					'class'   => 'form-group custom-file'
182
-				) );
183
-			}elseif($type == 'checkbox'){
182
+				));
183
+			}elseif ($type == 'checkbox') {
184 184
 				$wrap_class = $args['switch'] ? 'custom-switch' : 'custom-checkbox';
185
-				$output = self::wrap( array(
185
+				$output = self::wrap(array(
186 186
 					'content' => $output,
187
-					'class'   => 'custom-control '.$wrap_class
188
-				) );
187
+					'class'   => 'custom-control ' . $wrap_class
188
+				));
189 189
 
190
-				if($args['label_type']=='horizontal'){
190
+				if ($args['label_type'] == 'horizontal') {
191 191
 					$output = '<div class="col-sm-2 col-form-label"></div><div class="col-sm-10">' . $output . '</div>';
192 192
 				}
193
-			}elseif($type == 'password' && $args['password_toggle'] && !$args['input_group_right']){
193
+			}elseif ($type == 'password' && $args['password_toggle'] && !$args['input_group_right']) {
194 194
 
195 195
 
196 196
 				// allow password field to toggle view
@@ -204,23 +204,23 @@  discard block
 block discarded – undo
204 204
 			}
205 205
 
206 206
 			// input group wraps
207
-			if($args['input_group_left'] || $args['input_group_right']){
207
+			if ($args['input_group_left'] || $args['input_group_right']) {
208 208
 				$w100 = strpos($args['class'], 'w-100') !== false ? ' w-100' : '';
209
-				if($args['input_group_left']){
210
-					$output = self::wrap( array(
209
+				if ($args['input_group_left']) {
210
+					$output = self::wrap(array(
211 211
 						'content' => $output,
212
-						'class'   => $args['input_group_left_inside'] ? 'input-group-inside'.$w100  : 'input-group',
212
+						'class'   => $args['input_group_left_inside'] ? 'input-group-inside' . $w100 : 'input-group',
213 213
 						'input_group_left' => $args['input_group_left'],
214 214
 						'input_group_left_inside'    => $args['input_group_left_inside']
215
-					) );
215
+					));
216 216
 				}
217
-				if($args['input_group_right']){
218
-					$output = self::wrap( array(
217
+				if ($args['input_group_right']) {
218
+					$output = self::wrap(array(
219 219
 						'content' => $output,
220
-						'class'   => $args['input_group_right_inside'] ? 'input-group-inside'.$w100 : 'input-group',
220
+						'class'   => $args['input_group_right_inside'] ? 'input-group-inside' . $w100 : 'input-group',
221 221
 						'input_group_right' => $args['input_group_right'],
222 222
 						'input_group_right_inside'    => $args['input_group_right_inside']
223
-					) );
223
+					));
224 224
 				}
225 225
 
226 226
 				// Labels need to be on the outside of the wrap
@@ -228,19 +228,19 @@  discard block
 block discarded – undo
228 228
 //				$output = $label . str_replace($label,"",$output);
229 229
 			}
230 230
 
231
-			if(!$label_after){
231
+			if (!$label_after) {
232 232
 				$output .= $help_text;
233 233
 			}
234 234
 
235 235
 
236
-			if($args['label_type']=='horizontal' && $type != 'checkbox'){
237
-				$output = self::wrap( array(
236
+			if ($args['label_type'] == 'horizontal' && $type != 'checkbox') {
237
+				$output = self::wrap(array(
238 238
 					'content' => $output,
239 239
 					'class'   => 'col-sm-10',
240
-				) );
240
+				));
241 241
 			}
242 242
 
243
-			if(!$label_after){
243
+			if (!$label_after) {
244 244
 				$output = $label . $output;
245 245
 			}
246 246
 
@@ -254,8 +254,8 @@  discard block
 block discarded – undo
254 254
 //			}
255 255
 
256 256
 			// wrap
257
-			if(!$args['no_wrap']){
258
-				$wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group';
257
+			if (!$args['no_wrap']) {
258
+				$wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group';
259 259
 				$output = self::wrap(array(
260 260
 					'content' => $output,
261 261
 					'class'   => $wrap_class,
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
 	 *
277 277
 	 * @return string The rendered component.
278 278
 	 */
279
-	public static function textarea($args = array()){
279
+	public static function textarea($args = array()) {
280 280
 		$defaults = array(
281 281
 			'name'       => '',
282 282
 			'class'      => '',
@@ -299,27 +299,27 @@  discard block
 block discarded – undo
299 299
 		/**
300 300
 		 * Parse incoming $args into an array and merge it with $defaults
301 301
 		 */
302
-		$args   = wp_parse_args( $args, $defaults );
302
+		$args   = wp_parse_args($args, $defaults);
303 303
 		$output = '';
304 304
 
305 305
 		// label
306
-		if(!empty($args['label']) && is_array($args['label'])){
307
-		}elseif(!empty($args['label'])){
306
+		if (!empty($args['label']) && is_array($args['label'])) {
307
+		}elseif (!empty($args['label'])) {
308 308
 			$label_args = array(
309 309
 				'title'=> $args['label'],
310 310
 				'for'=> $args['id'],
311
-				'class' => $args['label_class']." ",
311
+				'class' => $args['label_class'] . " ",
312 312
 				'label_type' => $args['label_type']
313 313
 			);
314
-			$output .= self::label( $label_args );
314
+			$output .= self::label($label_args);
315 315
 		}
316 316
 
317 317
 		// maybe horizontal label
318
-		if($args['label_type']=='horizontal'){
318
+		if ($args['label_type'] == 'horizontal') {
319 319
 			$output .= '<div class="col-sm-10">';
320 320
 		}
321 321
 
322
-		if(!empty($args['wysiwyg'])){
322
+		if (!empty($args['wysiwyg'])) {
323 323
 			ob_start();
324 324
 			$content = $args['value'];
325 325
 			$editor_id = !empty($args['id']) ? sanitize_html_class($args['id']) : 'wp_editor';
@@ -333,69 +333,69 @@  discard block
 block discarded – undo
333 333
 			);
334 334
 
335 335
 			// maybe set settings if array
336
-			if(is_array($args['wysiwyg'])){
337
-				$settings  = wp_parse_args( $args['wysiwyg'], $settings );
336
+			if (is_array($args['wysiwyg'])) {
337
+				$settings = wp_parse_args($args['wysiwyg'], $settings);
338 338
 			}
339 339
 
340
-			wp_editor( $content, $editor_id, $settings );
340
+			wp_editor($content, $editor_id, $settings);
341 341
 			$output .= ob_get_clean();
342
-		}else{
342
+		} else {
343 343
 
344 344
 			// open
345 345
 			$output .= '<textarea ';
346 346
 
347 347
 			// name
348
-			if(!empty($args['name'])){
349
-				$output .= ' name="'.sanitize_html_class($args['name']).'" ';
348
+			if (!empty($args['name'])) {
349
+				$output .= ' name="' . sanitize_html_class($args['name']) . '" ';
350 350
 			}
351 351
 
352 352
 			// id
353
-			if(!empty($args['id'])){
354
-				$output .= ' id="'.sanitize_html_class($args['id']).'" ';
353
+			if (!empty($args['id'])) {
354
+				$output .= ' id="' . sanitize_html_class($args['id']) . '" ';
355 355
 			}
356 356
 
357 357
 			// placeholder
358
-			if(!empty($args['placeholder'])){
359
-				$output .= ' placeholder="'.esc_attr($args['placeholder']).'" ';
358
+			if (!empty($args['placeholder'])) {
359
+				$output .= ' placeholder="' . esc_attr($args['placeholder']) . '" ';
360 360
 			}
361 361
 
362 362
 			// title
363
-			if(!empty($args['title'])){
364
-				$output .= ' title="'.esc_attr($args['title']).'" ';
363
+			if (!empty($args['title'])) {
364
+				$output .= ' title="' . esc_attr($args['title']) . '" ';
365 365
 			}
366 366
 
367 367
 			// validation text
368
-			if(!empty($args['validation_text'])){
369
-				$output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" ';
368
+			if (!empty($args['validation_text'])) {
369
+				$output .= ' oninvalid="setCustomValidity(\'' . esc_attr($args['validation_text']) . '\')" ';
370 370
 				$output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" ';
371 371
 			}
372 372
 
373 373
 			// validation_pattern
374
-			if(!empty($args['validation_pattern'])){
375
-				$output .= ' pattern="'.$args['validation_pattern'].'" ';
374
+			if (!empty($args['validation_pattern'])) {
375
+				$output .= ' pattern="' . $args['validation_pattern'] . '" ';
376 376
 			}
377 377
 
378 378
 			// required
379
-			if(!empty($args['required'])){
379
+			if (!empty($args['required'])) {
380 380
 				$output .= ' required ';
381 381
 			}
382 382
 
383 383
 			// rows
384
-			if(!empty($args['rows'])){
385
-				$output .= ' rows="'.absint($args['rows']).'" ';
384
+			if (!empty($args['rows'])) {
385
+				$output .= ' rows="' . absint($args['rows']) . '" ';
386 386
 			}
387 387
 
388 388
 
389 389
 			// class
390 390
 			$class = !empty($args['class']) ? $args['class'] : '';
391
-			$output .= ' class="form-control '.$class.'" ';
391
+			$output .= ' class="form-control ' . $class . '" ';
392 392
 
393 393
 
394 394
 			// close tag
395 395
 			$output .= ' >';
396 396
 
397 397
 			// value
398
-			if(!empty($args['value'])){
398
+			if (!empty($args['value'])) {
399 399
 				$output .= sanitize_textarea_field($args['value']);
400 400
 			}
401 401
 
@@ -405,19 +405,19 @@  discard block
 block discarded – undo
405 405
 		}
406 406
 
407 407
 		// help text
408
-		if(!empty($args['help_text'])){
408
+		if (!empty($args['help_text'])) {
409 409
 			$output .= AUI_Component_Helper::help_text($args['help_text']);
410 410
 		}
411 411
 
412 412
 		// maybe horizontal label
413
-		if($args['label_type']=='horizontal'){
413
+		if ($args['label_type'] == 'horizontal') {
414 414
 			$output .= '</div>';
415 415
 		}
416 416
 
417 417
 
418 418
 		// wrap
419
-		if(!$args['no_wrap']){
420
-			$wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group';
419
+		if (!$args['no_wrap']) {
420
+			$wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group';
421 421
 			$output = self::wrap(array(
422 422
 				'content' => $output,
423 423
 				'class'   => $wrap_class,
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
 		return $output;
429 429
 	}
430 430
 
431
-	public static function label($args = array(), $type = ''){
431
+	public static function label($args = array(), $type = '') {
432 432
 		//<label for="exampleInputEmail1">Email address</label>
433 433
 		$defaults = array(
434 434
 			'title'       => 'div',
@@ -440,20 +440,20 @@  discard block
 block discarded – undo
440 440
 		/**
441 441
 		 * Parse incoming $args into an array and merge it with $defaults
442 442
 		 */
443
-		$args   = wp_parse_args( $args, $defaults );
443
+		$args   = wp_parse_args($args, $defaults);
444 444
 		$output = '';
445 445
 
446
-		if($args['title']){
446
+		if ($args['title']) {
447 447
 
448 448
 			// maybe hide labels //@todo set a global option for visibility class
449
-			if($type == 'file' || $type == 'checkbox' || $type == 'radio' || !empty($args['label_type']) ){
449
+			if ($type == 'file' || $type == 'checkbox' || $type == 'radio' || !empty($args['label_type'])) {
450 450
 				$class = $args['class'];
451
-			}else{
452
-				$class = 'sr-only '.$args['class'];
451
+			} else {
452
+				$class = 'sr-only ' . $args['class'];
453 453
 			}
454 454
 
455 455
 			// maybe horizontal
456
-			if($args['label_type']=='horizontal' && $type != 'checkbox'){
456
+			if ($args['label_type'] == 'horizontal' && $type != 'checkbox') {
457 457
 				$class .= ' col-sm-2 col-form-label';
458 458
 			}
459 459
 
@@ -461,19 +461,19 @@  discard block
 block discarded – undo
461 461
 			$output .= '<label ';
462 462
 
463 463
 			// for
464
-			if(!empty($args['for'])){
465
-				$output .= ' for="'.sanitize_text_field($args['for']).'" ';
464
+			if (!empty($args['for'])) {
465
+				$output .= ' for="' . sanitize_text_field($args['for']) . '" ';
466 466
 			}
467 467
 
468 468
 			// class
469
-			$output .= ' class="'.$class.'" ';
469
+			$output .= ' class="' . $class . '" ';
470 470
 
471 471
 			// close
472 472
 			$output .= '>';
473 473
 
474 474
 
475 475
 			// title, don't escape fully as can contain html
476
-			if(!empty($args['title'])){
476
+			if (!empty($args['title'])) {
477 477
 				$output .= wp_kses_post($args['title']);
478 478
 			}
479 479
 
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
 		return $output;
488 488
 	}
489 489
 
490
-	public static function wrap($args = array()){
490
+	public static function wrap($args = array()) {
491 491
 		$defaults = array(
492 492
 			'type'       => 'div',
493 493
 			'class'      => 'form-group',
@@ -501,44 +501,44 @@  discard block
 block discarded – undo
501 501
 		/**
502 502
 		 * Parse incoming $args into an array and merge it with $defaults
503 503
 		 */
504
-		$args   = wp_parse_args( $args, $defaults );
504
+		$args   = wp_parse_args($args, $defaults);
505 505
 		$output = '';
506
-		if($args['type']){
506
+		if ($args['type']) {
507 507
 
508 508
 			// open
509
-			$output .= '<'.sanitize_html_class($args['type']);
509
+			$output .= '<' . sanitize_html_class($args['type']);
510 510
 
511 511
 			// class
512 512
 			$class = !empty($args['class']) ? $args['class'] : '';
513
-			$output .= ' class="'.$class.'" ';
513
+			$output .= ' class="' . $class . '" ';
514 514
 
515 515
 			// close wrap
516 516
 			$output .= ' >';
517 517
 
518 518
 
519 519
 			// Input group left
520
-			if(!empty($args['input_group_left'])){
520
+			if (!empty($args['input_group_left'])) {
521 521
 				$position_class = !empty($args['input_group_left_inside']) ? 'position-absolute' : '';
522
-				$input_group_left = strpos($args['input_group_left'], '<') !== false ? $args['input_group_left'] : '<span class="input-group-text">'.$args['input_group_left'].'</span>';
523
-				$output .= '<div class="input-group-prepend '.$position_class.'">'.$input_group_left.'</div>';
522
+				$input_group_left = strpos($args['input_group_left'], '<') !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>';
523
+				$output .= '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>';
524 524
 			}
525 525
 
526 526
 			// content
527 527
 			$output .= $args['content'];
528 528
 
529 529
 			// Input group right
530
-			if(!empty($args['input_group_right'])){
530
+			if (!empty($args['input_group_right'])) {
531 531
 				$position_class = !empty($args['input_group_left_inside']) ? 'position-absolute' : '';
532
-				$input_group_right = strpos($args['input_group_right'], '<') !== false ? $args['input_group_right'] : '<span class="input-group-text">'.$args['input_group_right'].'</span>';
533
-				$output .= '<div class="input-group-append '.$position_class.'">'.$input_group_right.'</div>';
532
+				$input_group_right = strpos($args['input_group_right'], '<') !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>';
533
+				$output .= '<div class="input-group-append ' . $position_class . '">' . $input_group_right . '</div>';
534 534
 			}
535 535
 
536 536
 
537 537
 			// close wrap
538
-			$output .= '</'.sanitize_html_class($args['type']).'>';
538
+			$output .= '</' . sanitize_html_class($args['type']) . '>';
539 539
 
540 540
 
541
-		}else{
541
+		} else {
542 542
 			$output = $args['content'];
543 543
 		}
544 544
 
@@ -552,7 +552,7 @@  discard block
 block discarded – undo
552 552
 	 *
553 553
 	 * @return string The rendered component.
554 554
 	 */
555
-	public static function select($args = array()){
555
+	public static function select($args = array()) {
556 556
 		$defaults = array(
557 557
 			'class'      => '',
558 558
 			'id'         => '',
@@ -575,45 +575,45 @@  discard block
 block discarded – undo
575 575
 		/**
576 576
 		 * Parse incoming $args into an array and merge it with $defaults
577 577
 		 */
578
-		$args   = wp_parse_args( $args, $defaults );
578
+		$args   = wp_parse_args($args, $defaults);
579 579
 		$output = '';
580 580
 
581 581
 		// Maybe setup select2
582 582
 		$is_select2 = false;
583
-		if(!empty($args['select2'])){
583
+		if (!empty($args['select2'])) {
584 584
 			$args['class'] .= ' aui-select2';
585 585
 			$is_select2 = true;
586
-		}elseif( strpos($args['class'], 'aui-select2') !== false){
586
+		}elseif (strpos($args['class'], 'aui-select2') !== false) {
587 587
 			$is_select2 = true;
588 588
 		}
589 589
 
590 590
 		// select2 tags
591
-		if( !empty($args['select2']) && $args['select2'] === 'tags'){ // triple equlas needed here for some reason
591
+		if (!empty($args['select2']) && $args['select2'] === 'tags') { // triple equlas needed here for some reason
592 592
 			$args['data-tags'] = 'true';
593 593
 			$args['data-token-separators'] = "[',']";
594 594
 			$args['multiple'] = true;
595 595
 		}
596 596
 
597 597
 		// select2 placeholder
598
-		if($is_select2 && !empty($args['placeholder']) && empty($args['data-placeholder'])){
598
+		if ($is_select2 && !empty($args['placeholder']) && empty($args['data-placeholder'])) {
599 599
 			$args['data-placeholder'] = esc_attr($args['placeholder']);
600 600
 			$args['data-allow-clear'] = empty($args['data-allow-clear']) ? true : esc_attr($args['data-allow-clear']);
601 601
 		}
602 602
 
603 603
 		// label
604
-		if(!empty($args['label']) && is_array($args['label'])){
605
-		}elseif(!empty($args['label'])){
604
+		if (!empty($args['label']) && is_array($args['label'])) {
605
+		}elseif (!empty($args['label'])) {
606 606
 			$label_args = array(
607 607
 				'title'=> $args['label'],
608 608
 				'for'=> $args['id'],
609
-				'class' => $args['label_class']." ",
609
+				'class' => $args['label_class'] . " ",
610 610
 				'label_type' => $args['label_type']
611 611
 			);
612 612
 			$output .= self::label($label_args);
613 613
 		}
614 614
 
615 615
 		// maybe horizontal label
616
-		if($args['label_type']=='horizontal'){
616
+		if ($args['label_type'] == 'horizontal') {
617 617
 			$output .= '<div class="col-sm-10">';
618 618
 		}
619 619
 
@@ -621,26 +621,26 @@  discard block
 block discarded – undo
621 621
 		$output .= '<select ';
622 622
 
623 623
 		// style
624
-		if($is_select2){
624
+		if ($is_select2) {
625 625
 			$output .= " style='width:100%;' ";
626 626
 		}
627 627
 
628 628
 		// class
629 629
 		$class = !empty($args['class']) ? $args['class'] : '';
630
-		$output .= AUI_Component_Helper::class_attr('custom-select '.$class);
630
+		$output .= AUI_Component_Helper::class_attr('custom-select ' . $class);
631 631
 
632 632
 		// name
633
-		if(!empty($args['name'])){
634
-			$output .= AUI_Component_Helper::name($args['name'],$args['multiple']);
633
+		if (!empty($args['name'])) {
634
+			$output .= AUI_Component_Helper::name($args['name'], $args['multiple']);
635 635
 		}
636 636
 
637 637
 		// id
638
-		if(!empty($args['id'])){
638
+		if (!empty($args['id'])) {
639 639
 			$output .= AUI_Component_Helper::id($args['id']);
640 640
 		}
641 641
 
642 642
 		// title
643
-		if(!empty($args['title'])){
643
+		if (!empty($args['title'])) {
644 644
 			$output .= AUI_Component_Helper::title($args['title']);
645 645
 		}
646 646
 
@@ -651,17 +651,17 @@  discard block
 block discarded – undo
651 651
 		$output .= AUI_Component_Helper::aria_attributes($args);
652 652
 
653 653
 		// extra attributes
654
-		if(!empty($args['extra_attributes'])){
654
+		if (!empty($args['extra_attributes'])) {
655 655
 			$output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']);
656 656
 		}
657 657
 
658 658
 		// required
659
-		if(!empty($args['required'])){
659
+		if (!empty($args['required'])) {
660 660
 			$output .= ' required ';
661 661
 		}
662 662
 
663 663
 		// multiple
664
-		if(!empty($args['multiple'])){
664
+		if (!empty($args['multiple'])) {
665 665
 			$output .= ' multiple ';
666 666
 		}
667 667
 
@@ -669,15 +669,15 @@  discard block
 block discarded – undo
669 669
 		$output .= ' >';
670 670
 
671 671
 		// placeholder
672
-		if(!empty($args['placeholder']) && !$is_select2){
673
-			$output .= '<option value="" disabled selected hidden>'.esc_attr($args['placeholder']).'</option>';
672
+		if (!empty($args['placeholder']) && !$is_select2) {
673
+			$output .= '<option value="" disabled selected hidden>' . esc_attr($args['placeholder']) . '</option>';
674 674
 		}
675 675
 
676 676
 		// Options
677
-		if(!empty($args['options'])){
678
-			foreach($args['options'] as $val => $name){
677
+		if (!empty($args['options'])) {
678
+			foreach ($args['options'] as $val => $name) {
679 679
 				$selected = '';
680
-				if(is_array($name)){
680
+				if (is_array($name)) {
681 681
 					if (isset($name['optgroup']) && ($name['optgroup'] == 'start' || $name['optgroup'] == 'end')) {
682 682
 						$option_label = isset($name['label']) ? $name['label'] : '';
683 683
 
@@ -685,23 +685,23 @@  discard block
 block discarded – undo
685 685
 					} else {
686 686
 						$option_label = isset($name['label']) ? $name['label'] : '';
687 687
 						$option_value = isset($name['value']) ? $name['value'] : '';
688
-						if(!empty($args['multiple']) && !empty($args['value'])){
688
+						if (!empty($args['multiple']) && !empty($args['value'])) {
689 689
 							$selected = in_array($option_value, stripslashes_deep($args['value'])) ? "selected" : "";
690
-						} elseif(!empty($args['value'])) {
691
-							$selected = selected($option_value,stripslashes_deep($args['value']), false);
690
+						} elseif (!empty($args['value'])) {
691
+							$selected = selected($option_value, stripslashes_deep($args['value']), false);
692 692
 						}
693 693
 
694 694
 						$output .= '<option value="' . esc_attr($option_value) . '" ' . $selected . '>' . $option_label . '</option>';
695 695
 					}
696
-				}else{
697
-					if(!empty($args['value'])){
698
-						if(is_array($args['value'])){
699
-							$selected = in_array($val,$args['value']) ? 'selected="selected"' : '';
700
-						} elseif(!empty($args['value'])) {
701
-							$selected = selected( $args['value'], $val, false);
696
+				} else {
697
+					if (!empty($args['value'])) {
698
+						if (is_array($args['value'])) {
699
+							$selected = in_array($val, $args['value']) ? 'selected="selected"' : '';
700
+						} elseif (!empty($args['value'])) {
701
+							$selected = selected($args['value'], $val, false);
702 702
 						}
703 703
 					}
704
-					$output .= '<option value="'.esc_attr($val).'" '.$selected.'>'.esc_attr($name).'</option>';
704
+					$output .= '<option value="' . esc_attr($val) . '" ' . $selected . '>' . esc_attr($name) . '</option>';
705 705
 				}
706 706
 			}
707 707
 
@@ -711,19 +711,19 @@  discard block
 block discarded – undo
711 711
 		$output .= '</select>';
712 712
 
713 713
 		// help text
714
-		if(!empty($args['help_text'])){
714
+		if (!empty($args['help_text'])) {
715 715
 			$output .= AUI_Component_Helper::help_text($args['help_text']);
716 716
 		}
717 717
 
718 718
 		// maybe horizontal label
719
-		if($args['label_type']=='horizontal'){
719
+		if ($args['label_type'] == 'horizontal') {
720 720
 			$output .= '</div>';
721 721
 		}
722 722
 
723 723
 
724 724
 		// wrap
725
-		if(!$args['no_wrap']){
726
-			$wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group';
725
+		if (!$args['no_wrap']) {
726
+			$wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group';
727 727
 			$output = self::wrap(array(
728 728
 				'content' => $output,
729 729
 				'class'   => $wrap_class,
@@ -741,7 +741,7 @@  discard block
 block discarded – undo
741 741
 	 *
742 742
 	 * @return string The rendered component.
743 743
 	 */
744
-	public static function radio($args = array()){
744
+	public static function radio($args = array()) {
745 745
 		$defaults = array(
746 746
 			'class'      => '',
747 747
 			'id'         => '',
@@ -762,11 +762,11 @@  discard block
 block discarded – undo
762 762
 		/**
763 763
 		 * Parse incoming $args into an array and merge it with $defaults
764 764
 		 */
765
-		$args   = wp_parse_args( $args, $defaults );
765
+		$args = wp_parse_args($args, $defaults);
766 766
 
767 767
 		$label_args = array(
768 768
 			'title'=> $args['label'],
769
-			'class' => $args['label_class']." pt-0 ",
769
+			'class' => $args['label_class'] . " pt-0 ",
770 770
 			'label_type' => $args['label_type']
771 771
 		);
772 772
 
@@ -775,35 +775,35 @@  discard block
 block discarded – undo
775 775
 
776 776
 
777 777
 		// label before
778
-		if(!empty($args['label'])){
779
-			$output .= self::label( $label_args, 'radio' );
778
+		if (!empty($args['label'])) {
779
+			$output .= self::label($label_args, 'radio');
780 780
 		}
781 781
 
782 782
 		// maybe horizontal label
783
-		if($args['label_type']=='horizontal'){
783
+		if ($args['label_type'] == 'horizontal') {
784 784
 			$output .= '<div class="col-sm-10">';
785 785
 		}
786 786
 
787
-		if(!empty($args['options'])){
787
+		if (!empty($args['options'])) {
788 788
 			$count = 0;
789
-			foreach($args['options'] as $value => $label){
789
+			foreach ($args['options'] as $value => $label) {
790 790
 				$option_args = $args;
791 791
 				$option_args['value'] = $value;
792 792
 				$option_args['label'] = $label;
793 793
 				$option_args['checked'] = $value == $args['value'] ? true : false;
794
-				$output .= self::radio_option($option_args,$count);
794
+				$output .= self::radio_option($option_args, $count);
795 795
 				$count++;
796 796
 			}
797 797
 		}
798 798
 
799 799
 		// maybe horizontal label
800
-		if($args['label_type']=='horizontal'){
800
+		if ($args['label_type'] == 'horizontal') {
801 801
 			$output .= '</div>';
802 802
 		}
803 803
 
804 804
 
805 805
 		// wrap
806
-		$wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group';
806
+		$wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group';
807 807
 		$output = self::wrap(array(
808 808
 			'content' => $output,
809 809
 			'class'   => $wrap_class,
@@ -820,7 +820,7 @@  discard block
 block discarded – undo
820 820
 	 *
821 821
 	 * @return string The rendered component.
822 822
 	 */
823
-	public static function radio_option($args = array(),$count = ''){
823
+	public static function radio_option($args = array(), $count = '') {
824 824
 		$defaults = array(
825 825
 			'class'      => '',
826 826
 			'id'         => '',
@@ -838,7 +838,7 @@  discard block
 block discarded – undo
838 838
 		/**
839 839
 		 * Parse incoming $args into an array and merge it with $defaults
840 840
 		 */
841
-		$args   = wp_parse_args( $args, $defaults );
841
+		$args   = wp_parse_args($args, $defaults);
842 842
 
843 843
 		$output = '';
844 844
 
@@ -849,27 +849,27 @@  discard block
 block discarded – undo
849 849
 		$output .= ' class="form-check-input" ';
850 850
 
851 851
 		// name
852
-		if(!empty($args['name'])){
852
+		if (!empty($args['name'])) {
853 853
 			$output .= AUI_Component_Helper::name($args['name']);
854 854
 		}
855 855
 
856 856
 		// id
857
-		if(!empty($args['id'])){
858
-			$output .= AUI_Component_Helper::id($args['id'].$count);
857
+		if (!empty($args['id'])) {
858
+			$output .= AUI_Component_Helper::id($args['id'] . $count);
859 859
 		}
860 860
 
861 861
 		// title
862
-		if(!empty($args['title'])){
862
+		if (!empty($args['title'])) {
863 863
 			$output .= AUI_Component_Helper::title($args['title']);
864 864
 		}
865 865
 
866 866
 		// value
867
-		if(!empty($args['value'])){
868
-			$output .= ' value="'.sanitize_text_field($args['value']).'" ';
867
+		if (!empty($args['value'])) {
868
+			$output .= ' value="' . sanitize_text_field($args['value']) . '" ';
869 869
 		}
870 870
 
871 871
 		// checked, for radio and checkboxes
872
-		if( $args['checked'] ){
872
+		if ($args['checked']) {
873 873
 			$output .= ' checked ';
874 874
 		}
875 875
 
@@ -880,12 +880,12 @@  discard block
 block discarded – undo
880 880
 		$output .= AUI_Component_Helper::aria_attributes($args);
881 881
 
882 882
 		// extra attributes
883
-		if(!empty($args['extra_attributes'])){
883
+		if (!empty($args['extra_attributes'])) {
884 884
 			$output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']);
885 885
 		}
886 886
 
887 887
 		// required
888
-		if(!empty($args['required'])){
888
+		if (!empty($args['required'])) {
889 889
 			$output .= ' required ';
890 890
 		}
891 891
 
@@ -893,13 +893,13 @@  discard block
 block discarded – undo
893 893
 		$output .= ' >';
894 894
 
895 895
 		// label
896
-		if(!empty($args['label']) && is_array($args['label'])){
897
-		}elseif(!empty($args['label'])){
898
-			$output .= self::label(array('title'=>$args['label'],'for'=>$args['id'].$count,'class'=>'form-check-label'),'radio');
896
+		if (!empty($args['label']) && is_array($args['label'])) {
897
+		}elseif (!empty($args['label'])) {
898
+			$output .= self::label(array('title'=>$args['label'], 'for'=>$args['id'] . $count, 'class'=>'form-check-label'), 'radio');
899 899
 		}
900 900
 
901 901
 		// wrap
902
-		if(!$args['no_wrap']){
902
+		if (!$args['no_wrap']) {
903 903
 			$wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check';
904 904
 			$output = self::wrap(array(
905 905
 				'content' => $output,
Please login to merge, or discard this patch.
Braces   +13 added lines, -14 removed lines patch added patch discarded remove patch
@@ -69,10 +69,10 @@  discard block
 block discarded – undo
69 69
 			if($type=='file' ){
70 70
 				$label_after = true; // if type file we need the label after
71 71
 				$args['class'] .= ' custom-file-input ';
72
-			}elseif($type=='checkbox'){
72
+			} elseif($type=='checkbox'){
73 73
 				$label_after = true; // if type file we need the label after
74 74
 				$args['class'] .= ' custom-control-input ';
75
-			}elseif($type=='datepicker' || $type=='timepicker'){
75
+			} elseif($type=='datepicker' || $type=='timepicker'){
76 76
 				$type = 'text';
77 77
 				$args['class'] .= ' aui-flatpickr bg-initial ';
78 78
 
@@ -154,8 +154,7 @@  discard block
 block discarded – undo
154 154
 
155 155
 			// label
156 156
 			if(!empty($args['label'])){
157
-				if($type == 'file'){$label_args['class'] .= 'custom-file-label';}
158
-				elseif($type == 'checkbox'){$label_args['class'] .= 'custom-control-label';}
157
+				if($type == 'file'){$label_args['class'] .= 'custom-file-label';} elseif($type == 'checkbox'){$label_args['class'] .= 'custom-control-label';}
159 158
 				$label = self::label( $label_args, $type );
160 159
 			}
161 160
 
@@ -180,7 +179,7 @@  discard block
 block discarded – undo
180 179
 					'content' => $output,
181 180
 					'class'   => 'form-group custom-file'
182 181
 				) );
183
-			}elseif($type == 'checkbox'){
182
+			} elseif($type == 'checkbox'){
184 183
 				$wrap_class = $args['switch'] ? 'custom-switch' : 'custom-checkbox';
185 184
 				$output = self::wrap( array(
186 185
 					'content' => $output,
@@ -190,7 +189,7 @@  discard block
 block discarded – undo
190 189
 				if($args['label_type']=='horizontal'){
191 190
 					$output = '<div class="col-sm-2 col-form-label"></div><div class="col-sm-10">' . $output . '</div>';
192 191
 				}
193
-			}elseif($type == 'password' && $args['password_toggle'] && !$args['input_group_right']){
192
+			} elseif($type == 'password' && $args['password_toggle'] && !$args['input_group_right']){
194 193
 
195 194
 
196 195
 				// allow password field to toggle view
@@ -304,7 +303,7 @@  discard block
 block discarded – undo
304 303
 
305 304
 		// label
306 305
 		if(!empty($args['label']) && is_array($args['label'])){
307
-		}elseif(!empty($args['label'])){
306
+		} elseif(!empty($args['label'])){
308 307
 			$label_args = array(
309 308
 				'title'=> $args['label'],
310 309
 				'for'=> $args['id'],
@@ -339,7 +338,7 @@  discard block
 block discarded – undo
339 338
 
340 339
 			wp_editor( $content, $editor_id, $settings );
341 340
 			$output .= ob_get_clean();
342
-		}else{
341
+		} else{
343 342
 
344 343
 			// open
345 344
 			$output .= '<textarea ';
@@ -448,7 +447,7 @@  discard block
 block discarded – undo
448 447
 			// maybe hide labels //@todo set a global option for visibility class
449 448
 			if($type == 'file' || $type == 'checkbox' || $type == 'radio' || !empty($args['label_type']) ){
450 449
 				$class = $args['class'];
451
-			}else{
450
+			} else{
452 451
 				$class = 'sr-only '.$args['class'];
453 452
 			}
454 453
 
@@ -538,7 +537,7 @@  discard block
 block discarded – undo
538 537
 			$output .= '</'.sanitize_html_class($args['type']).'>';
539 538
 
540 539
 
541
-		}else{
540
+		} else{
542 541
 			$output = $args['content'];
543 542
 		}
544 543
 
@@ -583,7 +582,7 @@  discard block
 block discarded – undo
583 582
 		if(!empty($args['select2'])){
584 583
 			$args['class'] .= ' aui-select2';
585 584
 			$is_select2 = true;
586
-		}elseif( strpos($args['class'], 'aui-select2') !== false){
585
+		} elseif( strpos($args['class'], 'aui-select2') !== false){
587 586
 			$is_select2 = true;
588 587
 		}
589 588
 
@@ -602,7 +601,7 @@  discard block
 block discarded – undo
602 601
 
603 602
 		// label
604 603
 		if(!empty($args['label']) && is_array($args['label'])){
605
-		}elseif(!empty($args['label'])){
604
+		} elseif(!empty($args['label'])){
606 605
 			$label_args = array(
607 606
 				'title'=> $args['label'],
608 607
 				'for'=> $args['id'],
@@ -693,7 +692,7 @@  discard block
 block discarded – undo
693 692
 
694 693
 						$output .= '<option value="' . esc_attr($option_value) . '" ' . $selected . '>' . $option_label . '</option>';
695 694
 					}
696
-				}else{
695
+				} else{
697 696
 					if(!empty($args['value'])){
698 697
 						if(is_array($args['value'])){
699 698
 							$selected = in_array($val,$args['value']) ? 'selected="selected"' : '';
@@ -894,7 +893,7 @@  discard block
 block discarded – undo
894 893
 
895 894
 		// label
896 895
 		if(!empty($args['label']) && is_array($args['label'])){
897
-		}elseif(!empty($args['label'])){
896
+		} elseif(!empty($args['label'])){
898 897
 			$output .= self::label(array('title'=>$args['label'],'for'=>$args['id'].$count,'class'=>'form-check-label'),'radio');
899 898
 		}
900 899
 
Please login to merge, or discard this patch.
vendor/ayecode/wp-ayecode-ui/includes/ayecode-ui-settings.php 2 patches
Indentation   +822 added lines, -822 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
  * Bail if we are not in WP.
14 14
  */
15 15
 if ( ! defined( 'ABSPATH' ) ) {
16
-	exit;
16
+    exit;
17 17
 }
18 18
 
19 19
 /**
@@ -21,167 +21,167 @@  discard block
 block discarded – undo
21 21
  */
22 22
 if ( ! class_exists( 'AyeCode_UI_Settings' ) ) {
23 23
 
24
-	/**
25
-	 * A Class to be able to change settings for Font Awesome.
26
-	 *
27
-	 * Class AyeCode_UI_Settings
28
-	 * @ver 1.0.0
29
-	 * @todo decide how to implement textdomain
30
-	 */
31
-	class AyeCode_UI_Settings {
32
-
33
-		/**
34
-		 * Class version version.
35
-		 *
36
-		 * @var string
37
-		 */
38
-		public $version = '1.0.1';
39
-
40
-		/**
41
-		 * Class textdomain.
42
-		 *
43
-		 * @var string
44
-		 */
45
-		public $textdomain = 'aui';
46
-
47
-		/**
48
-		 * Latest version of Bootstrap at time of publish published.
49
-		 *
50
-		 * @var string
51
-		 */
52
-		public $latest = "4.3.1";
53
-
54
-		/**
55
-		 * Current version of select2 being used.
56
-		 *
57
-		 * @var string
58
-		 */
59
-		public $select2_version = "4.0.11";
60
-
61
-		/**
62
-		 * The title.
63
-		 *
64
-		 * @var string
65
-		 */
66
-		public $name = 'AyeCode UI';
67
-
68
-		/**
69
-		 * The relative url to the assets.
70
-		 *
71
-		 * @var string
72
-		 */
73
-		public $url = '';
74
-
75
-		/**
76
-		 * Holds the settings values.
77
-		 *
78
-		 * @var array
79
-		 */
80
-		private $settings;
81
-
82
-		/**
83
-		 * AyeCode_UI_Settings instance.
84
-		 *
85
-		 * @access private
86
-		 * @since  1.0.0
87
-		 * @var    AyeCode_UI_Settings There can be only one!
88
-		 */
89
-		private static $instance = null;
90
-
91
-		/**
92
-		 * Main AyeCode_UI_Settings Instance.
93
-		 *
94
-		 * Ensures only one instance of AyeCode_UI_Settings is loaded or can be loaded.
95
-		 *
96
-		 * @since 1.0.0
97
-		 * @static
98
-		 * @return AyeCode_UI_Settings - Main instance.
99
-		 */
100
-		public static function instance() {
101
-			if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_UI_Settings ) ) {
102
-				self::$instance = new AyeCode_UI_Settings;
103
-
104
-				add_action( 'init', array( self::$instance, 'init' ) ); // set settings
105
-
106
-				if ( is_admin() ) {
107
-					add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
108
-					add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
109
-
110
-					// Maybe show example page
111
-					add_action( 'template_redirect', array( self::$instance,'maybe_show_examples' ) );
112
-				}
113
-
114
-				add_action( 'customize_register', array( self::$instance, 'customizer_settings' ));
115
-
116
-				do_action( 'ayecode_ui_settings_loaded' );
117
-			}
118
-
119
-			return self::$instance;
120
-		}
121
-
122
-		/**
123
-		 * Initiate the settings and add the required action hooks.
124
-		 */
125
-		public function init() {
126
-			$this->settings = $this->get_settings();
127
-			$this->url = $this->get_url();
24
+    /**
25
+     * A Class to be able to change settings for Font Awesome.
26
+     *
27
+     * Class AyeCode_UI_Settings
28
+     * @ver 1.0.0
29
+     * @todo decide how to implement textdomain
30
+     */
31
+    class AyeCode_UI_Settings {
32
+
33
+        /**
34
+         * Class version version.
35
+         *
36
+         * @var string
37
+         */
38
+        public $version = '1.0.1';
39
+
40
+        /**
41
+         * Class textdomain.
42
+         *
43
+         * @var string
44
+         */
45
+        public $textdomain = 'aui';
46
+
47
+        /**
48
+         * Latest version of Bootstrap at time of publish published.
49
+         *
50
+         * @var string
51
+         */
52
+        public $latest = "4.3.1";
53
+
54
+        /**
55
+         * Current version of select2 being used.
56
+         *
57
+         * @var string
58
+         */
59
+        public $select2_version = "4.0.11";
60
+
61
+        /**
62
+         * The title.
63
+         *
64
+         * @var string
65
+         */
66
+        public $name = 'AyeCode UI';
67
+
68
+        /**
69
+         * The relative url to the assets.
70
+         *
71
+         * @var string
72
+         */
73
+        public $url = '';
74
+
75
+        /**
76
+         * Holds the settings values.
77
+         *
78
+         * @var array
79
+         */
80
+        private $settings;
81
+
82
+        /**
83
+         * AyeCode_UI_Settings instance.
84
+         *
85
+         * @access private
86
+         * @since  1.0.0
87
+         * @var    AyeCode_UI_Settings There can be only one!
88
+         */
89
+        private static $instance = null;
90
+
91
+        /**
92
+         * Main AyeCode_UI_Settings Instance.
93
+         *
94
+         * Ensures only one instance of AyeCode_UI_Settings is loaded or can be loaded.
95
+         *
96
+         * @since 1.0.0
97
+         * @static
98
+         * @return AyeCode_UI_Settings - Main instance.
99
+         */
100
+        public static function instance() {
101
+            if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_UI_Settings ) ) {
102
+                self::$instance = new AyeCode_UI_Settings;
103
+
104
+                add_action( 'init', array( self::$instance, 'init' ) ); // set settings
105
+
106
+                if ( is_admin() ) {
107
+                    add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
108
+                    add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
109
+
110
+                    // Maybe show example page
111
+                    add_action( 'template_redirect', array( self::$instance,'maybe_show_examples' ) );
112
+                }
128 113
 
129
-			/**
130
-			 * Maybe load CSS
131
-			 *
132
-			 * We load super early in case there is a theme version that might change the colors
133
-			 */
134
-			if ( $this->settings['css'] ) {
135
-				add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 1 );
136
-			}
137
-			if ( $this->settings['css_backend'] ) {
138
-				add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 1 );
139
-			}
140
-
141
-			// maybe load JS
142
-			if ( $this->settings['js'] ) {
143
-				add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 );
144
-			}
145
-			if ( $this->settings['js_backend'] ) {
146
-				add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 );
147
-			}
148
-
149
-			// Maybe set the HTML font size
150
-			if ( $this->settings['html_font_size'] ) {
151
-				add_action( 'wp_footer', array( $this, 'html_font_size' ), 10 );
152
-			}
153
-
154
-
155
-		}
156
-
157
-		/**
158
-		 * Add a html font size to the footer.
159
-		 */
160
-		public function html_font_size(){
161
-			$this->settings = $this->get_settings();
162
-			echo "<style>html{font-size:".absint($this->settings['html_font_size'])."px;}</style>";
163
-		}
164
-
165
-		/**
166
-		 * Adds the Font Awesome styles.
167
-		 */
168
-		public function enqueue_style() {
169
-
170
-			$css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend';
171
-
172
-			if($this->settings[$css_setting]){
173
-				$compatibility = $this->settings[$css_setting]=='core' ? false : true;
174
-				$url = $this->settings[$css_setting]=='core' ? $this->url.'assets/css/ayecode-ui.css' : $this->url.'assets/css/ayecode-ui-compatibility.css';
175
-				wp_register_style( 'ayecode-ui', $url, array(), $this->latest );
176
-				wp_enqueue_style( 'ayecode-ui' );
177
-
178
-				// flatpickr
179
-				wp_register_style( 'flatpickr', $this->url.'assets/css/flatpickr.min.css', array(), $this->latest );
180
-
181
-
182
-				// fix some wp-admin issues
183
-				if(is_admin()){
184
-					$custom_css = "
114
+                add_action( 'customize_register', array( self::$instance, 'customizer_settings' ));
115
+
116
+                do_action( 'ayecode_ui_settings_loaded' );
117
+            }
118
+
119
+            return self::$instance;
120
+        }
121
+
122
+        /**
123
+         * Initiate the settings and add the required action hooks.
124
+         */
125
+        public function init() {
126
+            $this->settings = $this->get_settings();
127
+            $this->url = $this->get_url();
128
+
129
+            /**
130
+             * Maybe load CSS
131
+             *
132
+             * We load super early in case there is a theme version that might change the colors
133
+             */
134
+            if ( $this->settings['css'] ) {
135
+                add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 1 );
136
+            }
137
+            if ( $this->settings['css_backend'] ) {
138
+                add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 1 );
139
+            }
140
+
141
+            // maybe load JS
142
+            if ( $this->settings['js'] ) {
143
+                add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 );
144
+            }
145
+            if ( $this->settings['js_backend'] ) {
146
+                add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 );
147
+            }
148
+
149
+            // Maybe set the HTML font size
150
+            if ( $this->settings['html_font_size'] ) {
151
+                add_action( 'wp_footer', array( $this, 'html_font_size' ), 10 );
152
+            }
153
+
154
+
155
+        }
156
+
157
+        /**
158
+         * Add a html font size to the footer.
159
+         */
160
+        public function html_font_size(){
161
+            $this->settings = $this->get_settings();
162
+            echo "<style>html{font-size:".absint($this->settings['html_font_size'])."px;}</style>";
163
+        }
164
+
165
+        /**
166
+         * Adds the Font Awesome styles.
167
+         */
168
+        public function enqueue_style() {
169
+
170
+            $css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend';
171
+
172
+            if($this->settings[$css_setting]){
173
+                $compatibility = $this->settings[$css_setting]=='core' ? false : true;
174
+                $url = $this->settings[$css_setting]=='core' ? $this->url.'assets/css/ayecode-ui.css' : $this->url.'assets/css/ayecode-ui-compatibility.css';
175
+                wp_register_style( 'ayecode-ui', $url, array(), $this->latest );
176
+                wp_enqueue_style( 'ayecode-ui' );
177
+
178
+                // flatpickr
179
+                wp_register_style( 'flatpickr', $this->url.'assets/css/flatpickr.min.css', array(), $this->latest );
180
+
181
+
182
+                // fix some wp-admin issues
183
+                if(is_admin()){
184
+                    $custom_css = "
185 185
                 body{
186 186
                     background-color: #f1f1f1;
187 187
                     font-family: -apple-system,BlinkMacSystemFont,\"Segoe UI\",Roboto,Oxygen-Sans,Ubuntu,Cantarell,\"Helvetica Neue\",sans-serif;
@@ -216,23 +216,23 @@  discard block
 block discarded – undo
216 216
 				    margin: 1em 0
217 217
 				}
218 218
                 ";
219
-					wp_add_inline_style( 'ayecode-ui', $custom_css );
220
-				}
219
+                    wp_add_inline_style( 'ayecode-ui', $custom_css );
220
+                }
221 221
 
222
-				// custom changes
223
-				wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) );
222
+                // custom changes
223
+                wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) );
224 224
 
225
-			}
226
-		}
225
+            }
226
+        }
227 227
 
228
-		/**
229
-		 * Get inline script used if bootstrap enqueued
230
-		 *
231
-		 * If this remains small then its best to use this than to add another JS file.
232
-		 */
233
-		public function inline_script(){
234
-			ob_start();
235
-			?>
228
+        /**
229
+         * Get inline script used if bootstrap enqueued
230
+         *
231
+         * If this remains small then its best to use this than to add another JS file.
232
+         */
233
+        public function inline_script(){
234
+            ob_start();
235
+            ?>
236 236
 			<script>
237 237
 
238 238
 				/**
@@ -444,25 +444,25 @@  discard block
 block discarded – undo
444 444
 				});
445 445
 			</script>
446 446
 			<?php
447
-			$output = ob_get_clean();
447
+            $output = ob_get_clean();
448 448
 
449
-			/*
449
+            /*
450 450
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
451 451
 			 */
452
-			return str_replace( array(
453
-				'<script>',
454
-				'</script>'
455
-			), '', $output );
456
-		}
457
-
458
-		/**
459
-		 * Get inline script used if bootstrap file browser enqueued.
460
-		 *
461
-		 * If this remains small then its best to use this than to add another JS file.
462
-		 */
463
-		public function inline_script_file_browser(){
464
-			ob_start();
465
-			?>
452
+            return str_replace( array(
453
+                '<script>',
454
+                '</script>'
455
+            ), '', $output );
456
+        }
457
+
458
+        /**
459
+         * Get inline script used if bootstrap file browser enqueued.
460
+         *
461
+         * If this remains small then its best to use this than to add another JS file.
462
+         */
463
+        public function inline_script_file_browser(){
464
+            ob_start();
465
+            ?>
466 466
 			<script>
467 467
 				// run on doc ready
468 468
 				jQuery(document).ready(function () {
@@ -470,183 +470,183 @@  discard block
 block discarded – undo
470 470
 				});
471 471
 			</script>
472 472
 			<?php
473
-			$output = ob_get_clean();
473
+            $output = ob_get_clean();
474 474
 
475
-			/*
475
+            /*
476 476
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
477 477
 			 */
478
-			return str_replace( array(
479
-				'<script>',
480
-				'</script>'
481
-			), '', $output );
482
-		}
483
-
484
-		/**
485
-		 * Adds the Font Awesome JS.
486
-		 */
487
-		public function enqueue_scripts() {
488
-
489
-			$js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend';
490
-
491
-			// select2
492
-			wp_register_script( 'select2', $this->url.'assets/js/select2.min.js', array('jquery'), $this->select2_version );
493
-
494
-			// flatpickr
495
-			wp_register_script( 'flatpickr', $this->url.'assets/js/flatpickr.min.js', array(), $this->latest );
496
-
497
-			// Bootstrap file browser
498
-			wp_register_script( 'aui-custom-file-input', $url = $this->url.'assets/js/bs-custom-file-input.min.js', array('jquery'), $this->select2_version );
499
-			wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() );
500
-
501
-			$load_inline = false;
502
-
503
-			if($this->settings[$js_setting]=='core-popper'){
504
-				// Bootstrap bundle
505
-				$url = $this->url.'assets/js/bootstrap.bundle.min.js';
506
-				wp_register_script( 'bootstrap-js-bundle', $url, array('select2','jquery'), $this->latest );
507
-				wp_enqueue_script( 'bootstrap-js-bundle' );
508
-				$script = $this->inline_script();
509
-				wp_add_inline_script( 'bootstrap-js-bundle', $script );
510
-			}elseif($this->settings[$js_setting]=='popper'){
511
-				$url = $this->url.'assets/js/popper.min.js';
512
-				wp_register_script( 'bootstrap-js-popper', $url, array('jquery'), $this->latest );
513
-				wp_enqueue_script( 'bootstrap-js-popper' );
514
-				$load_inline = true;
515
-			}else{
516
-				$load_inline = true;
517
-			}
518
-
519
-			// Load needed inline scripts by faking the loading of a script if the main script is not being loaded
520
-			if($load_inline){
521
-				wp_register_script( 'bootstrap-dummy', '',array('jquery') );
522
-				wp_enqueue_script( 'bootstrap-dummy' );
523
-				$script = $this->inline_script();
524
-				wp_add_inline_script( 'bootstrap-dummy', $script  );
525
-			}
526
-
527
-		}
528
-
529
-		/**
530
-		 * Enqueue flatpickr if called.
531
-		 */
532
-		public function enqueue_flatpickr(){
533
-			wp_enqueue_style( 'flatpickr' );
534
-			wp_enqueue_script( 'flatpickr' );
535
-		}
536
-
537
-		/**
538
-		 * Get the url path to the current folder.
539
-		 *
540
-		 * @return string
541
-		 */
542
-		public function get_url() {
543
-
544
-			$url = '';
545
-			// check if we are inside a plugin
546
-			$file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) );
547
-
548
-			// add check in-case user has changed wp-content dir name.
549
-			$wp_content_folder_name = basename(WP_CONTENT_DIR);
550
-			$dir_parts = explode("/$wp_content_folder_name/",$file_dir);
551
-			$url_parts = explode("/$wp_content_folder_name/",plugins_url());
552
-
553
-			if(!empty($url_parts[0]) && !empty($dir_parts[1])){
554
-				$url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] );
555
-			}
556
-
557
-			return $url;
558
-		}
559
-
560
-		/**
561
-		 * Register the database settings with WordPress.
562
-		 */
563
-		public function register_settings() {
564
-			register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' );
565
-		}
566
-
567
-		/**
568
-		 * Add the WordPress settings menu item.
569
-		 * @since 1.0.10 Calling function name direct will fail theme check so we don't.
570
-		 */
571
-		public function menu_item() {
572
-			$menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
573
-			call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array(
574
-				$this,
575
-				'settings_page'
576
-			) );
577
-		}
578
-
579
-		/**
580
-		 * Get a list of themes and their default JS settings.
581
-		 *
582
-		 * @return array
583
-		 */
584
-		public function theme_js_settings(){
585
-			return array(
586
-				'ayetheme' => 'popper',
587
-				'listimia' => 'required',
588
-				'listimia_backend' => 'core-popper',
589
-				'avada'    => 'required',
590
-			);
591
-		}
592
-
593
-		/**
594
-		 * Get the current Font Awesome output settings.
595
-		 *
596
-		 * @return array The array of settings.
597
-		 */
598
-		public function get_settings() {
599
-
600
-			$db_settings = get_option( 'ayecode-ui-settings' );
601
-			$js_default = 'core-popper';
602
-			$js_default_backend = $js_default;
603
-
604
-			// maybe set defaults (if no settings set)
605
-			if(empty($db_settings)){
606
-				$active_theme = strtolower( get_template() ); // active parent theme.
607
-				$theme_js_settings = self::theme_js_settings();
608
-				if(isset($theme_js_settings[$active_theme])){
609
-					$js_default = $theme_js_settings[$active_theme];
610
-					$js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default;
611
-				}
612
-			}
613
-
614
-			$defaults = array(
615
-				'css'       => 'compatibility', // core, compatibility
616
-				'js'        => $js_default, // js to load, core-popper, popper
617
-				'html_font_size'        => '16', // js to load, core-popper, popper
618
-				'css_backend'       => 'compatibility', // core, compatibility
619
-				'js_backend'        => $js_default_backend, // js to load, core-popper, popper
620
-
621
-			);
622
-
623
-			$settings = wp_parse_args( $db_settings, $defaults );
624
-
625
-			/**
626
-			 * Filter the Bootstrap settings.
627
-			 *
628
-			 * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
629
-			 */
630
-			return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults );
631
-		}
632
-
633
-
634
-		/**
635
-		 * The settings page html output.
636
-		 */
637
-		public function settings_page() {
638
-			if ( ! current_user_can( 'manage_options' ) ) {
639
-				wp_die( __( 'You do not have sufficient permissions to access this page.', 'aui' ) );
640
-			}
641
-			?>
478
+            return str_replace( array(
479
+                '<script>',
480
+                '</script>'
481
+            ), '', $output );
482
+        }
483
+
484
+        /**
485
+         * Adds the Font Awesome JS.
486
+         */
487
+        public function enqueue_scripts() {
488
+
489
+            $js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend';
490
+
491
+            // select2
492
+            wp_register_script( 'select2', $this->url.'assets/js/select2.min.js', array('jquery'), $this->select2_version );
493
+
494
+            // flatpickr
495
+            wp_register_script( 'flatpickr', $this->url.'assets/js/flatpickr.min.js', array(), $this->latest );
496
+
497
+            // Bootstrap file browser
498
+            wp_register_script( 'aui-custom-file-input', $url = $this->url.'assets/js/bs-custom-file-input.min.js', array('jquery'), $this->select2_version );
499
+            wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() );
500
+
501
+            $load_inline = false;
502
+
503
+            if($this->settings[$js_setting]=='core-popper'){
504
+                // Bootstrap bundle
505
+                $url = $this->url.'assets/js/bootstrap.bundle.min.js';
506
+                wp_register_script( 'bootstrap-js-bundle', $url, array('select2','jquery'), $this->latest );
507
+                wp_enqueue_script( 'bootstrap-js-bundle' );
508
+                $script = $this->inline_script();
509
+                wp_add_inline_script( 'bootstrap-js-bundle', $script );
510
+            }elseif($this->settings[$js_setting]=='popper'){
511
+                $url = $this->url.'assets/js/popper.min.js';
512
+                wp_register_script( 'bootstrap-js-popper', $url, array('jquery'), $this->latest );
513
+                wp_enqueue_script( 'bootstrap-js-popper' );
514
+                $load_inline = true;
515
+            }else{
516
+                $load_inline = true;
517
+            }
518
+
519
+            // Load needed inline scripts by faking the loading of a script if the main script is not being loaded
520
+            if($load_inline){
521
+                wp_register_script( 'bootstrap-dummy', '',array('jquery') );
522
+                wp_enqueue_script( 'bootstrap-dummy' );
523
+                $script = $this->inline_script();
524
+                wp_add_inline_script( 'bootstrap-dummy', $script  );
525
+            }
526
+
527
+        }
528
+
529
+        /**
530
+         * Enqueue flatpickr if called.
531
+         */
532
+        public function enqueue_flatpickr(){
533
+            wp_enqueue_style( 'flatpickr' );
534
+            wp_enqueue_script( 'flatpickr' );
535
+        }
536
+
537
+        /**
538
+         * Get the url path to the current folder.
539
+         *
540
+         * @return string
541
+         */
542
+        public function get_url() {
543
+
544
+            $url = '';
545
+            // check if we are inside a plugin
546
+            $file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) );
547
+
548
+            // add check in-case user has changed wp-content dir name.
549
+            $wp_content_folder_name = basename(WP_CONTENT_DIR);
550
+            $dir_parts = explode("/$wp_content_folder_name/",$file_dir);
551
+            $url_parts = explode("/$wp_content_folder_name/",plugins_url());
552
+
553
+            if(!empty($url_parts[0]) && !empty($dir_parts[1])){
554
+                $url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] );
555
+            }
556
+
557
+            return $url;
558
+        }
559
+
560
+        /**
561
+         * Register the database settings with WordPress.
562
+         */
563
+        public function register_settings() {
564
+            register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' );
565
+        }
566
+
567
+        /**
568
+         * Add the WordPress settings menu item.
569
+         * @since 1.0.10 Calling function name direct will fail theme check so we don't.
570
+         */
571
+        public function menu_item() {
572
+            $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
573
+            call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array(
574
+                $this,
575
+                'settings_page'
576
+            ) );
577
+        }
578
+
579
+        /**
580
+         * Get a list of themes and their default JS settings.
581
+         *
582
+         * @return array
583
+         */
584
+        public function theme_js_settings(){
585
+            return array(
586
+                'ayetheme' => 'popper',
587
+                'listimia' => 'required',
588
+                'listimia_backend' => 'core-popper',
589
+                'avada'    => 'required',
590
+            );
591
+        }
592
+
593
+        /**
594
+         * Get the current Font Awesome output settings.
595
+         *
596
+         * @return array The array of settings.
597
+         */
598
+        public function get_settings() {
599
+
600
+            $db_settings = get_option( 'ayecode-ui-settings' );
601
+            $js_default = 'core-popper';
602
+            $js_default_backend = $js_default;
603
+
604
+            // maybe set defaults (if no settings set)
605
+            if(empty($db_settings)){
606
+                $active_theme = strtolower( get_template() ); // active parent theme.
607
+                $theme_js_settings = self::theme_js_settings();
608
+                if(isset($theme_js_settings[$active_theme])){
609
+                    $js_default = $theme_js_settings[$active_theme];
610
+                    $js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default;
611
+                }
612
+            }
613
+
614
+            $defaults = array(
615
+                'css'       => 'compatibility', // core, compatibility
616
+                'js'        => $js_default, // js to load, core-popper, popper
617
+                'html_font_size'        => '16', // js to load, core-popper, popper
618
+                'css_backend'       => 'compatibility', // core, compatibility
619
+                'js_backend'        => $js_default_backend, // js to load, core-popper, popper
620
+
621
+            );
622
+
623
+            $settings = wp_parse_args( $db_settings, $defaults );
624
+
625
+            /**
626
+             * Filter the Bootstrap settings.
627
+             *
628
+             * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
629
+             */
630
+            return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults );
631
+        }
632
+
633
+
634
+        /**
635
+         * The settings page html output.
636
+         */
637
+        public function settings_page() {
638
+            if ( ! current_user_can( 'manage_options' ) ) {
639
+                wp_die( __( 'You do not have sufficient permissions to access this page.', 'aui' ) );
640
+            }
641
+            ?>
642 642
 			<div class="wrap">
643 643
 				<h1><?php echo $this->name; ?></h1>
644 644
 				<p><?php _e("Here you can adjust settings if you are having compatibility issues.","aui");?></p>
645 645
 				<form method="post" action="options.php">
646 646
 					<?php
647
-					settings_fields( 'ayecode-ui-settings' );
648
-					do_settings_sections( 'ayecode-ui-settings' );
649
-					?>
647
+                    settings_fields( 'ayecode-ui-settings' );
648
+                    do_settings_sections( 'ayecode-ui-settings' );
649
+                    ?>
650 650
 
651 651
 					<h2><?php _e( 'Frontend', 'aui' ); ?></h2>
652 652
 					<table class="form-table wpbs-table-settings">
@@ -716,485 +716,485 @@  discard block
 block discarded – undo
716 716
 					</table>
717 717
 
718 718
 					<?php
719
-					submit_button();
720
-					?>
719
+                    submit_button();
720
+                    ?>
721 721
 				</form>
722 722
 
723 723
 				<div id="wpbs-version"><?php echo $this->version; ?></div>
724 724
 			</div>
725 725
 
726 726
 			<?php
727
-		}
728
-
729
-		public function customizer_settings($wp_customize){
730
-			$wp_customize->add_section('aui_settings', array(
731
-				'title'    => __('AyeCode UI'),
732
-				'priority' => 120,
733
-			));
734
-
735
-			//  =============================
736
-			//  = Color Picker              =
737
-			//  =============================
738
-			$wp_customize->add_setting('aui_options[color_primary]', array(
739
-				'default'           => '#1e73be',
740
-				'sanitize_callback' => 'sanitize_hex_color',
741
-				'capability'        => 'edit_theme_options',
742
-				'type'              => 'option',
743
-				'transport'         => 'refresh',
744
-			));
745
-			$wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array(
746
-				'label'    => __('Primary Color'),
747
-				'section'  => 'aui_settings',
748
-				'settings' => 'aui_options[color_primary]',
749
-			)));
750
-
751
-			$wp_customize->add_setting('aui_options[color_secondary]', array(
752
-				'default'           => '#6c757d',
753
-				'sanitize_callback' => 'sanitize_hex_color',
754
-				'capability'        => 'edit_theme_options',
755
-				'type'              => 'option',
756
-				'transport'         => 'refresh',
757
-			));
758
-			$wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array(
759
-				'label'    => __('Secondary Color'),
760
-				'section'  => 'aui_settings',
761
-				'settings' => 'aui_options[color_secondary]',
762
-			)));
763
-		}
764
-
765
-
766
-		public static function custom_css($compatibility = true) {
767
-			$settings = get_option('aui_options');
768
-
769
-			ob_start();
770
-			?>
727
+        }
728
+
729
+        public function customizer_settings($wp_customize){
730
+            $wp_customize->add_section('aui_settings', array(
731
+                'title'    => __('AyeCode UI'),
732
+                'priority' => 120,
733
+            ));
734
+
735
+            //  =============================
736
+            //  = Color Picker              =
737
+            //  =============================
738
+            $wp_customize->add_setting('aui_options[color_primary]', array(
739
+                'default'           => '#1e73be',
740
+                'sanitize_callback' => 'sanitize_hex_color',
741
+                'capability'        => 'edit_theme_options',
742
+                'type'              => 'option',
743
+                'transport'         => 'refresh',
744
+            ));
745
+            $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array(
746
+                'label'    => __('Primary Color'),
747
+                'section'  => 'aui_settings',
748
+                'settings' => 'aui_options[color_primary]',
749
+            )));
750
+
751
+            $wp_customize->add_setting('aui_options[color_secondary]', array(
752
+                'default'           => '#6c757d',
753
+                'sanitize_callback' => 'sanitize_hex_color',
754
+                'capability'        => 'edit_theme_options',
755
+                'type'              => 'option',
756
+                'transport'         => 'refresh',
757
+            ));
758
+            $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array(
759
+                'label'    => __('Secondary Color'),
760
+                'section'  => 'aui_settings',
761
+                'settings' => 'aui_options[color_secondary]',
762
+            )));
763
+        }
764
+
765
+
766
+        public static function custom_css($compatibility = true) {
767
+            $settings = get_option('aui_options');
768
+
769
+            ob_start();
770
+            ?>
771 771
 			<style>
772 772
 				<?php
773
-					if(!empty($settings['color_primary']) && $settings['color_primary'] != "#1e73be"){
774
-						echo self::css_primary($settings['color_primary'],$compatibility);
775
-					}
773
+                    if(!empty($settings['color_primary']) && $settings['color_primary'] != "#1e73be"){
774
+                        echo self::css_primary($settings['color_primary'],$compatibility);
775
+                    }
776 776
 
777
-					if(!empty($settings['color_secondary']) && $settings['color_secondary'] != "#6c757d"){
778
-						echo self::css_secondary($settings['color_secondary'],$compatibility);
779
-					}
777
+                    if(!empty($settings['color_secondary']) && $settings['color_secondary'] != "#6c757d"){
778
+                        echo self::css_secondary($settings['color_secondary'],$compatibility);
779
+                    }
780 780
                 ?>
781 781
 			</style>
782 782
 			<?php
783 783
 
784 784
 
785
-			/*
785
+            /*
786 786
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
787 787
 			 */
788
-			return str_replace( array(
789
-				'<style>',
790
-				'</style>'
791
-			), '', ob_get_clean());
792
-		}
793
-
794
-		public static function css_primary($color_code,$compatibility){;
795
-			$color_code = sanitize_hex_color($color_code);
796
-			if(!$color_code){return '';}
797
-			/**
798
-			 * c = color, b = background color, o = border-color, f = fill
799
-			 */
800
-			$selectors = array(
801
-				'a' => array('c'),
802
-				'.btn-primary' => array('b','o'),
803
-				'.btn-primary.disabled' => array('b','o'),
804
-				'.btn-primary:disabled' => array('b','o'),
805
-				'.btn-outline-primary' => array('c','o'),
806
-				'.btn-outline-primary:hover' => array('b','o'),
807
-				'.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b','o'),
808
-				'.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b','o'),
809
-				'.show>.btn-outline-primary.dropdown-toggle' => array('b','o'),
810
-				'.btn-link' => array('c'),
811
-				'.dropdown-item.active' => array('b'),
812
-				'.custom-control-input:checked~.custom-control-label::before' => array('b','o'),
813
-				'.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b','o'),
788
+            return str_replace( array(
789
+                '<style>',
790
+                '</style>'
791
+            ), '', ob_get_clean());
792
+        }
793
+
794
+        public static function css_primary($color_code,$compatibility){;
795
+            $color_code = sanitize_hex_color($color_code);
796
+            if(!$color_code){return '';}
797
+            /**
798
+             * c = color, b = background color, o = border-color, f = fill
799
+             */
800
+            $selectors = array(
801
+                'a' => array('c'),
802
+                '.btn-primary' => array('b','o'),
803
+                '.btn-primary.disabled' => array('b','o'),
804
+                '.btn-primary:disabled' => array('b','o'),
805
+                '.btn-outline-primary' => array('c','o'),
806
+                '.btn-outline-primary:hover' => array('b','o'),
807
+                '.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b','o'),
808
+                '.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b','o'),
809
+                '.show>.btn-outline-primary.dropdown-toggle' => array('b','o'),
810
+                '.btn-link' => array('c'),
811
+                '.dropdown-item.active' => array('b'),
812
+                '.custom-control-input:checked~.custom-control-label::before' => array('b','o'),
813
+                '.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b','o'),
814 814
 //				'.custom-range::-webkit-slider-thumb' => array('b'), // these break the inline rules...
815 815
 //				'.custom-range::-moz-range-thumb' => array('b'),
816 816
 //				'.custom-range::-ms-thumb' => array('b'),
817
-				'.nav-pills .nav-link.active' => array('b'),
818
-				'.nav-pills .show>.nav-link' => array('b'),
819
-				'.page-link' => array('c'),
820
-				'.page-item.active .page-link' => array('b','o'),
821
-				'.badge-primary' => array('b'),
822
-				'.alert-primary' => array('b','o'),
823
-				'.progress-bar' => array('b'),
824
-				'.list-group-item.active' => array('b','o'),
825
-				'.bg-primary' => array('b','f'),
826
-				'.btn-link.btn-primary' => array('c'),
827
-				'.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array('b'),
828
-			);
829
-
830
-			$important_selectors = array(
831
-				'.bg-primary' => array('b','f'),
832
-				'.border-primary' => array('o'),
833
-				'.text-primary' => array('c'),
834
-			);
835
-
836
-			$color = array();
837
-			$color_i = array();
838
-			$background = array();
839
-			$background_i = array();
840
-			$border = array();
841
-			$border_i = array();
842
-			$fill = array();
843
-			$fill_i = array();
844
-
845
-			$output = '';
846
-
847
-			// build rules into each type
848
-			foreach($selectors as $selector => $types){
849
-				$selector = $compatibility ? ".bsui ".$selector : $selector;
850
-				$types = array_combine($types,$types);
851
-				if(isset($types['c'])){$color[] = $selector;}
852
-				if(isset($types['b'])){$background[] = $selector;}
853
-				if(isset($types['o'])){$border[] = $selector;}
854
-				if(isset($types['f'])){$fill[] = $selector;}
855
-			}
856
-
857
-			// build rules into each type
858
-			foreach($important_selectors as $selector => $types){
859
-				$selector = $compatibility ? ".bsui ".$selector : $selector;
860
-				$types = array_combine($types,$types);
861
-				if(isset($types['c'])){$color_i[] = $selector;}
862
-				if(isset($types['b'])){$background_i[] = $selector;}
863
-				if(isset($types['o'])){$border_i[] = $selector;}
864
-				if(isset($types['f'])){$fill_i[] = $selector;}
865
-			}
866
-
867
-			// add any color rules
868
-			if(!empty($color)){
869
-				$output .= implode(",",$color) . "{color: $color_code;} ";
870
-			}
871
-			if(!empty($color_i)){
872
-				$output .= implode(",",$color_i) . "{color: $color_code !important;} ";
873
-			}
874
-
875
-			// add any background color rules
876
-			if(!empty($background)){
877
-				$output .= implode(",",$background) . "{background-color: $color_code;} ";
878
-			}
879
-			if(!empty($background_i)){
880
-				$output .= implode(",",$background_i) . "{background-color: $color_code !important;} ";
881
-			}
882
-
883
-			// add any border color rules
884
-			if(!empty($border)){
885
-				$output .= implode(",",$border) . "{border-color: $color_code;} ";
886
-			}
887
-			if(!empty($border_i)){
888
-				$output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
889
-			}
890
-
891
-			// add any fill color rules
892
-			if(!empty($fill)){
893
-				$output .= implode(",",$fill) . "{fill: $color_code;} ";
894
-			}
895
-			if(!empty($fill_i)){
896
-				$output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
897
-			}
898
-
899
-
900
-			$prefix = $compatibility ? ".bsui " : "";
901
-
902
-			// darken
903
-			$darker_075 = self::css_hex_lighten_darken($color_code,"-0.075");
904
-			$darker_10 = self::css_hex_lighten_darken($color_code,"-0.10");
905
-			$darker_125 = self::css_hex_lighten_darken($color_code,"-0.125");
906
-
907
-			// lighten
908
-			$lighten_25 = self::css_hex_lighten_darken($color_code,"0.25");
909
-
910
-			// opacity see https://css-tricks.com/8-digit-hex-codes/
911
-			$op_25 = $color_code."40"; // 25% opacity
912
-
913
-
914
-			// button states
915
-			$output .= $prefix ." .btn-primary:hover{background-color: ".$darker_075.";    border-color: ".$darker_10.";} ";
916
-			$output .= $prefix ." .btn-outline-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-primary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
917
-			$output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active, $prefix .btn-primary:not(:disabled):not(.disabled).active, .show>$prefix .btn-primary.dropdown-toggle{background-color: ".$darker_10.";    border-color: ".$darker_125.";} ";
918
-			$output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-primary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} ";
919
-
920
-
921
-			// dropdown's
922
-			$output .= $prefix ." .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} ";
923
-
924
-
925
-			// input states
926
-			$output .= $prefix ." .form-control:focus{border-color: ".$lighten_25.";box-shadow: 0 0 0 0.2rem $op_25;} ";
927
-
928
-			// page link
929
-			$output .= $prefix ." .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
930
-
931
-			return $output;
932
-		}
933
-
934
-		public static function css_secondary($color_code,$compatibility){;
935
-			$color_code = sanitize_hex_color($color_code);
936
-			if(!$color_code){return '';}
937
-			/**
938
-			 * c = color, b = background color, o = border-color, f = fill
939
-			 */
940
-			$selectors = array(
941
-				'.btn-secondary' => array('b','o'),
942
-				'.btn-secondary.disabled' => array('b','o'),
943
-				'.btn-secondary:disabled' => array('b','o'),
944
-				'.btn-outline-secondary' => array('c','o'),
945
-				'.btn-outline-secondary:hover' => array('b','o'),
946
-				'.btn-outline-secondary.disabled' => array('c'),
947
-				'.btn-outline-secondary:disabled' => array('c'),
948
-				'.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b','o'),
949
-				'.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b','o'),
950
-				'.btn-outline-secondary.dropdown-toggle' => array('b','o'),
951
-				'.badge-secondary' => array('b'),
952
-				'.alert-secondary' => array('b','o'),
953
-				'.btn-link.btn-secondary' => array('c'),
954
-			);
955
-
956
-			$important_selectors = array(
957
-				'.bg-secondary' => array('b','f'),
958
-				'.border-secondary' => array('o'),
959
-				'.text-secondary' => array('c'),
960
-			);
961
-
962
-			$color = array();
963
-			$color_i = array();
964
-			$background = array();
965
-			$background_i = array();
966
-			$border = array();
967
-			$border_i = array();
968
-			$fill = array();
969
-			$fill_i = array();
970
-
971
-			$output = '';
972
-
973
-			// build rules into each type
974
-			foreach($selectors as $selector => $types){
975
-				$selector = $compatibility ? ".bsui ".$selector : $selector;
976
-				$types = array_combine($types,$types);
977
-				if(isset($types['c'])){$color[] = $selector;}
978
-				if(isset($types['b'])){$background[] = $selector;}
979
-				if(isset($types['o'])){$border[] = $selector;}
980
-				if(isset($types['f'])){$fill[] = $selector;}
981
-			}
982
-
983
-			// build rules into each type
984
-			foreach($important_selectors as $selector => $types){
985
-				$selector = $compatibility ? ".bsui ".$selector : $selector;
986
-				$types = array_combine($types,$types);
987
-				if(isset($types['c'])){$color_i[] = $selector;}
988
-				if(isset($types['b'])){$background_i[] = $selector;}
989
-				if(isset($types['o'])){$border_i[] = $selector;}
990
-				if(isset($types['f'])){$fill_i[] = $selector;}
991
-			}
992
-
993
-			// add any color rules
994
-			if(!empty($color)){
995
-				$output .= implode(",",$color) . "{color: $color_code;} ";
996
-			}
997
-			if(!empty($color_i)){
998
-				$output .= implode(",",$color_i) . "{color: $color_code !important;} ";
999
-			}
1000
-
1001
-			// add any background color rules
1002
-			if(!empty($background)){
1003
-				$output .= implode(",",$background) . "{background-color: $color_code;} ";
1004
-			}
1005
-			if(!empty($background_i)){
1006
-				$output .= implode(",",$background_i) . "{background-color: $color_code !important;} ";
1007
-			}
1008
-
1009
-			// add any border color rules
1010
-			if(!empty($border)){
1011
-				$output .= implode(",",$border) . "{border-color: $color_code;} ";
1012
-			}
1013
-			if(!empty($border_i)){
1014
-				$output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
1015
-			}
1016
-
1017
-			// add any fill color rules
1018
-			if(!empty($fill)){
1019
-				$output .= implode(",",$fill) . "{fill: $color_code;} ";
1020
-			}
1021
-			if(!empty($fill_i)){
1022
-				$output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
1023
-			}
1024
-
1025
-
1026
-			$prefix = $compatibility ? ".bsui " : "";
1027
-
1028
-			// darken
1029
-			$darker_075 = self::css_hex_lighten_darken($color_code,"-0.075");
1030
-			$darker_10 = self::css_hex_lighten_darken($color_code,"-0.10");
1031
-			$darker_125 = self::css_hex_lighten_darken($color_code,"-0.125");
1032
-
1033
-			// lighten
1034
-			$lighten_25 = self::css_hex_lighten_darken($color_code,"0.25");
1035
-
1036
-			// opacity see https://css-tricks.com/8-digit-hex-codes/
1037
-			$op_25 = $color_code."40"; // 25% opacity
1038
-
1039
-
1040
-			// button states
1041
-			$output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075.";    border-color: ".$darker_10.";} ";
1042
-			$output .= $prefix ." .btn-outline-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-secondary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1043
-			$output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active, $prefix .btn-secondary:not(:disabled):not(.disabled).active, .show>$prefix .btn-secondary.dropdown-toggle{background-color: ".$darker_10.";    border-color: ".$darker_125.";} ";
1044
-			$output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-secondary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} ";
1045
-
1046
-
1047
-			return $output;
1048
-		}
1049
-
1050
-		/**
1051
-		 * Increases or decreases the brightness of a color by a percentage of the current brightness.
1052
-		 *
1053
-		 * @param   string  $hexCode        Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF`
1054
-		 * @param   float   $adjustPercent  A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker.
1055
-		 *
1056
-		 * @return  string
1057
-		 */
1058
-		public static function css_hex_lighten_darken($hexCode, $adjustPercent) {
1059
-			$hexCode = ltrim($hexCode, '#');
1060
-
1061
-			if (strlen($hexCode) == 3) {
1062
-				$hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2];
1063
-			}
1064
-
1065
-			$hexCode = array_map('hexdec', str_split($hexCode, 2));
1066
-
1067
-			foreach ($hexCode as & $color) {
1068
-				$adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color;
1069
-				$adjustAmount = ceil($adjustableLimit * $adjustPercent);
1070
-
1071
-				$color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT);
1072
-			}
1073
-
1074
-			return '#' . implode($hexCode);
1075
-		}
1076
-
1077
-		/**
1078
-		 * Check if we should display examples.
1079
-		 */
1080
-		public function maybe_show_examples(){
1081
-			if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){
1082
-				echo "<head>";
1083
-				wp_head();
1084
-				echo "</head>";
1085
-				echo "<body>";
1086
-				echo $this->get_examples();
1087
-				echo "</body>";
1088
-				exit;
1089
-			}
1090
-		}
1091
-
1092
-		/**
1093
-		 * Get developer examples.
1094
-		 *
1095
-		 * @return string
1096
-		 */
1097
-		public function get_examples(){
1098
-			$output = '';
1099
-
1100
-
1101
-			// open form
1102
-			$output .= "<form class='p-5 m-5 border rounded'>";
1103
-
1104
-			// input example
1105
-			$output .= aui()->input(array(
1106
-				'type'  =>  'text',
1107
-				'id'    =>  'text-example',
1108
-				'name'    =>  'text-example',
1109
-				'placeholder'   => 'text placeholder',
1110
-				'title'   => 'Text input example',
1111
-				'value' =>  '',
1112
-				'required'  => false,
1113
-				'help_text' => 'help text',
1114
-				'label' => 'Text input example label'
1115
-			));
1116
-
1117
-			// input example
1118
-			$output .= aui()->input(array(
1119
-				'type'  =>  'url',
1120
-				'id'    =>  'text-example2',
1121
-				'name'    =>  'text-example',
1122
-				'placeholder'   => 'url placeholder',
1123
-				'title'   => 'Text input example',
1124
-				'value' =>  '',
1125
-				'required'  => false,
1126
-				'help_text' => 'help text',
1127
-				'label' => 'Text input example label'
1128
-			));
1129
-
1130
-			// checkbox example
1131
-			$output .= aui()->input(array(
1132
-				'type'  =>  'checkbox',
1133
-				'id'    =>  'checkbox-example',
1134
-				'name'    =>  'checkbox-example',
1135
-				'placeholder'   => 'checkbox-example',
1136
-				'title'   => 'Checkbox example',
1137
-				'value' =>  '1',
1138
-				'checked'   => true,
1139
-				'required'  => false,
1140
-				'help_text' => 'help text',
1141
-				'label' => 'Checkbox checked'
1142
-			));
1143
-
1144
-			// checkbox example
1145
-			$output .= aui()->input(array(
1146
-				'type'  =>  'checkbox',
1147
-				'id'    =>  'checkbox-example2',
1148
-				'name'    =>  'checkbox-example2',
1149
-				'placeholder'   => 'checkbox-example',
1150
-				'title'   => 'Checkbox example',
1151
-				'value' =>  '1',
1152
-				'checked'   => false,
1153
-				'required'  => false,
1154
-				'help_text' => 'help text',
1155
-				'label' => 'Checkbox un-checked'
1156
-			));
1157
-
1158
-			// switch example
1159
-			$output .= aui()->input(array(
1160
-				'type'  =>  'checkbox',
1161
-				'id'    =>  'switch-example',
1162
-				'name'    =>  'switch-example',
1163
-				'placeholder'   => 'checkbox-example',
1164
-				'title'   => 'Switch example',
1165
-				'value' =>  '1',
1166
-				'checked'   => true,
1167
-				'switch'    => true,
1168
-				'required'  => false,
1169
-				'help_text' => 'help text',
1170
-				'label' => 'Switch on'
1171
-			));
1172
-
1173
-			// switch example
1174
-			$output .= aui()->input(array(
1175
-				'type'  =>  'checkbox',
1176
-				'id'    =>  'switch-example2',
1177
-				'name'    =>  'switch-example2',
1178
-				'placeholder'   => 'checkbox-example',
1179
-				'title'   => 'Switch example',
1180
-				'value' =>  '1',
1181
-				'checked'   => false,
1182
-				'switch'    => true,
1183
-				'required'  => false,
1184
-				'help_text' => 'help text',
1185
-				'label' => 'Switch off'
1186
-			));
1187
-
1188
-			// close form
1189
-			$output .= "</form>";
1190
-
1191
-			return $output;
1192
-		}
1193
-
1194
-	}
1195
-
1196
-	/**
1197
-	 * Run the class if found.
1198
-	 */
1199
-	AyeCode_UI_Settings::instance();
817
+                '.nav-pills .nav-link.active' => array('b'),
818
+                '.nav-pills .show>.nav-link' => array('b'),
819
+                '.page-link' => array('c'),
820
+                '.page-item.active .page-link' => array('b','o'),
821
+                '.badge-primary' => array('b'),
822
+                '.alert-primary' => array('b','o'),
823
+                '.progress-bar' => array('b'),
824
+                '.list-group-item.active' => array('b','o'),
825
+                '.bg-primary' => array('b','f'),
826
+                '.btn-link.btn-primary' => array('c'),
827
+                '.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array('b'),
828
+            );
829
+
830
+            $important_selectors = array(
831
+                '.bg-primary' => array('b','f'),
832
+                '.border-primary' => array('o'),
833
+                '.text-primary' => array('c'),
834
+            );
835
+
836
+            $color = array();
837
+            $color_i = array();
838
+            $background = array();
839
+            $background_i = array();
840
+            $border = array();
841
+            $border_i = array();
842
+            $fill = array();
843
+            $fill_i = array();
844
+
845
+            $output = '';
846
+
847
+            // build rules into each type
848
+            foreach($selectors as $selector => $types){
849
+                $selector = $compatibility ? ".bsui ".$selector : $selector;
850
+                $types = array_combine($types,$types);
851
+                if(isset($types['c'])){$color[] = $selector;}
852
+                if(isset($types['b'])){$background[] = $selector;}
853
+                if(isset($types['o'])){$border[] = $selector;}
854
+                if(isset($types['f'])){$fill[] = $selector;}
855
+            }
856
+
857
+            // build rules into each type
858
+            foreach($important_selectors as $selector => $types){
859
+                $selector = $compatibility ? ".bsui ".$selector : $selector;
860
+                $types = array_combine($types,$types);
861
+                if(isset($types['c'])){$color_i[] = $selector;}
862
+                if(isset($types['b'])){$background_i[] = $selector;}
863
+                if(isset($types['o'])){$border_i[] = $selector;}
864
+                if(isset($types['f'])){$fill_i[] = $selector;}
865
+            }
866
+
867
+            // add any color rules
868
+            if(!empty($color)){
869
+                $output .= implode(",",$color) . "{color: $color_code;} ";
870
+            }
871
+            if(!empty($color_i)){
872
+                $output .= implode(",",$color_i) . "{color: $color_code !important;} ";
873
+            }
874
+
875
+            // add any background color rules
876
+            if(!empty($background)){
877
+                $output .= implode(",",$background) . "{background-color: $color_code;} ";
878
+            }
879
+            if(!empty($background_i)){
880
+                $output .= implode(",",$background_i) . "{background-color: $color_code !important;} ";
881
+            }
882
+
883
+            // add any border color rules
884
+            if(!empty($border)){
885
+                $output .= implode(",",$border) . "{border-color: $color_code;} ";
886
+            }
887
+            if(!empty($border_i)){
888
+                $output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
889
+            }
890
+
891
+            // add any fill color rules
892
+            if(!empty($fill)){
893
+                $output .= implode(",",$fill) . "{fill: $color_code;} ";
894
+            }
895
+            if(!empty($fill_i)){
896
+                $output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
897
+            }
898
+
899
+
900
+            $prefix = $compatibility ? ".bsui " : "";
901
+
902
+            // darken
903
+            $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075");
904
+            $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10");
905
+            $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125");
906
+
907
+            // lighten
908
+            $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25");
909
+
910
+            // opacity see https://css-tricks.com/8-digit-hex-codes/
911
+            $op_25 = $color_code."40"; // 25% opacity
912
+
913
+
914
+            // button states
915
+            $output .= $prefix ." .btn-primary:hover{background-color: ".$darker_075.";    border-color: ".$darker_10.";} ";
916
+            $output .= $prefix ." .btn-outline-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-primary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
917
+            $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active, $prefix .btn-primary:not(:disabled):not(.disabled).active, .show>$prefix .btn-primary.dropdown-toggle{background-color: ".$darker_10.";    border-color: ".$darker_125.";} ";
918
+            $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-primary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} ";
919
+
920
+
921
+            // dropdown's
922
+            $output .= $prefix ." .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} ";
923
+
924
+
925
+            // input states
926
+            $output .= $prefix ." .form-control:focus{border-color: ".$lighten_25.";box-shadow: 0 0 0 0.2rem $op_25;} ";
927
+
928
+            // page link
929
+            $output .= $prefix ." .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
930
+
931
+            return $output;
932
+        }
933
+
934
+        public static function css_secondary($color_code,$compatibility){;
935
+            $color_code = sanitize_hex_color($color_code);
936
+            if(!$color_code){return '';}
937
+            /**
938
+             * c = color, b = background color, o = border-color, f = fill
939
+             */
940
+            $selectors = array(
941
+                '.btn-secondary' => array('b','o'),
942
+                '.btn-secondary.disabled' => array('b','o'),
943
+                '.btn-secondary:disabled' => array('b','o'),
944
+                '.btn-outline-secondary' => array('c','o'),
945
+                '.btn-outline-secondary:hover' => array('b','o'),
946
+                '.btn-outline-secondary.disabled' => array('c'),
947
+                '.btn-outline-secondary:disabled' => array('c'),
948
+                '.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b','o'),
949
+                '.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b','o'),
950
+                '.btn-outline-secondary.dropdown-toggle' => array('b','o'),
951
+                '.badge-secondary' => array('b'),
952
+                '.alert-secondary' => array('b','o'),
953
+                '.btn-link.btn-secondary' => array('c'),
954
+            );
955
+
956
+            $important_selectors = array(
957
+                '.bg-secondary' => array('b','f'),
958
+                '.border-secondary' => array('o'),
959
+                '.text-secondary' => array('c'),
960
+            );
961
+
962
+            $color = array();
963
+            $color_i = array();
964
+            $background = array();
965
+            $background_i = array();
966
+            $border = array();
967
+            $border_i = array();
968
+            $fill = array();
969
+            $fill_i = array();
970
+
971
+            $output = '';
972
+
973
+            // build rules into each type
974
+            foreach($selectors as $selector => $types){
975
+                $selector = $compatibility ? ".bsui ".$selector : $selector;
976
+                $types = array_combine($types,$types);
977
+                if(isset($types['c'])){$color[] = $selector;}
978
+                if(isset($types['b'])){$background[] = $selector;}
979
+                if(isset($types['o'])){$border[] = $selector;}
980
+                if(isset($types['f'])){$fill[] = $selector;}
981
+            }
982
+
983
+            // build rules into each type
984
+            foreach($important_selectors as $selector => $types){
985
+                $selector = $compatibility ? ".bsui ".$selector : $selector;
986
+                $types = array_combine($types,$types);
987
+                if(isset($types['c'])){$color_i[] = $selector;}
988
+                if(isset($types['b'])){$background_i[] = $selector;}
989
+                if(isset($types['o'])){$border_i[] = $selector;}
990
+                if(isset($types['f'])){$fill_i[] = $selector;}
991
+            }
992
+
993
+            // add any color rules
994
+            if(!empty($color)){
995
+                $output .= implode(",",$color) . "{color: $color_code;} ";
996
+            }
997
+            if(!empty($color_i)){
998
+                $output .= implode(",",$color_i) . "{color: $color_code !important;} ";
999
+            }
1000
+
1001
+            // add any background color rules
1002
+            if(!empty($background)){
1003
+                $output .= implode(",",$background) . "{background-color: $color_code;} ";
1004
+            }
1005
+            if(!empty($background_i)){
1006
+                $output .= implode(",",$background_i) . "{background-color: $color_code !important;} ";
1007
+            }
1008
+
1009
+            // add any border color rules
1010
+            if(!empty($border)){
1011
+                $output .= implode(",",$border) . "{border-color: $color_code;} ";
1012
+            }
1013
+            if(!empty($border_i)){
1014
+                $output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
1015
+            }
1016
+
1017
+            // add any fill color rules
1018
+            if(!empty($fill)){
1019
+                $output .= implode(",",$fill) . "{fill: $color_code;} ";
1020
+            }
1021
+            if(!empty($fill_i)){
1022
+                $output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
1023
+            }
1024
+
1025
+
1026
+            $prefix = $compatibility ? ".bsui " : "";
1027
+
1028
+            // darken
1029
+            $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075");
1030
+            $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10");
1031
+            $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125");
1032
+
1033
+            // lighten
1034
+            $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25");
1035
+
1036
+            // opacity see https://css-tricks.com/8-digit-hex-codes/
1037
+            $op_25 = $color_code."40"; // 25% opacity
1038
+
1039
+
1040
+            // button states
1041
+            $output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075.";    border-color: ".$darker_10.";} ";
1042
+            $output .= $prefix ." .btn-outline-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-secondary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1043
+            $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active, $prefix .btn-secondary:not(:disabled):not(.disabled).active, .show>$prefix .btn-secondary.dropdown-toggle{background-color: ".$darker_10.";    border-color: ".$darker_125.";} ";
1044
+            $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-secondary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} ";
1045
+
1046
+
1047
+            return $output;
1048
+        }
1049
+
1050
+        /**
1051
+         * Increases or decreases the brightness of a color by a percentage of the current brightness.
1052
+         *
1053
+         * @param   string  $hexCode        Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF`
1054
+         * @param   float   $adjustPercent  A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker.
1055
+         *
1056
+         * @return  string
1057
+         */
1058
+        public static function css_hex_lighten_darken($hexCode, $adjustPercent) {
1059
+            $hexCode = ltrim($hexCode, '#');
1060
+
1061
+            if (strlen($hexCode) == 3) {
1062
+                $hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2];
1063
+            }
1064
+
1065
+            $hexCode = array_map('hexdec', str_split($hexCode, 2));
1066
+
1067
+            foreach ($hexCode as & $color) {
1068
+                $adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color;
1069
+                $adjustAmount = ceil($adjustableLimit * $adjustPercent);
1070
+
1071
+                $color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT);
1072
+            }
1073
+
1074
+            return '#' . implode($hexCode);
1075
+        }
1076
+
1077
+        /**
1078
+         * Check if we should display examples.
1079
+         */
1080
+        public function maybe_show_examples(){
1081
+            if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){
1082
+                echo "<head>";
1083
+                wp_head();
1084
+                echo "</head>";
1085
+                echo "<body>";
1086
+                echo $this->get_examples();
1087
+                echo "</body>";
1088
+                exit;
1089
+            }
1090
+        }
1091
+
1092
+        /**
1093
+         * Get developer examples.
1094
+         *
1095
+         * @return string
1096
+         */
1097
+        public function get_examples(){
1098
+            $output = '';
1099
+
1100
+
1101
+            // open form
1102
+            $output .= "<form class='p-5 m-5 border rounded'>";
1103
+
1104
+            // input example
1105
+            $output .= aui()->input(array(
1106
+                'type'  =>  'text',
1107
+                'id'    =>  'text-example',
1108
+                'name'    =>  'text-example',
1109
+                'placeholder'   => 'text placeholder',
1110
+                'title'   => 'Text input example',
1111
+                'value' =>  '',
1112
+                'required'  => false,
1113
+                'help_text' => 'help text',
1114
+                'label' => 'Text input example label'
1115
+            ));
1116
+
1117
+            // input example
1118
+            $output .= aui()->input(array(
1119
+                'type'  =>  'url',
1120
+                'id'    =>  'text-example2',
1121
+                'name'    =>  'text-example',
1122
+                'placeholder'   => 'url placeholder',
1123
+                'title'   => 'Text input example',
1124
+                'value' =>  '',
1125
+                'required'  => false,
1126
+                'help_text' => 'help text',
1127
+                'label' => 'Text input example label'
1128
+            ));
1129
+
1130
+            // checkbox example
1131
+            $output .= aui()->input(array(
1132
+                'type'  =>  'checkbox',
1133
+                'id'    =>  'checkbox-example',
1134
+                'name'    =>  'checkbox-example',
1135
+                'placeholder'   => 'checkbox-example',
1136
+                'title'   => 'Checkbox example',
1137
+                'value' =>  '1',
1138
+                'checked'   => true,
1139
+                'required'  => false,
1140
+                'help_text' => 'help text',
1141
+                'label' => 'Checkbox checked'
1142
+            ));
1143
+
1144
+            // checkbox example
1145
+            $output .= aui()->input(array(
1146
+                'type'  =>  'checkbox',
1147
+                'id'    =>  'checkbox-example2',
1148
+                'name'    =>  'checkbox-example2',
1149
+                'placeholder'   => 'checkbox-example',
1150
+                'title'   => 'Checkbox example',
1151
+                'value' =>  '1',
1152
+                'checked'   => false,
1153
+                'required'  => false,
1154
+                'help_text' => 'help text',
1155
+                'label' => 'Checkbox un-checked'
1156
+            ));
1157
+
1158
+            // switch example
1159
+            $output .= aui()->input(array(
1160
+                'type'  =>  'checkbox',
1161
+                'id'    =>  'switch-example',
1162
+                'name'    =>  'switch-example',
1163
+                'placeholder'   => 'checkbox-example',
1164
+                'title'   => 'Switch example',
1165
+                'value' =>  '1',
1166
+                'checked'   => true,
1167
+                'switch'    => true,
1168
+                'required'  => false,
1169
+                'help_text' => 'help text',
1170
+                'label' => 'Switch on'
1171
+            ));
1172
+
1173
+            // switch example
1174
+            $output .= aui()->input(array(
1175
+                'type'  =>  'checkbox',
1176
+                'id'    =>  'switch-example2',
1177
+                'name'    =>  'switch-example2',
1178
+                'placeholder'   => 'checkbox-example',
1179
+                'title'   => 'Switch example',
1180
+                'value' =>  '1',
1181
+                'checked'   => false,
1182
+                'switch'    => true,
1183
+                'required'  => false,
1184
+                'help_text' => 'help text',
1185
+                'label' => 'Switch off'
1186
+            ));
1187
+
1188
+            // close form
1189
+            $output .= "</form>";
1190
+
1191
+            return $output;
1192
+        }
1193
+
1194
+    }
1195
+
1196
+    /**
1197
+     * Run the class if found.
1198
+     */
1199
+    AyeCode_UI_Settings::instance();
1200 1200
 }
1201 1201
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +223 added lines, -223 removed lines patch added patch discarded remove patch
@@ -12,14 +12,14 @@  discard block
 block discarded – undo
12 12
 /**
13 13
  * Bail if we are not in WP.
14 14
  */
15
-if ( ! defined( 'ABSPATH' ) ) {
15
+if (!defined('ABSPATH')) {
16 16
 	exit;
17 17
 }
18 18
 
19 19
 /**
20 20
  * Only add if the class does not already exist.
21 21
  */
22
-if ( ! class_exists( 'AyeCode_UI_Settings' ) ) {
22
+if (!class_exists('AyeCode_UI_Settings')) {
23 23
 
24 24
 	/**
25 25
 	 * A Class to be able to change settings for Font Awesome.
@@ -98,22 +98,22 @@  discard block
 block discarded – undo
98 98
 		 * @return AyeCode_UI_Settings - Main instance.
99 99
 		 */
100 100
 		public static function instance() {
101
-			if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_UI_Settings ) ) {
101
+			if (!isset(self::$instance) && !(self::$instance instanceof AyeCode_UI_Settings)) {
102 102
 				self::$instance = new AyeCode_UI_Settings;
103 103
 
104
-				add_action( 'init', array( self::$instance, 'init' ) ); // set settings
104
+				add_action('init', array(self::$instance, 'init')); // set settings
105 105
 
106
-				if ( is_admin() ) {
107
-					add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
108
-					add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
106
+				if (is_admin()) {
107
+					add_action('admin_menu', array(self::$instance, 'menu_item'));
108
+					add_action('admin_init', array(self::$instance, 'register_settings'));
109 109
 
110 110
 					// Maybe show example page
111
-					add_action( 'template_redirect', array( self::$instance,'maybe_show_examples' ) );
111
+					add_action('template_redirect', array(self::$instance, 'maybe_show_examples'));
112 112
 				}
113 113
 
114
-				add_action( 'customize_register', array( self::$instance, 'customizer_settings' ));
114
+				add_action('customize_register', array(self::$instance, 'customizer_settings'));
115 115
 
116
-				do_action( 'ayecode_ui_settings_loaded' );
116
+				do_action('ayecode_ui_settings_loaded');
117 117
 			}
118 118
 
119 119
 			return self::$instance;
@@ -131,24 +131,24 @@  discard block
 block discarded – undo
131 131
 			 *
132 132
 			 * We load super early in case there is a theme version that might change the colors
133 133
 			 */
134
-			if ( $this->settings['css'] ) {
135
-				add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 1 );
134
+			if ($this->settings['css']) {
135
+				add_action('wp_enqueue_scripts', array($this, 'enqueue_style'), 1);
136 136
 			}
137
-			if ( $this->settings['css_backend'] ) {
138
-				add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 1 );
137
+			if ($this->settings['css_backend']) {
138
+				add_action('admin_enqueue_scripts', array($this, 'enqueue_style'), 1);
139 139
 			}
140 140
 
141 141
 			// maybe load JS
142
-			if ( $this->settings['js'] ) {
143
-				add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 );
142
+			if ($this->settings['js']) {
143
+				add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 1);
144 144
 			}
145
-			if ( $this->settings['js_backend'] ) {
146
-				add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 );
145
+			if ($this->settings['js_backend']) {
146
+				add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'), 1);
147 147
 			}
148 148
 
149 149
 			// Maybe set the HTML font size
150
-			if ( $this->settings['html_font_size'] ) {
151
-				add_action( 'wp_footer', array( $this, 'html_font_size' ), 10 );
150
+			if ($this->settings['html_font_size']) {
151
+				add_action('wp_footer', array($this, 'html_font_size'), 10);
152 152
 			}
153 153
 
154 154
 
@@ -157,9 +157,9 @@  discard block
 block discarded – undo
157 157
 		/**
158 158
 		 * Add a html font size to the footer.
159 159
 		 */
160
-		public function html_font_size(){
160
+		public function html_font_size() {
161 161
 			$this->settings = $this->get_settings();
162
-			echo "<style>html{font-size:".absint($this->settings['html_font_size'])."px;}</style>";
162
+			echo "<style>html{font-size:" . absint($this->settings['html_font_size']) . "px;}</style>";
163 163
 		}
164 164
 
165 165
 		/**
@@ -169,18 +169,18 @@  discard block
 block discarded – undo
169 169
 
170 170
 			$css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend';
171 171
 
172
-			if($this->settings[$css_setting]){
173
-				$compatibility = $this->settings[$css_setting]=='core' ? false : true;
174
-				$url = $this->settings[$css_setting]=='core' ? $this->url.'assets/css/ayecode-ui.css' : $this->url.'assets/css/ayecode-ui-compatibility.css';
175
-				wp_register_style( 'ayecode-ui', $url, array(), $this->latest );
176
-				wp_enqueue_style( 'ayecode-ui' );
172
+			if ($this->settings[$css_setting]) {
173
+				$compatibility = $this->settings[$css_setting] == 'core' ? false : true;
174
+				$url = $this->settings[$css_setting] == 'core' ? $this->url . 'assets/css/ayecode-ui.css' : $this->url . 'assets/css/ayecode-ui-compatibility.css';
175
+				wp_register_style('ayecode-ui', $url, array(), $this->latest);
176
+				wp_enqueue_style('ayecode-ui');
177 177
 
178 178
 				// flatpickr
179
-				wp_register_style( 'flatpickr', $this->url.'assets/css/flatpickr.min.css', array(), $this->latest );
179
+				wp_register_style('flatpickr', $this->url . 'assets/css/flatpickr.min.css', array(), $this->latest);
180 180
 
181 181
 
182 182
 				// fix some wp-admin issues
183
-				if(is_admin()){
183
+				if (is_admin()) {
184 184
 					$custom_css = "
185 185
                 body{
186 186
                     background-color: #f1f1f1;
@@ -216,11 +216,11 @@  discard block
 block discarded – undo
216 216
 				    margin: 1em 0
217 217
 				}
218 218
                 ";
219
-					wp_add_inline_style( 'ayecode-ui', $custom_css );
219
+					wp_add_inline_style('ayecode-ui', $custom_css);
220 220
 				}
221 221
 
222 222
 				// custom changes
223
-				wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) );
223
+				wp_add_inline_style('ayecode-ui', self::custom_css($compatibility));
224 224
 
225 225
 			}
226 226
 		}
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
 		 *
231 231
 		 * If this remains small then its best to use this than to add another JS file.
232 232
 		 */
233
-		public function inline_script(){
233
+		public function inline_script() {
234 234
 			ob_start();
235 235
 			?>
236 236
 			<script>
@@ -449,10 +449,10 @@  discard block
 block discarded – undo
449 449
 			/*
450 450
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
451 451
 			 */
452
-			return str_replace( array(
452
+			return str_replace(array(
453 453
 				'<script>',
454 454
 				'</script>'
455
-			), '', $output );
455
+			), '', $output);
456 456
 		}
457 457
 
458 458
 		/**
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
 		 *
461 461
 		 * If this remains small then its best to use this than to add another JS file.
462 462
 		 */
463
-		public function inline_script_file_browser(){
463
+		public function inline_script_file_browser() {
464 464
 			ob_start();
465 465
 			?>
466 466
 			<script>
@@ -475,10 +475,10 @@  discard block
 block discarded – undo
475 475
 			/*
476 476
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
477 477
 			 */
478
-			return str_replace( array(
478
+			return str_replace(array(
479 479
 				'<script>',
480 480
 				'</script>'
481
-			), '', $output );
481
+			), '', $output);
482 482
 		}
483 483
 
484 484
 		/**
@@ -489,39 +489,39 @@  discard block
 block discarded – undo
489 489
 			$js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend';
490 490
 
491 491
 			// select2
492
-			wp_register_script( 'select2', $this->url.'assets/js/select2.min.js', array('jquery'), $this->select2_version );
492
+			wp_register_script('select2', $this->url . 'assets/js/select2.min.js', array('jquery'), $this->select2_version);
493 493
 
494 494
 			// flatpickr
495
-			wp_register_script( 'flatpickr', $this->url.'assets/js/flatpickr.min.js', array(), $this->latest );
495
+			wp_register_script('flatpickr', $this->url . 'assets/js/flatpickr.min.js', array(), $this->latest);
496 496
 
497 497
 			// Bootstrap file browser
498
-			wp_register_script( 'aui-custom-file-input', $url = $this->url.'assets/js/bs-custom-file-input.min.js', array('jquery'), $this->select2_version );
499
-			wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() );
498
+			wp_register_script('aui-custom-file-input', $url = $this->url . 'assets/js/bs-custom-file-input.min.js', array('jquery'), $this->select2_version);
499
+			wp_add_inline_script('aui-custom-file-input', $this->inline_script_file_browser());
500 500
 
501 501
 			$load_inline = false;
502 502
 
503
-			if($this->settings[$js_setting]=='core-popper'){
503
+			if ($this->settings[$js_setting] == 'core-popper') {
504 504
 				// Bootstrap bundle
505
-				$url = $this->url.'assets/js/bootstrap.bundle.min.js';
506
-				wp_register_script( 'bootstrap-js-bundle', $url, array('select2','jquery'), $this->latest );
507
-				wp_enqueue_script( 'bootstrap-js-bundle' );
505
+				$url = $this->url . 'assets/js/bootstrap.bundle.min.js';
506
+				wp_register_script('bootstrap-js-bundle', $url, array('select2', 'jquery'), $this->latest);
507
+				wp_enqueue_script('bootstrap-js-bundle');
508 508
 				$script = $this->inline_script();
509
-				wp_add_inline_script( 'bootstrap-js-bundle', $script );
510
-			}elseif($this->settings[$js_setting]=='popper'){
511
-				$url = $this->url.'assets/js/popper.min.js';
512
-				wp_register_script( 'bootstrap-js-popper', $url, array('jquery'), $this->latest );
513
-				wp_enqueue_script( 'bootstrap-js-popper' );
509
+				wp_add_inline_script('bootstrap-js-bundle', $script);
510
+			}elseif ($this->settings[$js_setting] == 'popper') {
511
+				$url = $this->url . 'assets/js/popper.min.js';
512
+				wp_register_script('bootstrap-js-popper', $url, array('jquery'), $this->latest);
513
+				wp_enqueue_script('bootstrap-js-popper');
514 514
 				$load_inline = true;
515
-			}else{
515
+			} else {
516 516
 				$load_inline = true;
517 517
 			}
518 518
 
519 519
 			// Load needed inline scripts by faking the loading of a script if the main script is not being loaded
520
-			if($load_inline){
521
-				wp_register_script( 'bootstrap-dummy', '',array('jquery') );
522
-				wp_enqueue_script( 'bootstrap-dummy' );
520
+			if ($load_inline) {
521
+				wp_register_script('bootstrap-dummy', '', array('jquery'));
522
+				wp_enqueue_script('bootstrap-dummy');
523 523
 				$script = $this->inline_script();
524
-				wp_add_inline_script( 'bootstrap-dummy', $script  );
524
+				wp_add_inline_script('bootstrap-dummy', $script);
525 525
 			}
526 526
 
527 527
 		}
@@ -529,9 +529,9 @@  discard block
 block discarded – undo
529 529
 		/**
530 530
 		 * Enqueue flatpickr if called.
531 531
 		 */
532
-		public function enqueue_flatpickr(){
533
-			wp_enqueue_style( 'flatpickr' );
534
-			wp_enqueue_script( 'flatpickr' );
532
+		public function enqueue_flatpickr() {
533
+			wp_enqueue_style('flatpickr');
534
+			wp_enqueue_script('flatpickr');
535 535
 		}
536 536
 
537 537
 		/**
@@ -543,15 +543,15 @@  discard block
 block discarded – undo
543 543
 
544 544
 			$url = '';
545 545
 			// check if we are inside a plugin
546
-			$file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) );
546
+			$file_dir = str_replace("/includes", "", wp_normalize_path(dirname(__FILE__)));
547 547
 
548 548
 			// add check in-case user has changed wp-content dir name.
549 549
 			$wp_content_folder_name = basename(WP_CONTENT_DIR);
550
-			$dir_parts = explode("/$wp_content_folder_name/",$file_dir);
551
-			$url_parts = explode("/$wp_content_folder_name/",plugins_url());
550
+			$dir_parts = explode("/$wp_content_folder_name/", $file_dir);
551
+			$url_parts = explode("/$wp_content_folder_name/", plugins_url());
552 552
 
553
-			if(!empty($url_parts[0]) && !empty($dir_parts[1])){
554
-				$url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] );
553
+			if (!empty($url_parts[0]) && !empty($dir_parts[1])) {
554
+				$url = trailingslashit($url_parts[0] . "/$wp_content_folder_name/" . $dir_parts[1]);
555 555
 			}
556 556
 
557 557
 			return $url;
@@ -561,7 +561,7 @@  discard block
 block discarded – undo
561 561
 		 * Register the database settings with WordPress.
562 562
 		 */
563 563
 		public function register_settings() {
564
-			register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' );
564
+			register_setting('ayecode-ui-settings', 'ayecode-ui-settings');
565 565
 		}
566 566
 
567 567
 		/**
@@ -570,10 +570,10 @@  discard block
 block discarded – undo
570 570
 		 */
571 571
 		public function menu_item() {
572 572
 			$menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
573
-			call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array(
573
+			call_user_func($menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array(
574 574
 				$this,
575 575
 				'settings_page'
576
-			) );
576
+			));
577 577
 		}
578 578
 
579 579
 		/**
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
 		 *
582 582
 		 * @return array
583 583
 		 */
584
-		public function theme_js_settings(){
584
+		public function theme_js_settings() {
585 585
 			return array(
586 586
 				'ayetheme' => 'popper',
587 587
 				'listimia' => 'required',
@@ -597,17 +597,17 @@  discard block
 block discarded – undo
597 597
 		 */
598 598
 		public function get_settings() {
599 599
 
600
-			$db_settings = get_option( 'ayecode-ui-settings' );
600
+			$db_settings = get_option('ayecode-ui-settings');
601 601
 			$js_default = 'core-popper';
602 602
 			$js_default_backend = $js_default;
603 603
 
604 604
 			// maybe set defaults (if no settings set)
605
-			if(empty($db_settings)){
606
-				$active_theme = strtolower( get_template() ); // active parent theme.
605
+			if (empty($db_settings)) {
606
+				$active_theme = strtolower(get_template()); // active parent theme.
607 607
 				$theme_js_settings = self::theme_js_settings();
608
-				if(isset($theme_js_settings[$active_theme])){
608
+				if (isset($theme_js_settings[$active_theme])) {
609 609
 					$js_default = $theme_js_settings[$active_theme];
610
-					$js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default;
610
+					$js_default_backend = isset($theme_js_settings[$active_theme . "_backend"]) ? $theme_js_settings[$active_theme . "_backend"] : $js_default;
611 611
 				}
612 612
 			}
613 613
 
@@ -620,14 +620,14 @@  discard block
 block discarded – undo
620 620
 
621 621
 			);
622 622
 
623
-			$settings = wp_parse_args( $db_settings, $defaults );
623
+			$settings = wp_parse_args($db_settings, $defaults);
624 624
 
625 625
 			/**
626 626
 			 * Filter the Bootstrap settings.
627 627
 			 *
628 628
 			 * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
629 629
 			 */
630
-			return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults );
630
+			return $this->settings = apply_filters('ayecode-ui-settings', $settings, $db_settings, $defaults);
631 631
 		}
632 632
 
633 633
 
@@ -635,80 +635,80 @@  discard block
 block discarded – undo
635 635
 		 * The settings page html output.
636 636
 		 */
637 637
 		public function settings_page() {
638
-			if ( ! current_user_can( 'manage_options' ) ) {
639
-				wp_die( __( 'You do not have sufficient permissions to access this page.', 'aui' ) );
638
+			if (!current_user_can('manage_options')) {
639
+				wp_die(__('You do not have sufficient permissions to access this page.', 'aui'));
640 640
 			}
641 641
 			?>
642 642
 			<div class="wrap">
643 643
 				<h1><?php echo $this->name; ?></h1>
644
-				<p><?php _e("Here you can adjust settings if you are having compatibility issues.","aui");?></p>
644
+				<p><?php _e("Here you can adjust settings if you are having compatibility issues.", "aui"); ?></p>
645 645
 				<form method="post" action="options.php">
646 646
 					<?php
647
-					settings_fields( 'ayecode-ui-settings' );
648
-					do_settings_sections( 'ayecode-ui-settings' );
647
+					settings_fields('ayecode-ui-settings');
648
+					do_settings_sections('ayecode-ui-settings');
649 649
 					?>
650 650
 
651
-					<h2><?php _e( 'Frontend', 'aui' ); ?></h2>
651
+					<h2><?php _e('Frontend', 'aui'); ?></h2>
652 652
 					<table class="form-table wpbs-table-settings">
653 653
 						<tr valign="top">
654 654
 							<th scope="row"><label
655
-									for="wpbs-css"><?php _e( 'Load CSS', 'aui' ); ?></label></th>
655
+									for="wpbs-css"><?php _e('Load CSS', 'aui'); ?></label></th>
656 656
 							<td>
657 657
 								<select name="ayecode-ui-settings[css]" id="wpbs-css">
658
-									<option	value="compatibility" <?php selected( $this->settings['css'], 'compatibility' ); ?>><?php _e( 'Compatibility Mode', 'aui' ); ?></option>
659
-									<option value="core" <?php selected( $this->settings['css'], 'core' ); ?>><?php _e( 'Full Mode', 'aui' ); ?></option>
660
-									<option	value="" <?php selected( $this->settings['css'], '' ); ?>><?php _e( 'Disabled', 'aui' ); ?></option>
658
+									<option	value="compatibility" <?php selected($this->settings['css'], 'compatibility'); ?>><?php _e('Compatibility Mode', 'aui'); ?></option>
659
+									<option value="core" <?php selected($this->settings['css'], 'core'); ?>><?php _e('Full Mode', 'aui'); ?></option>
660
+									<option	value="" <?php selected($this->settings['css'], ''); ?>><?php _e('Disabled', 'aui'); ?></option>
661 661
 								</select>
662 662
 							</td>
663 663
 						</tr>
664 664
 
665 665
 						<tr valign="top">
666 666
 							<th scope="row"><label
667
-									for="wpbs-js"><?php _e( 'Load JS', 'aui' ); ?></label></th>
667
+									for="wpbs-js"><?php _e('Load JS', 'aui'); ?></label></th>
668 668
 							<td>
669 669
 								<select name="ayecode-ui-settings[js]" id="wpbs-js">
670
-									<option	value="core-popper" <?php selected( $this->settings['js'], 'core-popper' ); ?>><?php _e( 'Core + Popper (default)', 'aui' ); ?></option>
671
-									<option value="popper" <?php selected( $this->settings['js'], 'popper' ); ?>><?php _e( 'Popper', 'aui' ); ?></option>
672
-									<option value="required" <?php selected( $this->settings['js'], 'required' ); ?>><?php _e( 'Required functions only', 'aui' ); ?></option>
673
-									<option	value="" <?php selected( $this->settings['js'], '' ); ?>><?php _e( 'Disabled (not recommended)', 'aui' ); ?></option>
670
+									<option	value="core-popper" <?php selected($this->settings['js'], 'core-popper'); ?>><?php _e('Core + Popper (default)', 'aui'); ?></option>
671
+									<option value="popper" <?php selected($this->settings['js'], 'popper'); ?>><?php _e('Popper', 'aui'); ?></option>
672
+									<option value="required" <?php selected($this->settings['js'], 'required'); ?>><?php _e('Required functions only', 'aui'); ?></option>
673
+									<option	value="" <?php selected($this->settings['js'], ''); ?>><?php _e('Disabled (not recommended)', 'aui'); ?></option>
674 674
 								</select>
675 675
 							</td>
676 676
 						</tr>
677 677
 
678 678
 						<tr valign="top">
679 679
 							<th scope="row"><label
680
-									for="wpbs-font_size"><?php _e( 'HTML Font Size (px)', 'aui' ); ?></label></th>
680
+									for="wpbs-font_size"><?php _e('HTML Font Size (px)', 'aui'); ?></label></th>
681 681
 							<td>
682
-								<input type="number" name="ayecode-ui-settings[html_font_size]" id="wpbs-font_size" value="<?php echo absint( $this->settings['html_font_size']); ?>" placeholder="16" />
683
-								<p class="description" ><?php _e("Our font sizing is rem (responsive based) here you can set the html font size in-case your theme is setting it too low.","aui");?></p>
682
+								<input type="number" name="ayecode-ui-settings[html_font_size]" id="wpbs-font_size" value="<?php echo absint($this->settings['html_font_size']); ?>" placeholder="16" />
683
+								<p class="description" ><?php _e("Our font sizing is rem (responsive based) here you can set the html font size in-case your theme is setting it too low.", "aui"); ?></p>
684 684
 							</td>
685 685
 						</tr>
686 686
 
687 687
 					</table>
688 688
 
689
-					<h2><?php _e( 'Backend', 'aui' ); ?> (wp-admin)</h2>
689
+					<h2><?php _e('Backend', 'aui'); ?> (wp-admin)</h2>
690 690
 					<table class="form-table wpbs-table-settings">
691 691
 						<tr valign="top">
692 692
 							<th scope="row"><label
693
-									for="wpbs-css"><?php _e( 'Load CSS', 'aui' ); ?></label></th>
693
+									for="wpbs-css"><?php _e('Load CSS', 'aui'); ?></label></th>
694 694
 							<td>
695 695
 								<select name="ayecode-ui-settings[css_backend]" id="wpbs-css">
696
-									<option	value="compatibility" <?php selected( $this->settings['css_backend'], 'compatibility' ); ?>><?php _e( 'Compatibility Mode', 'aui' ); ?></option>
697
-									<option value="core" <?php selected( $this->settings['css_backend'], 'core' ); ?>><?php _e( 'Full Mode', 'aui' ); ?></option>
698
-									<option	value="" <?php selected( $this->settings['css_backend'], '' ); ?>><?php _e( 'Disabled', 'aui' ); ?></option>
696
+									<option	value="compatibility" <?php selected($this->settings['css_backend'], 'compatibility'); ?>><?php _e('Compatibility Mode', 'aui'); ?></option>
697
+									<option value="core" <?php selected($this->settings['css_backend'], 'core'); ?>><?php _e('Full Mode', 'aui'); ?></option>
698
+									<option	value="" <?php selected($this->settings['css_backend'], ''); ?>><?php _e('Disabled', 'aui'); ?></option>
699 699
 								</select>
700 700
 							</td>
701 701
 						</tr>
702 702
 
703 703
 						<tr valign="top">
704 704
 							<th scope="row"><label
705
-									for="wpbs-js"><?php _e( 'Load JS', 'aui' ); ?></label></th>
705
+									for="wpbs-js"><?php _e('Load JS', 'aui'); ?></label></th>
706 706
 							<td>
707 707
 								<select name="ayecode-ui-settings[js_backend]" id="wpbs-js">
708
-									<option	value="core-popper" <?php selected( $this->settings['js_backend'], 'core-popper' ); ?>><?php _e( 'Core + Popper (default)', 'aui' ); ?></option>
709
-									<option value="popper" <?php selected( $this->settings['js_backend'], 'popper' ); ?>><?php _e( 'Popper', 'aui' ); ?></option>
710
-									<option value="required" <?php selected( $this->settings['js_backend'], 'required' ); ?>><?php _e( 'Required functions only', 'aui' ); ?></option>
711
-									<option	value="" <?php selected( $this->settings['js_backend'], '' ); ?>><?php _e( 'Disabled (not recommended)', 'aui' ); ?></option>
708
+									<option	value="core-popper" <?php selected($this->settings['js_backend'], 'core-popper'); ?>><?php _e('Core + Popper (default)', 'aui'); ?></option>
709
+									<option value="popper" <?php selected($this->settings['js_backend'], 'popper'); ?>><?php _e('Popper', 'aui'); ?></option>
710
+									<option value="required" <?php selected($this->settings['js_backend'], 'required'); ?>><?php _e('Required functions only', 'aui'); ?></option>
711
+									<option	value="" <?php selected($this->settings['js_backend'], ''); ?>><?php _e('Disabled (not recommended)', 'aui'); ?></option>
712 712
 								</select>
713 713
 							</td>
714 714
 						</tr>
@@ -726,7 +726,7 @@  discard block
 block discarded – undo
726 726
 			<?php
727 727
 		}
728 728
 
729
-		public function customizer_settings($wp_customize){
729
+		public function customizer_settings($wp_customize) {
730 730
 			$wp_customize->add_section('aui_settings', array(
731 731
 				'title'    => __('AyeCode UI'),
732 732
 				'priority' => 120,
@@ -742,7 +742,7 @@  discard block
 block discarded – undo
742 742
 				'type'              => 'option',
743 743
 				'transport'         => 'refresh',
744 744
 			));
745
-			$wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array(
745
+			$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'color_primary', array(
746 746
 				'label'    => __('Primary Color'),
747 747
 				'section'  => 'aui_settings',
748 748
 				'settings' => 'aui_options[color_primary]',
@@ -755,7 +755,7 @@  discard block
 block discarded – undo
755 755
 				'type'              => 'option',
756 756
 				'transport'         => 'refresh',
757 757
 			));
758
-			$wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array(
758
+			$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'color_secondary', array(
759 759
 				'label'    => __('Secondary Color'),
760 760
 				'section'  => 'aui_settings',
761 761
 				'settings' => 'aui_options[color_secondary]',
@@ -770,12 +770,12 @@  discard block
 block discarded – undo
770 770
 			?>
771 771
 			<style>
772 772
 				<?php
773
-					if(!empty($settings['color_primary']) && $settings['color_primary'] != "#1e73be"){
774
-						echo self::css_primary($settings['color_primary'],$compatibility);
773
+					if (!empty($settings['color_primary']) && $settings['color_primary'] != "#1e73be") {
774
+						echo self::css_primary($settings['color_primary'], $compatibility);
775 775
 					}
776 776
 
777
-					if(!empty($settings['color_secondary']) && $settings['color_secondary'] != "#6c757d"){
778
-						echo self::css_secondary($settings['color_secondary'],$compatibility);
777
+					if (!empty($settings['color_secondary']) && $settings['color_secondary'] != "#6c757d") {
778
+						echo self::css_secondary($settings['color_secondary'], $compatibility);
779 779
 					}
780 780
                 ?>
781 781
 			</style>
@@ -785,50 +785,50 @@  discard block
 block discarded – undo
785 785
 			/*
786 786
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
787 787
 			 */
788
-			return str_replace( array(
788
+			return str_replace(array(
789 789
 				'<style>',
790 790
 				'</style>'
791 791
 			), '', ob_get_clean());
792 792
 		}
793 793
 
794
-		public static function css_primary($color_code,$compatibility){;
794
+		public static function css_primary($color_code, $compatibility) {;
795 795
 			$color_code = sanitize_hex_color($color_code);
796
-			if(!$color_code){return '';}
796
+			if (!$color_code) {return ''; }
797 797
 			/**
798 798
 			 * c = color, b = background color, o = border-color, f = fill
799 799
 			 */
800 800
 			$selectors = array(
801 801
 				'a' => array('c'),
802
-				'.btn-primary' => array('b','o'),
803
-				'.btn-primary.disabled' => array('b','o'),
804
-				'.btn-primary:disabled' => array('b','o'),
805
-				'.btn-outline-primary' => array('c','o'),
806
-				'.btn-outline-primary:hover' => array('b','o'),
807
-				'.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b','o'),
808
-				'.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b','o'),
809
-				'.show>.btn-outline-primary.dropdown-toggle' => array('b','o'),
802
+				'.btn-primary' => array('b', 'o'),
803
+				'.btn-primary.disabled' => array('b', 'o'),
804
+				'.btn-primary:disabled' => array('b', 'o'),
805
+				'.btn-outline-primary' => array('c', 'o'),
806
+				'.btn-outline-primary:hover' => array('b', 'o'),
807
+				'.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b', 'o'),
808
+				'.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b', 'o'),
809
+				'.show>.btn-outline-primary.dropdown-toggle' => array('b', 'o'),
810 810
 				'.btn-link' => array('c'),
811 811
 				'.dropdown-item.active' => array('b'),
812
-				'.custom-control-input:checked~.custom-control-label::before' => array('b','o'),
813
-				'.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b','o'),
812
+				'.custom-control-input:checked~.custom-control-label::before' => array('b', 'o'),
813
+				'.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b', 'o'),
814 814
 //				'.custom-range::-webkit-slider-thumb' => array('b'), // these break the inline rules...
815 815
 //				'.custom-range::-moz-range-thumb' => array('b'),
816 816
 //				'.custom-range::-ms-thumb' => array('b'),
817 817
 				'.nav-pills .nav-link.active' => array('b'),
818 818
 				'.nav-pills .show>.nav-link' => array('b'),
819 819
 				'.page-link' => array('c'),
820
-				'.page-item.active .page-link' => array('b','o'),
820
+				'.page-item.active .page-link' => array('b', 'o'),
821 821
 				'.badge-primary' => array('b'),
822
-				'.alert-primary' => array('b','o'),
822
+				'.alert-primary' => array('b', 'o'),
823 823
 				'.progress-bar' => array('b'),
824
-				'.list-group-item.active' => array('b','o'),
825
-				'.bg-primary' => array('b','f'),
824
+				'.list-group-item.active' => array('b', 'o'),
825
+				'.bg-primary' => array('b', 'f'),
826 826
 				'.btn-link.btn-primary' => array('c'),
827 827
 				'.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array('b'),
828 828
 			);
829 829
 
830 830
 			$important_selectors = array(
831
-				'.bg-primary' => array('b','f'),
831
+				'.bg-primary' => array('b', 'f'),
832 832
 				'.border-primary' => array('o'),
833 833
 				'.text-primary' => array('c'),
834 834
 			);
@@ -845,116 +845,116 @@  discard block
 block discarded – undo
845 845
 			$output = '';
846 846
 
847 847
 			// build rules into each type
848
-			foreach($selectors as $selector => $types){
849
-				$selector = $compatibility ? ".bsui ".$selector : $selector;
850
-				$types = array_combine($types,$types);
851
-				if(isset($types['c'])){$color[] = $selector;}
852
-				if(isset($types['b'])){$background[] = $selector;}
853
-				if(isset($types['o'])){$border[] = $selector;}
854
-				if(isset($types['f'])){$fill[] = $selector;}
848
+			foreach ($selectors as $selector => $types) {
849
+				$selector = $compatibility ? ".bsui " . $selector : $selector;
850
+				$types = array_combine($types, $types);
851
+				if (isset($types['c'])) {$color[] = $selector; }
852
+				if (isset($types['b'])) {$background[] = $selector; }
853
+				if (isset($types['o'])) {$border[] = $selector; }
854
+				if (isset($types['f'])) {$fill[] = $selector; }
855 855
 			}
856 856
 
857 857
 			// build rules into each type
858
-			foreach($important_selectors as $selector => $types){
859
-				$selector = $compatibility ? ".bsui ".$selector : $selector;
860
-				$types = array_combine($types,$types);
861
-				if(isset($types['c'])){$color_i[] = $selector;}
862
-				if(isset($types['b'])){$background_i[] = $selector;}
863
-				if(isset($types['o'])){$border_i[] = $selector;}
864
-				if(isset($types['f'])){$fill_i[] = $selector;}
858
+			foreach ($important_selectors as $selector => $types) {
859
+				$selector = $compatibility ? ".bsui " . $selector : $selector;
860
+				$types = array_combine($types, $types);
861
+				if (isset($types['c'])) {$color_i[] = $selector; }
862
+				if (isset($types['b'])) {$background_i[] = $selector; }
863
+				if (isset($types['o'])) {$border_i[] = $selector; }
864
+				if (isset($types['f'])) {$fill_i[] = $selector; }
865 865
 			}
866 866
 
867 867
 			// add any color rules
868
-			if(!empty($color)){
869
-				$output .= implode(",",$color) . "{color: $color_code;} ";
868
+			if (!empty($color)) {
869
+				$output .= implode(",", $color) . "{color: $color_code;} ";
870 870
 			}
871
-			if(!empty($color_i)){
872
-				$output .= implode(",",$color_i) . "{color: $color_code !important;} ";
871
+			if (!empty($color_i)) {
872
+				$output .= implode(",", $color_i) . "{color: $color_code !important;} ";
873 873
 			}
874 874
 
875 875
 			// add any background color rules
876
-			if(!empty($background)){
877
-				$output .= implode(",",$background) . "{background-color: $color_code;} ";
876
+			if (!empty($background)) {
877
+				$output .= implode(",", $background) . "{background-color: $color_code;} ";
878 878
 			}
879
-			if(!empty($background_i)){
880
-				$output .= implode(",",$background_i) . "{background-color: $color_code !important;} ";
879
+			if (!empty($background_i)) {
880
+				$output .= implode(",", $background_i) . "{background-color: $color_code !important;} ";
881 881
 			}
882 882
 
883 883
 			// add any border color rules
884
-			if(!empty($border)){
885
-				$output .= implode(",",$border) . "{border-color: $color_code;} ";
884
+			if (!empty($border)) {
885
+				$output .= implode(",", $border) . "{border-color: $color_code;} ";
886 886
 			}
887
-			if(!empty($border_i)){
888
-				$output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
887
+			if (!empty($border_i)) {
888
+				$output .= implode(",", $border_i) . "{border-color: $color_code !important;} ";
889 889
 			}
890 890
 
891 891
 			// add any fill color rules
892
-			if(!empty($fill)){
893
-				$output .= implode(",",$fill) . "{fill: $color_code;} ";
892
+			if (!empty($fill)) {
893
+				$output .= implode(",", $fill) . "{fill: $color_code;} ";
894 894
 			}
895
-			if(!empty($fill_i)){
896
-				$output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
895
+			if (!empty($fill_i)) {
896
+				$output .= implode(",", $fill_i) . "{fill: $color_code !important;} ";
897 897
 			}
898 898
 
899 899
 
900 900
 			$prefix = $compatibility ? ".bsui " : "";
901 901
 
902 902
 			// darken
903
-			$darker_075 = self::css_hex_lighten_darken($color_code,"-0.075");
904
-			$darker_10 = self::css_hex_lighten_darken($color_code,"-0.10");
905
-			$darker_125 = self::css_hex_lighten_darken($color_code,"-0.125");
903
+			$darker_075 = self::css_hex_lighten_darken($color_code, "-0.075");
904
+			$darker_10 = self::css_hex_lighten_darken($color_code, "-0.10");
905
+			$darker_125 = self::css_hex_lighten_darken($color_code, "-0.125");
906 906
 
907 907
 			// lighten
908
-			$lighten_25 = self::css_hex_lighten_darken($color_code,"0.25");
908
+			$lighten_25 = self::css_hex_lighten_darken($color_code, "0.25");
909 909
 
910 910
 			// opacity see https://css-tricks.com/8-digit-hex-codes/
911
-			$op_25 = $color_code."40"; // 25% opacity
911
+			$op_25 = $color_code . "40"; // 25% opacity
912 912
 
913 913
 
914 914
 			// button states
915
-			$output .= $prefix ." .btn-primary:hover{background-color: ".$darker_075.";    border-color: ".$darker_10.";} ";
916
-			$output .= $prefix ." .btn-outline-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-primary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
917
-			$output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active, $prefix .btn-primary:not(:disabled):not(.disabled).active, .show>$prefix .btn-primary.dropdown-toggle{background-color: ".$darker_10.";    border-color: ".$darker_125.";} ";
918
-			$output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-primary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} ";
915
+			$output .= $prefix . " .btn-primary:hover{background-color: " . $darker_075 . ";    border-color: " . $darker_10 . ";} ";
916
+			$output .= $prefix . " .btn-outline-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-primary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
917
+			$output .= $prefix . " .btn-primary:not(:disabled):not(.disabled):active, $prefix .btn-primary:not(:disabled):not(.disabled).active, .show>$prefix .btn-primary.dropdown-toggle{background-color: " . $darker_10 . ";    border-color: " . $darker_125 . ";} ";
918
+			$output .= $prefix . " .btn-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-primary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} ";
919 919
 
920 920
 
921 921
 			// dropdown's
922
-			$output .= $prefix ." .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} ";
922
+			$output .= $prefix . " .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} ";
923 923
 
924 924
 
925 925
 			// input states
926
-			$output .= $prefix ." .form-control:focus{border-color: ".$lighten_25.";box-shadow: 0 0 0 0.2rem $op_25;} ";
926
+			$output .= $prefix . " .form-control:focus{border-color: " . $lighten_25 . ";box-shadow: 0 0 0 0.2rem $op_25;} ";
927 927
 
928 928
 			// page link
929
-			$output .= $prefix ." .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
929
+			$output .= $prefix . " .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
930 930
 
931 931
 			return $output;
932 932
 		}
933 933
 
934
-		public static function css_secondary($color_code,$compatibility){;
934
+		public static function css_secondary($color_code, $compatibility) {;
935 935
 			$color_code = sanitize_hex_color($color_code);
936
-			if(!$color_code){return '';}
936
+			if (!$color_code) {return ''; }
937 937
 			/**
938 938
 			 * c = color, b = background color, o = border-color, f = fill
939 939
 			 */
940 940
 			$selectors = array(
941
-				'.btn-secondary' => array('b','o'),
942
-				'.btn-secondary.disabled' => array('b','o'),
943
-				'.btn-secondary:disabled' => array('b','o'),
944
-				'.btn-outline-secondary' => array('c','o'),
945
-				'.btn-outline-secondary:hover' => array('b','o'),
941
+				'.btn-secondary' => array('b', 'o'),
942
+				'.btn-secondary.disabled' => array('b', 'o'),
943
+				'.btn-secondary:disabled' => array('b', 'o'),
944
+				'.btn-outline-secondary' => array('c', 'o'),
945
+				'.btn-outline-secondary:hover' => array('b', 'o'),
946 946
 				'.btn-outline-secondary.disabled' => array('c'),
947 947
 				'.btn-outline-secondary:disabled' => array('c'),
948
-				'.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b','o'),
949
-				'.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b','o'),
950
-				'.btn-outline-secondary.dropdown-toggle' => array('b','o'),
948
+				'.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b', 'o'),
949
+				'.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b', 'o'),
950
+				'.btn-outline-secondary.dropdown-toggle' => array('b', 'o'),
951 951
 				'.badge-secondary' => array('b'),
952
-				'.alert-secondary' => array('b','o'),
952
+				'.alert-secondary' => array('b', 'o'),
953 953
 				'.btn-link.btn-secondary' => array('c'),
954 954
 			);
955 955
 
956 956
 			$important_selectors = array(
957
-				'.bg-secondary' => array('b','f'),
957
+				'.bg-secondary' => array('b', 'f'),
958 958
 				'.border-secondary' => array('o'),
959 959
 				'.text-secondary' => array('c'),
960 960
 			);
@@ -971,77 +971,77 @@  discard block
 block discarded – undo
971 971
 			$output = '';
972 972
 
973 973
 			// build rules into each type
974
-			foreach($selectors as $selector => $types){
975
-				$selector = $compatibility ? ".bsui ".$selector : $selector;
976
-				$types = array_combine($types,$types);
977
-				if(isset($types['c'])){$color[] = $selector;}
978
-				if(isset($types['b'])){$background[] = $selector;}
979
-				if(isset($types['o'])){$border[] = $selector;}
980
-				if(isset($types['f'])){$fill[] = $selector;}
974
+			foreach ($selectors as $selector => $types) {
975
+				$selector = $compatibility ? ".bsui " . $selector : $selector;
976
+				$types = array_combine($types, $types);
977
+				if (isset($types['c'])) {$color[] = $selector; }
978
+				if (isset($types['b'])) {$background[] = $selector; }
979
+				if (isset($types['o'])) {$border[] = $selector; }
980
+				if (isset($types['f'])) {$fill[] = $selector; }
981 981
 			}
982 982
 
983 983
 			// build rules into each type
984
-			foreach($important_selectors as $selector => $types){
985
-				$selector = $compatibility ? ".bsui ".$selector : $selector;
986
-				$types = array_combine($types,$types);
987
-				if(isset($types['c'])){$color_i[] = $selector;}
988
-				if(isset($types['b'])){$background_i[] = $selector;}
989
-				if(isset($types['o'])){$border_i[] = $selector;}
990
-				if(isset($types['f'])){$fill_i[] = $selector;}
984
+			foreach ($important_selectors as $selector => $types) {
985
+				$selector = $compatibility ? ".bsui " . $selector : $selector;
986
+				$types = array_combine($types, $types);
987
+				if (isset($types['c'])) {$color_i[] = $selector; }
988
+				if (isset($types['b'])) {$background_i[] = $selector; }
989
+				if (isset($types['o'])) {$border_i[] = $selector; }
990
+				if (isset($types['f'])) {$fill_i[] = $selector; }
991 991
 			}
992 992
 
993 993
 			// add any color rules
994
-			if(!empty($color)){
995
-				$output .= implode(",",$color) . "{color: $color_code;} ";
994
+			if (!empty($color)) {
995
+				$output .= implode(",", $color) . "{color: $color_code;} ";
996 996
 			}
997
-			if(!empty($color_i)){
998
-				$output .= implode(",",$color_i) . "{color: $color_code !important;} ";
997
+			if (!empty($color_i)) {
998
+				$output .= implode(",", $color_i) . "{color: $color_code !important;} ";
999 999
 			}
1000 1000
 
1001 1001
 			// add any background color rules
1002
-			if(!empty($background)){
1003
-				$output .= implode(",",$background) . "{background-color: $color_code;} ";
1002
+			if (!empty($background)) {
1003
+				$output .= implode(",", $background) . "{background-color: $color_code;} ";
1004 1004
 			}
1005
-			if(!empty($background_i)){
1006
-				$output .= implode(",",$background_i) . "{background-color: $color_code !important;} ";
1005
+			if (!empty($background_i)) {
1006
+				$output .= implode(",", $background_i) . "{background-color: $color_code !important;} ";
1007 1007
 			}
1008 1008
 
1009 1009
 			// add any border color rules
1010
-			if(!empty($border)){
1011
-				$output .= implode(",",$border) . "{border-color: $color_code;} ";
1010
+			if (!empty($border)) {
1011
+				$output .= implode(",", $border) . "{border-color: $color_code;} ";
1012 1012
 			}
1013
-			if(!empty($border_i)){
1014
-				$output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
1013
+			if (!empty($border_i)) {
1014
+				$output .= implode(",", $border_i) . "{border-color: $color_code !important;} ";
1015 1015
 			}
1016 1016
 
1017 1017
 			// add any fill color rules
1018
-			if(!empty($fill)){
1019
-				$output .= implode(",",$fill) . "{fill: $color_code;} ";
1018
+			if (!empty($fill)) {
1019
+				$output .= implode(",", $fill) . "{fill: $color_code;} ";
1020 1020
 			}
1021
-			if(!empty($fill_i)){
1022
-				$output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
1021
+			if (!empty($fill_i)) {
1022
+				$output .= implode(",", $fill_i) . "{fill: $color_code !important;} ";
1023 1023
 			}
1024 1024
 
1025 1025
 
1026 1026
 			$prefix = $compatibility ? ".bsui " : "";
1027 1027
 
1028 1028
 			// darken
1029
-			$darker_075 = self::css_hex_lighten_darken($color_code,"-0.075");
1030
-			$darker_10 = self::css_hex_lighten_darken($color_code,"-0.10");
1031
-			$darker_125 = self::css_hex_lighten_darken($color_code,"-0.125");
1029
+			$darker_075 = self::css_hex_lighten_darken($color_code, "-0.075");
1030
+			$darker_10 = self::css_hex_lighten_darken($color_code, "-0.10");
1031
+			$darker_125 = self::css_hex_lighten_darken($color_code, "-0.125");
1032 1032
 
1033 1033
 			// lighten
1034
-			$lighten_25 = self::css_hex_lighten_darken($color_code,"0.25");
1034
+			$lighten_25 = self::css_hex_lighten_darken($color_code, "0.25");
1035 1035
 
1036 1036
 			// opacity see https://css-tricks.com/8-digit-hex-codes/
1037
-			$op_25 = $color_code."40"; // 25% opacity
1037
+			$op_25 = $color_code . "40"; // 25% opacity
1038 1038
 
1039 1039
 
1040 1040
 			// button states
1041
-			$output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075.";    border-color: ".$darker_10.";} ";
1042
-			$output .= $prefix ." .btn-outline-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-secondary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1043
-			$output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active, $prefix .btn-secondary:not(:disabled):not(.disabled).active, .show>$prefix .btn-secondary.dropdown-toggle{background-color: ".$darker_10.";    border-color: ".$darker_125.";} ";
1044
-			$output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-secondary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} ";
1041
+			$output .= $prefix . " .btn-secondary:hover{background-color: " . $darker_075 . ";    border-color: " . $darker_10 . ";} ";
1042
+			$output .= $prefix . " .btn-outline-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-secondary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1043
+			$output .= $prefix . " .btn-secondary:not(:disabled):not(.disabled):active, $prefix .btn-secondary:not(:disabled):not(.disabled).active, .show>$prefix .btn-secondary.dropdown-toggle{background-color: " . $darker_10 . ";    border-color: " . $darker_125 . ";} ";
1044
+			$output .= $prefix . " .btn-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-secondary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} ";
1045 1045
 
1046 1046
 
1047 1047
 			return $output;
@@ -1077,8 +1077,8 @@  discard block
 block discarded – undo
1077 1077
 		/**
1078 1078
 		 * Check if we should display examples.
1079 1079
 		 */
1080
-		public function maybe_show_examples(){
1081
-			if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){
1080
+		public function maybe_show_examples() {
1081
+			if (current_user_can('manage_options') && isset($_REQUEST['preview-aui'])) {
1082 1082
 				echo "<head>";
1083 1083
 				wp_head();
1084 1084
 				echo "</head>";
@@ -1094,7 +1094,7 @@  discard block
 block discarded – undo
1094 1094
 		 *
1095 1095
 		 * @return string
1096 1096
 		 */
1097
-		public function get_examples(){
1097
+		public function get_examples() {
1098 1098
 			$output = '';
1099 1099
 
1100 1100
 
Please login to merge, or discard this patch.
vendor/ayecode/wp-ayecode-ui/includes/class-aui.php 2 patches
Indentation   +202 added lines, -202 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if ( ! defined( 'ABSPATH' ) ) {
4
-	exit; // Exit if accessed directly
4
+    exit; // Exit if accessed directly
5 5
 }
6 6
 
7 7
 /**
@@ -11,206 +11,206 @@  discard block
 block discarded – undo
11 11
  */
12 12
 class AUI {
13 13
 
14
-	/**
15
-	 * Holds the class instance.
16
-	 *
17
-	 * @since 1.0.0
18
-	 * @var null
19
-	 */
20
-	private static $instance = null;
21
-
22
-	/**
23
-	 * Holds the current AUI version number.
24
-	 *
25
-	 * @var string $ver The current version number.
26
-	 */
27
-	public static $ver = '0.1.18';
28
-
29
-	/**
30
-	 * There can be only one.
31
-	 *
32
-	 * @since 1.0.0
33
-	 * @return AUI|null
34
-	 */
35
-	public static function instance() {
36
-		if ( self::$instance == null ) {
37
-			self::$instance = new AUI();
38
-		}
39
-
40
-		return self::$instance;
41
-	}
42
-
43
-	/**
44
-	 * AUI constructor.
45
-	 *
46
-	 * @since 1.0.0
47
-	 */
48
-	private function __construct() {
49
-		if ( function_exists( "__autoload" ) ) {
50
-			spl_autoload_register( "__autoload" );
51
-		}
52
-		spl_autoload_register( array( $this, 'autoload' ) );
53
-	}
54
-
55
-	/**
56
-	 * Autoload any components on the fly.
57
-	 *
58
-	 * @since 1.0.0
59
-	 *
60
-	 * @param $classname
61
-	 */
62
-	private function autoload( $classname ) {
63
-		$class     = str_replace( '_', '-', strtolower( $classname ) );
64
-		$file_path = trailingslashit( dirname( __FILE__ ) ) . "components/class-" . $class . '.php';
65
-		if ( $file_path && is_readable( $file_path ) ) {
66
-			include_once( $file_path );
67
-		}
68
-	}
69
-
70
-	public function render( $items = array() ) {
71
-		$output = '';
72
-
73
-		if ( ! empty( $items ) ) {
74
-			foreach ( $items as $args ) {
75
-				$render = isset( $args['render'] ) ? $args['render'] : '';
76
-				if ( $render && method_exists( __CLASS__, $render ) ) {
77
-					$output .= $this->$render( $args );
78
-				}
79
-			}
80
-		}
81
-
82
-		return $output;
83
-	}
84
-
85
-	/**
86
-	 * Render and return a bootstrap alert component.
87
-	 *
88
-	 * @since 1.0.0
89
-	 *
90
-	 * @param array $args
91
-	 *
92
-	 * @return string The rendered component.
93
-	 */
94
-	public function alert( $args = array() ) {
95
-		return AUI_Component_Alert::get( $args );
96
-	}
97
-
98
-	/**
99
-	 * Render and return a bootstrap input component.
100
-	 *
101
-	 * @since 1.0.0
102
-	 *
103
-	 * @param array $args
104
-	 *
105
-	 * @return string The rendered component.
106
-	 */
107
-	public function input( $args = array() ) {
108
-		return AUI_Component_Input::input( $args );
109
-	}
110
-
111
-	/**
112
-	 * Render and return a bootstrap textarea component.
113
-	 *
114
-	 * @since 1.0.0
115
-	 *
116
-	 * @param array $args
117
-	 *
118
-	 * @return string The rendered component.
119
-	 */
120
-	public function textarea( $args = array() ) {
121
-		return AUI_Component_Input::textarea( $args );
122
-	}
123
-
124
-	/**
125
-	 * Render and return a bootstrap button component.
126
-	 *
127
-	 * @since 1.0.0
128
-	 *
129
-	 * @param array $args
130
-	 *
131
-	 * @return string The rendered component.
132
-	 */
133
-	public function button( $args = array() ) {
134
-		return AUI_Component_Button::get( $args );
135
-	}
136
-
137
-	/**
138
-	 * Render and return a bootstrap button component.
139
-	 *
140
-	 * @since 1.0.0
141
-	 *
142
-	 * @param array $args
143
-	 *
144
-	 * @return string The rendered component.
145
-	 */
146
-	public function badge( $args = array() ) {
147
-		$defaults = array(
148
-			'class' => 'badge badge-primary align-middle',
149
-		);
150
-
151
-		// maybe set type
152
-		if ( empty( $args['href'] ) ) {
153
-			$defaults['type'] = 'badge';
154
-		}
155
-
156
-		/**
157
-		 * Parse incoming $args into an array and merge it with $defaults
158
-		 */
159
-		$args = wp_parse_args( $args, $defaults );
160
-
161
-		return AUI_Component_Button::get( $args );
162
-	}
163
-
164
-	/**
165
-	 * Render and return a bootstrap dropdown component.
166
-	 *
167
-	 * @since 1.0.0
168
-	 *
169
-	 * @param array $args
170
-	 *
171
-	 * @return string The rendered component.
172
-	 */
173
-	public function dropdown( $args = array() ) {
174
-		return AUI_Component_Dropdown::get( $args );
175
-	}
176
-
177
-	/**
178
-	 * Render and return a bootstrap select component.
179
-	 *
180
-	 * @since 1.0.0
181
-	 *
182
-	 * @param array $args
183
-	 *
184
-	 * @return string The rendered component.
185
-	 */
186
-	public function select( $args = array() ) {
187
-		return AUI_Component_Input::select( $args );
188
-	}
189
-
190
-	/**
191
-	 * Render and return a bootstrap radio component.
192
-	 *
193
-	 * @since 1.0.0
194
-	 *
195
-	 * @param array $args
196
-	 *
197
-	 * @return string The rendered component.
198
-	 */
199
-	public function radio( $args = array() ) {
200
-		return AUI_Component_Input::radio( $args );
201
-	}
202
-
203
-	/**
204
-	 * Render and return a bootstrap pagination component.
205
-	 *
206
-	 * @since 1.0.0
207
-	 *
208
-	 * @param array $args
209
-	 *
210
-	 * @return string The rendered component.
211
-	 */
212
-	public function pagination( $args = array() ) {
213
-		return AUI_Component_Pagination::get( $args );
214
-	}
14
+    /**
15
+     * Holds the class instance.
16
+     *
17
+     * @since 1.0.0
18
+     * @var null
19
+     */
20
+    private static $instance = null;
21
+
22
+    /**
23
+     * Holds the current AUI version number.
24
+     *
25
+     * @var string $ver The current version number.
26
+     */
27
+    public static $ver = '0.1.18';
28
+
29
+    /**
30
+     * There can be only one.
31
+     *
32
+     * @since 1.0.0
33
+     * @return AUI|null
34
+     */
35
+    public static function instance() {
36
+        if ( self::$instance == null ) {
37
+            self::$instance = new AUI();
38
+        }
39
+
40
+        return self::$instance;
41
+    }
42
+
43
+    /**
44
+     * AUI constructor.
45
+     *
46
+     * @since 1.0.0
47
+     */
48
+    private function __construct() {
49
+        if ( function_exists( "__autoload" ) ) {
50
+            spl_autoload_register( "__autoload" );
51
+        }
52
+        spl_autoload_register( array( $this, 'autoload' ) );
53
+    }
54
+
55
+    /**
56
+     * Autoload any components on the fly.
57
+     *
58
+     * @since 1.0.0
59
+     *
60
+     * @param $classname
61
+     */
62
+    private function autoload( $classname ) {
63
+        $class     = str_replace( '_', '-', strtolower( $classname ) );
64
+        $file_path = trailingslashit( dirname( __FILE__ ) ) . "components/class-" . $class . '.php';
65
+        if ( $file_path && is_readable( $file_path ) ) {
66
+            include_once( $file_path );
67
+        }
68
+    }
69
+
70
+    public function render( $items = array() ) {
71
+        $output = '';
72
+
73
+        if ( ! empty( $items ) ) {
74
+            foreach ( $items as $args ) {
75
+                $render = isset( $args['render'] ) ? $args['render'] : '';
76
+                if ( $render && method_exists( __CLASS__, $render ) ) {
77
+                    $output .= $this->$render( $args );
78
+                }
79
+            }
80
+        }
81
+
82
+        return $output;
83
+    }
84
+
85
+    /**
86
+     * Render and return a bootstrap alert component.
87
+     *
88
+     * @since 1.0.0
89
+     *
90
+     * @param array $args
91
+     *
92
+     * @return string The rendered component.
93
+     */
94
+    public function alert( $args = array() ) {
95
+        return AUI_Component_Alert::get( $args );
96
+    }
97
+
98
+    /**
99
+     * Render and return a bootstrap input component.
100
+     *
101
+     * @since 1.0.0
102
+     *
103
+     * @param array $args
104
+     *
105
+     * @return string The rendered component.
106
+     */
107
+    public function input( $args = array() ) {
108
+        return AUI_Component_Input::input( $args );
109
+    }
110
+
111
+    /**
112
+     * Render and return a bootstrap textarea component.
113
+     *
114
+     * @since 1.0.0
115
+     *
116
+     * @param array $args
117
+     *
118
+     * @return string The rendered component.
119
+     */
120
+    public function textarea( $args = array() ) {
121
+        return AUI_Component_Input::textarea( $args );
122
+    }
123
+
124
+    /**
125
+     * Render and return a bootstrap button component.
126
+     *
127
+     * @since 1.0.0
128
+     *
129
+     * @param array $args
130
+     *
131
+     * @return string The rendered component.
132
+     */
133
+    public function button( $args = array() ) {
134
+        return AUI_Component_Button::get( $args );
135
+    }
136
+
137
+    /**
138
+     * Render and return a bootstrap button component.
139
+     *
140
+     * @since 1.0.0
141
+     *
142
+     * @param array $args
143
+     *
144
+     * @return string The rendered component.
145
+     */
146
+    public function badge( $args = array() ) {
147
+        $defaults = array(
148
+            'class' => 'badge badge-primary align-middle',
149
+        );
150
+
151
+        // maybe set type
152
+        if ( empty( $args['href'] ) ) {
153
+            $defaults['type'] = 'badge';
154
+        }
155
+
156
+        /**
157
+         * Parse incoming $args into an array and merge it with $defaults
158
+         */
159
+        $args = wp_parse_args( $args, $defaults );
160
+
161
+        return AUI_Component_Button::get( $args );
162
+    }
163
+
164
+    /**
165
+     * Render and return a bootstrap dropdown component.
166
+     *
167
+     * @since 1.0.0
168
+     *
169
+     * @param array $args
170
+     *
171
+     * @return string The rendered component.
172
+     */
173
+    public function dropdown( $args = array() ) {
174
+        return AUI_Component_Dropdown::get( $args );
175
+    }
176
+
177
+    /**
178
+     * Render and return a bootstrap select component.
179
+     *
180
+     * @since 1.0.0
181
+     *
182
+     * @param array $args
183
+     *
184
+     * @return string The rendered component.
185
+     */
186
+    public function select( $args = array() ) {
187
+        return AUI_Component_Input::select( $args );
188
+    }
189
+
190
+    /**
191
+     * Render and return a bootstrap radio component.
192
+     *
193
+     * @since 1.0.0
194
+     *
195
+     * @param array $args
196
+     *
197
+     * @return string The rendered component.
198
+     */
199
+    public function radio( $args = array() ) {
200
+        return AUI_Component_Input::radio( $args );
201
+    }
202
+
203
+    /**
204
+     * Render and return a bootstrap pagination component.
205
+     *
206
+     * @since 1.0.0
207
+     *
208
+     * @param array $args
209
+     *
210
+     * @return string The rendered component.
211
+     */
212
+    public function pagination( $args = array() ) {
213
+        return AUI_Component_Pagination::get( $args );
214
+    }
215 215
 
216 216
 }
217 217
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'ABSPATH' ) ) {
3
+if (!defined('ABSPATH')) {
4 4
 	exit; // Exit if accessed directly
5 5
 }
6 6
 
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 	 * @return AUI|null
34 34
 	 */
35 35
 	public static function instance() {
36
-		if ( self::$instance == null ) {
36
+		if (self::$instance == null) {
37 37
 			self::$instance = new AUI();
38 38
 		}
39 39
 
@@ -46,10 +46,10 @@  discard block
 block discarded – undo
46 46
 	 * @since 1.0.0
47 47
 	 */
48 48
 	private function __construct() {
49
-		if ( function_exists( "__autoload" ) ) {
50
-			spl_autoload_register( "__autoload" );
49
+		if (function_exists("__autoload")) {
50
+			spl_autoload_register("__autoload");
51 51
 		}
52
-		spl_autoload_register( array( $this, 'autoload' ) );
52
+		spl_autoload_register(array($this, 'autoload'));
53 53
 	}
54 54
 
55 55
 	/**
@@ -59,22 +59,22 @@  discard block
 block discarded – undo
59 59
 	 *
60 60
 	 * @param $classname
61 61
 	 */
62
-	private function autoload( $classname ) {
63
-		$class     = str_replace( '_', '-', strtolower( $classname ) );
64
-		$file_path = trailingslashit( dirname( __FILE__ ) ) . "components/class-" . $class . '.php';
65
-		if ( $file_path && is_readable( $file_path ) ) {
66
-			include_once( $file_path );
62
+	private function autoload($classname) {
63
+		$class     = str_replace('_', '-', strtolower($classname));
64
+		$file_path = trailingslashit(dirname(__FILE__)) . "components/class-" . $class . '.php';
65
+		if ($file_path && is_readable($file_path)) {
66
+			include_once($file_path);
67 67
 		}
68 68
 	}
69 69
 
70
-	public function render( $items = array() ) {
70
+	public function render($items = array()) {
71 71
 		$output = '';
72 72
 
73
-		if ( ! empty( $items ) ) {
74
-			foreach ( $items as $args ) {
75
-				$render = isset( $args['render'] ) ? $args['render'] : '';
76
-				if ( $render && method_exists( __CLASS__, $render ) ) {
77
-					$output .= $this->$render( $args );
73
+		if (!empty($items)) {
74
+			foreach ($items as $args) {
75
+				$render = isset($args['render']) ? $args['render'] : '';
76
+				if ($render && method_exists(__CLASS__, $render)) {
77
+					$output .= $this->$render($args);
78 78
 				}
79 79
 			}
80 80
 		}
@@ -91,8 +91,8 @@  discard block
 block discarded – undo
91 91
 	 *
92 92
 	 * @return string The rendered component.
93 93
 	 */
94
-	public function alert( $args = array() ) {
95
-		return AUI_Component_Alert::get( $args );
94
+	public function alert($args = array()) {
95
+		return AUI_Component_Alert::get($args);
96 96
 	}
97 97
 
98 98
 	/**
@@ -104,8 +104,8 @@  discard block
 block discarded – undo
104 104
 	 *
105 105
 	 * @return string The rendered component.
106 106
 	 */
107
-	public function input( $args = array() ) {
108
-		return AUI_Component_Input::input( $args );
107
+	public function input($args = array()) {
108
+		return AUI_Component_Input::input($args);
109 109
 	}
110 110
 
111 111
 	/**
@@ -117,8 +117,8 @@  discard block
 block discarded – undo
117 117
 	 *
118 118
 	 * @return string The rendered component.
119 119
 	 */
120
-	public function textarea( $args = array() ) {
121
-		return AUI_Component_Input::textarea( $args );
120
+	public function textarea($args = array()) {
121
+		return AUI_Component_Input::textarea($args);
122 122
 	}
123 123
 
124 124
 	/**
@@ -130,8 +130,8 @@  discard block
 block discarded – undo
130 130
 	 *
131 131
 	 * @return string The rendered component.
132 132
 	 */
133
-	public function button( $args = array() ) {
134
-		return AUI_Component_Button::get( $args );
133
+	public function button($args = array()) {
134
+		return AUI_Component_Button::get($args);
135 135
 	}
136 136
 
137 137
 	/**
@@ -143,22 +143,22 @@  discard block
 block discarded – undo
143 143
 	 *
144 144
 	 * @return string The rendered component.
145 145
 	 */
146
-	public function badge( $args = array() ) {
146
+	public function badge($args = array()) {
147 147
 		$defaults = array(
148 148
 			'class' => 'badge badge-primary align-middle',
149 149
 		);
150 150
 
151 151
 		// maybe set type
152
-		if ( empty( $args['href'] ) ) {
152
+		if (empty($args['href'])) {
153 153
 			$defaults['type'] = 'badge';
154 154
 		}
155 155
 
156 156
 		/**
157 157
 		 * Parse incoming $args into an array and merge it with $defaults
158 158
 		 */
159
-		$args = wp_parse_args( $args, $defaults );
159
+		$args = wp_parse_args($args, $defaults);
160 160
 
161
-		return AUI_Component_Button::get( $args );
161
+		return AUI_Component_Button::get($args);
162 162
 	}
163 163
 
164 164
 	/**
@@ -170,8 +170,8 @@  discard block
 block discarded – undo
170 170
 	 *
171 171
 	 * @return string The rendered component.
172 172
 	 */
173
-	public function dropdown( $args = array() ) {
174
-		return AUI_Component_Dropdown::get( $args );
173
+	public function dropdown($args = array()) {
174
+		return AUI_Component_Dropdown::get($args);
175 175
 	}
176 176
 
177 177
 	/**
@@ -183,8 +183,8 @@  discard block
 block discarded – undo
183 183
 	 *
184 184
 	 * @return string The rendered component.
185 185
 	 */
186
-	public function select( $args = array() ) {
187
-		return AUI_Component_Input::select( $args );
186
+	public function select($args = array()) {
187
+		return AUI_Component_Input::select($args);
188 188
 	}
189 189
 
190 190
 	/**
@@ -196,8 +196,8 @@  discard block
 block discarded – undo
196 196
 	 *
197 197
 	 * @return string The rendered component.
198 198
 	 */
199
-	public function radio( $args = array() ) {
200
-		return AUI_Component_Input::radio( $args );
199
+	public function radio($args = array()) {
200
+		return AUI_Component_Input::radio($args);
201 201
 	}
202 202
 
203 203
 	/**
@@ -209,8 +209,8 @@  discard block
 block discarded – undo
209 209
 	 *
210 210
 	 * @return string The rendered component.
211 211
 	 */
212
-	public function pagination( $args = array() ) {
213
-		return AUI_Component_Pagination::get( $args );
212
+	public function pagination($args = array()) {
213
+		return AUI_Component_Pagination::get($args);
214 214
 	}
215 215
 
216 216
 }
217 217
\ No newline at end of file
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-mb-invoice-items.php 2 patches
Indentation   +5 added lines, -5 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 WPInv_Meta_Box_Items {
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
         global $wpinv_euvat, $ajax_cart_details;
26 26
 
Please login to merge, or discard this patch.
Spacing   +185 added lines, -185 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,43 +21,43 @@  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
         global $wpinv_euvat, $ajax_cart_details;
26 26
 
27
-        $post_id            = !empty( $post->ID ) ? $post->ID : 0;
28
-        $invoice            = new WPInv_Invoice( $post_id );
27
+        $post_id            = !empty($post->ID) ? $post->ID : 0;
28
+        $invoice            = new WPInv_Invoice($post_id);
29 29
         $ajax_cart_details  = $invoice->get_cart_details();
30
-        $subtotal           = $invoice->get_subtotal( true );
30
+        $subtotal           = $invoice->get_subtotal(true);
31 31
         $discount_raw       = $invoice->get_discount();
32
-        $discount           = wpinv_price( $discount_raw, $invoice->get_currency() );
32
+        $discount           = wpinv_price($discount_raw, $invoice->get_currency());
33 33
         $discounts          = $discount_raw > 0 ? $invoice->get_discounts() : '';
34
-        $tax                = $invoice->get_tax( true );
35
-        $total              = $invoice->get_total( true );
34
+        $tax                = $invoice->get_tax(true);
35
+        $total              = $invoice->get_total(true);
36 36
         $item_quantities    = wpinv_item_quantities_enabled();
37 37
         $use_taxes          = wpinv_use_taxes();
38
-        if ( !$use_taxes && (float)$invoice->get_tax() > 0 ) {
38
+        if (!$use_taxes && (float) $invoice->get_tax() > 0) {
39 39
             $use_taxes = true;
40 40
         }
41
-        $item_types         = apply_filters( 'wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post );
41
+        $item_types         = apply_filters('wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post);
42 42
         $is_recurring       = $invoice->is_recurring();
43 43
         $post_type_object   = get_post_type_object($invoice->post_type);
44 44
         $type_title         = $post_type_object->labels->singular_name;
45 45
 
46 46
         $cols = 5;
47
-        if ( $item_quantities ) {
47
+        if ($item_quantities) {
48 48
             $cols++;
49 49
         }
50
-        if ( $use_taxes ) {
50
+        if ($use_taxes) {
51 51
             $cols++;
52 52
         }
53 53
         $class = '';
54
-        if ( $invoice->is_paid() ) {
54
+        if ($invoice->is_paid()) {
55 55
             $class .= ' wpinv-paid';
56 56
         }
57
-        if ( $invoice->is_refunded() ) {
57
+        if ($invoice->is_refunded()) {
58 58
             $class .= ' wpinv-refunded';
59 59
         }
60
-        if ( $is_recurring ) {
60
+        if ($is_recurring) {
61 61
             $class .= ' wpi-recurring';
62 62
         }
63 63
         ?>
@@ -65,21 +65,21 @@  discard block
 block discarded – undo
65 65
             <table id="wpinv_items" class="wpinv-items" cellspacing="0" cellpadding="0">
66 66
                 <thead>
67 67
                     <tr>
68
-                        <th class="id"><?php _e( 'ID', 'invoicing' );?></th>
69
-                        <th class="title"><?php _e( 'Item', 'invoicing' );?></th>
70
-                        <th class="price"><?php _e( 'Price', 'invoicing' );?></th>
71
-                        <?php if ( $item_quantities ) { ?>
72
-                        <th class="qty"><?php _e( 'Qty', 'invoicing' );?></th>
68
+                        <th class="id"><?php _e('ID', 'invoicing'); ?></th>
69
+                        <th class="title"><?php _e('Item', 'invoicing'); ?></th>
70
+                        <th class="price"><?php _e('Price', 'invoicing'); ?></th>
71
+                        <?php if ($item_quantities) { ?>
72
+                        <th class="qty"><?php _e('Qty', 'invoicing'); ?></th>
73 73
                         <?php } ?>
74
-                        <th class="total"><?php _e( 'Total', 'invoicing' );?></th>
75
-                        <?php if ( $use_taxes ) { ?>
76
-                        <th class="tax"><?php _e( 'Tax (%)', 'invoicing' );?></th>
74
+                        <th class="total"><?php _e('Total', 'invoicing'); ?></th>
75
+                        <?php if ($use_taxes) { ?>
76
+                        <th class="tax"><?php _e('Tax (%)', 'invoicing'); ?></th>
77 77
                         <?php } ?>
78 78
                         <th class="action"></th>
79 79
                     </tr>
80 80
                 </thead>
81 81
                 <tbody class="wpinv-line-items">
82
-                    <?php echo wpinv_admin_get_line_items( $invoice ); ?>
82
+                    <?php echo wpinv_admin_get_line_items($invoice); ?>
83 83
                 </tbody>
84 84
                 <tfoot class="wpinv-totals">
85 85
                     <tr>
@@ -90,45 +90,45 @@  discard block
 block discarded – undo
90 90
                                         <td class="id">
91 91
                                         </td>
92 92
                                         <td class="title">
93
-                                            <input type="text" class="regular-text" placeholder="<?php _e( 'Item Name', 'invoicing' ); ?>" value="" name="_wpinv_quick[name]">
94
-                                            <?php if ( $wpinv_euvat->allow_vat_rules() ) { ?>
93
+                                            <input type="text" class="regular-text" placeholder="<?php _e('Item Name', 'invoicing'); ?>" value="" name="_wpinv_quick[name]">
94
+                                            <?php if ($wpinv_euvat->allow_vat_rules()) { ?>
95 95
                                             <div class="wp-clearfix">
96 96
                                                 <label class="wpi-vat-rule">
97
-                                                    <span class="title"><?php _e( 'VAT rule type', 'invoicing' );?></span>
97
+                                                    <span class="title"><?php _e('VAT rule type', 'invoicing'); ?></span>
98 98
                                                     <span class="input-text-wrap">
99
-                                                        <?php echo wpinv_html_select( array(
99
+                                                        <?php echo wpinv_html_select(array(
100 100
                                                             'options'          => $wpinv_euvat->get_rules(),
101 101
                                                             'name'             => '_wpinv_quick[vat_rule]',
102 102
                                                             'id'               => '_wpinv_quick_vat_rule',
103 103
                                                             'show_option_all'  => false,
104 104
                                                             'show_option_none' => false,
105 105
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-vat-rule wpi_select2',
106
-                                                        ) ); ?>
106
+                                                        )); ?>
107 107
                                                     </span>
108 108
                                                 </label>
109 109
                                             </div>
110
-                                            <?php } if ( $wpinv_euvat->allow_vat_classes() ) { ?>
110
+                                            <?php } if ($wpinv_euvat->allow_vat_classes()) { ?>
111 111
                                             <div class="wp-clearfix">
112 112
                                                 <label class="wpi-vat-class">
113
-                                                    <span class="title"><?php _e( 'VAT class', 'invoicing' );?></span>
113
+                                                    <span class="title"><?php _e('VAT class', 'invoicing'); ?></span>
114 114
                                                     <span class="input-text-wrap">
115
-                                                        <?php echo wpinv_html_select( array(
115
+                                                        <?php echo wpinv_html_select(array(
116 116
                                                             'options'          => $wpinv_euvat->get_all_classes(),
117 117
                                                             'name'             => '_wpinv_quick[vat_class]',
118 118
                                                             'id'               => '_wpinv_quick_vat_class',
119 119
                                                             'show_option_all'  => false,
120 120
                                                             'show_option_none' => false,
121 121
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-vat-class wpi_select2',
122
-                                                        ) ); ?>
122
+                                                        )); ?>
123 123
                                                     </span>
124 124
                                                 </label>
125 125
                                             </div>
126 126
                                             <?php } ?>
127 127
                                             <div class="wp-clearfix">
128 128
                                                 <label class="wpi-item-type">
129
-                                                    <span class="title"><?php _e( 'Item type', 'invoicing' );?></span>
129
+                                                    <span class="title"><?php _e('Item type', 'invoicing'); ?></span>
130 130
                                                     <span class="input-text-wrap">
131
-                                                        <?php echo wpinv_html_select( array(
131
+                                                        <?php echo wpinv_html_select(array(
132 132
                                                             'options'          => $item_types,
133 133
                                                             'name'             => '_wpinv_quick[type]',
134 134
                                                             'id'               => '_wpinv_quick_type',
@@ -136,37 +136,37 @@  discard block
 block discarded – undo
136 136
                                                             'show_option_all'  => false,
137 137
                                                             'show_option_none' => false,
138 138
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-type wpi_select2',
139
-                                                        ) ); ?>
139
+                                                        )); ?>
140 140
                                                     </span>
141 141
                                                 </label>
142 142
                                             </div>
143 143
 
144 144
                                             <div class="wp-clearfix">
145 145
                                                 <?php 
146
-                                                    echo wpinv_html_textarea( array(
146
+                                                    echo wpinv_html_textarea(array(
147 147
                                                         'name'  => '_wpinv_quick[excerpt]',
148 148
                                                         'id'    => '_wpinv_quick_excerpt',
149 149
                                                         'value' => '',
150 150
                                                         'class' => 'large-text',
151
-                                                        'label' => __( 'Item description', 'invoicing' ),
152
-                                                    ) ); 
151
+                                                        'label' => __('Item description', 'invoicing'),
152
+                                                    )); 
153 153
                                                 ?>
154 154
                                             </div>
155 155
 
156 156
                                             <div class="wp-clearfix">
157 157
                                                 <label class="wpi-item-actions">
158 158
                                                     <span class="input-text-wrap">
159
-                                                        <input type="button" value="<?php esc_attr_e( 'Add', 'invoicing' ); ?>" class="button button-primary" id="wpinv-save-item"><input type="button" value="Cancel" class="button button-secondary" id="wpinv-cancel-item">
159
+                                                        <input type="button" value="<?php esc_attr_e('Add', 'invoicing'); ?>" class="button button-primary" id="wpinv-save-item"><input type="button" value="Cancel" class="button button-secondary" id="wpinv-cancel-item">
160 160
                                                     </span>
161 161
                                                 </label>
162 162
                                             </div>
163 163
                                         </td>
164 164
                                         <td class="price"><input type="text" placeholder="0.00" class="wpi-field-price wpi-price" name="_wpinv_quick[price]" /></td>
165
-                                        <?php if ( $item_quantities ) { ?>
165
+                                        <?php if ($item_quantities) { ?>
166 166
                                         <td class="qty"><input type="number" class="small-text" step="1" min="1" value="1" name="_wpinv_quick[qty]" /></td>
167 167
                                         <?php } ?>
168 168
                                         <td class="total"></td>
169
-                                        <?php if ( $use_taxes ) { ?>
169
+                                        <?php if ($use_taxes) { ?>
170 170
                                         <td class="tax"></td>
171 171
                                         <?php } ?>
172 172
                                         <td class="action"></td>
@@ -179,29 +179,29 @@  discard block
 block discarded – undo
179 179
                         <td colspan="<?php echo $cols; ?>"></td>
180 180
                     </tr>
181 181
                     <tr class="totals">
182
-                        <td colspan="<?php echo ( $cols - 4 ); ?>"></td>
182
+                        <td colspan="<?php echo ($cols - 4); ?>"></td>
183 183
                         <td colspan="4">
184 184
                             <table cellspacing="0" cellpadding="0">
185 185
                                 <tr class="subtotal">
186
-                                    <td class="name"><?php _e( 'Sub Total:', 'invoicing' );?></td>
187
-                                    <td class="total"><?php echo $subtotal;?></td>
186
+                                    <td class="name"><?php _e('Sub Total:', 'invoicing'); ?></td>
187
+                                    <td class="total"><?php echo $subtotal; ?></td>
188 188
                                     <td class="action"></td>
189 189
                                 </tr>
190 190
                                 <tr class="discount">
191
-                                    <td class="name"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice->ID ) ); ?>:</td>
192
-                                    <td class="total"><?php echo wpinv_discount( $invoice->ID, true, true ); ?></td>
191
+                                    <td class="name"><?php wpinv_get_discount_label(wpinv_discount_code($invoice->ID)); ?>:</td>
192
+                                    <td class="total"><?php echo wpinv_discount($invoice->ID, true, true); ?></td>
193 193
                                     <td class="action"></td>
194 194
                                 </tr>
195
-                                <?php if ( $use_taxes ) { ?>
195
+                                <?php if ($use_taxes) { ?>
196 196
                                 <tr class="tax">
197
-                                    <td class="name"><?php _e( 'Tax:', 'invoicing' );?></td>
198
-                                    <td class="total"><?php echo $tax;?></td>
197
+                                    <td class="name"><?php _e('Tax:', 'invoicing'); ?></td>
198
+                                    <td class="total"><?php echo $tax; ?></td>
199 199
                                     <td class="action"></td>
200 200
                                 </tr>
201 201
                                 <?php } ?>
202 202
                                 <tr class="total">
203
-                                    <td class="name"><?php echo apply_filters( 'wpinv_invoice_items_total_label', __( 'Invoice Total:', 'invoicing' ), $invoice );?></td>
204
-                                    <td class="total"><?php echo $total;?></td>
203
+                                    <td class="name"><?php echo apply_filters('wpinv_invoice_items_total_label', __('Invoice Total:', 'invoicing'), $invoice); ?></td>
204
+                                    <td class="total"><?php echo $total; ?></td>
205 205
                                     <td class="action"></td>
206 206
                                 </tr>
207 207
                             </table>
@@ -212,90 +212,90 @@  discard block
 block discarded – undo
212 212
             <div class="wpinv-actions">
213 213
                 <?php ob_start(); ?>
214 214
                 <?php
215
-                    if ( !$invoice->is_paid() && !$invoice->is_refunded() ) {
216
-                        if ( !$invoice->is_recurring() ) {
217
-                            echo wpinv_item_dropdown( array(
215
+                    if (!$invoice->is_paid() && !$invoice->is_refunded()) {
216
+                        if (!$invoice->is_recurring()) {
217
+                            echo wpinv_item_dropdown(array(
218 218
                                 'name'             => 'wpinv_invoice_item',
219 219
                                 'id'               => 'wpinv_invoice_item',
220 220
                                 'show_recurring'   => true,
221 221
                                 'class'            => 'wpi_select2',
222
-                            ) );
222
+                            ));
223 223
                     ?>
224
-                <input type="button" value="<?php echo sprintf(esc_attr__( 'Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e( 'Create new item', 'invoicing' );?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e( 'Recalculate Totals', 'invoicing' );?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">
224
+                <input type="button" value="<?php echo sprintf(esc_attr__('Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e('Create new item', 'invoicing'); ?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e('Recalculate Totals', 'invoicing'); ?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">
225 225
                     <?php } ?>
226
-                <?php do_action( 'wpinv_invoice_items_actions', $invoice ); ?>
227
-                <?php $item_actions = ob_get_clean(); echo apply_filters( 'wpinv_invoice_items_actions_content', $item_actions, $invoice, $post ); ?>
226
+                <?php do_action('wpinv_invoice_items_actions', $invoice); ?>
227
+                <?php $item_actions = ob_get_clean(); echo apply_filters('wpinv_invoice_items_actions_content', $item_actions, $invoice, $post); ?>
228 228
             </div>
229 229
         </div>
230 230
         <?php
231 231
     }
232 232
 
233
-    public static function prices( $post ) {        
233
+    public static function prices($post) {        
234 234
         $symbol         = wpinv_currency_symbol();
235 235
         $position       = wpinv_currency_position();
236
-        $item           = new WPInv_Item( $post->ID );
236
+        $item           = new WPInv_Item($post->ID);
237 237
 
238 238
         $price                = $item->get_price();
239 239
         $is_dynamic_pricing   = $item->get_is_dynamic_pricing();
240 240
         $minimum_price        = $item->get_minimum_price();
241 241
         $is_recurring         = $item->is_recurring();
242 242
         $period               = $item->get_recurring_period();
243
-        $interval             = absint( $item->get_recurring_interval() );
244
-        $times                = absint( $item->get_recurring_limit() );
243
+        $interval             = absint($item->get_recurring_interval());
244
+        $times                = absint($item->get_recurring_limit());
245 245
         $free_trial           = $item->has_free_trial();
246 246
         $trial_interval       = $item->get_trial_interval();
247 247
         $trial_period         = $item->get_trial_period();
248 248
 
249 249
         $intervals            = array();
250
-        for ( $i = 1; $i <= 90; $i++ ) {
250
+        for ($i = 1; $i <= 90; $i++) {
251 251
             $intervals[$i] = $i;
252 252
         }
253 253
 
254
-        $interval       = $interval > 0 ? $interval : 1;
254
+        $interval = $interval > 0 ? $interval : 1;
255 255
 
256 256
         $class = $is_recurring ? 'wpinv-recurring-y' : 'wpinv-recurring-n';
257 257
 
258 258
         $minimum_price_style = 'margin-left: 24px;';
259
-        if(! $is_dynamic_pricing ) {
259
+        if (!$is_dynamic_pricing) {
260 260
             $minimum_price_style .= 'display: none;';
261 261
         }
262 262
 
263 263
         ?>
264
-        <p class="wpinv-row-prices"><?php echo ( $position != 'right' ? $symbol . '&nbsp;' : '' );?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount( 0 ); ?>" value="<?php echo $price;?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled( $item->is_editable(), false ); ?> /><?php echo ( $position == 'right' ? '&nbsp;' . $symbol : '' );?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce( 'wpinv_item_meta_box_save' ) ;?>" />
265
-        <?php do_action( 'wpinv_prices_metabox_price', $item ); ?>
264
+        <p class="wpinv-row-prices"><?php echo ($position != 'right' ? $symbol . '&nbsp;' : ''); ?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount(0); ?>" value="<?php echo $price; ?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled($item->is_editable(), false); ?> /><?php echo ($position == 'right' ? '&nbsp;' . $symbol : ''); ?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce('wpinv_item_meta_box_save'); ?>" />
265
+        <?php do_action('wpinv_prices_metabox_price', $item); ?>
266 266
         </p>
267 267
 
268
-    <?php if( $item->supports_dynamic_pricing() ) { ?>
268
+    <?php if ($item->supports_dynamic_pricing()) { ?>
269 269
 
270 270
         <p class="wpinv-row-name-your-price">
271 271
             <label>
272
-                <input type="checkbox" name="wpinv_name_your_price" id="wpinv_name_your_price" value="1" <?php checked( 1, $is_dynamic_pricing ); ?> />
273
-                <?php echo apply_filters( 'wpinv_name_your_price_toggle_text', __( 'User can set a custom price', 'invoicing' ) ); ?>
272
+                <input type="checkbox" name="wpinv_name_your_price" id="wpinv_name_your_price" value="1" <?php checked(1, $is_dynamic_pricing); ?> />
273
+                <?php echo apply_filters('wpinv_name_your_price_toggle_text', __('User can set a custom price', 'invoicing')); ?>
274 274
             </label>
275
-            <?php do_action( 'wpinv_prices_metabox_name_your_price_field', $item ); ?>
275
+            <?php do_action('wpinv_prices_metabox_name_your_price_field', $item); ?>
276 276
         </p>
277 277
 
278 278
         <p class="wpinv-row-minimum-price" style="<?php echo $minimum_price_style; ?>">
279 279
             <label>
280
-                <?php _e( 'Minimum Price', 'invoicing' ); ?>
281
-                <?php echo ( $position != 'right' ? $symbol . '&nbsp;' : '' );?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount( 0 ); ?>" value="<?php echo $minimum_price;?>" id="wpinv_minimum_price" name="wpinv_minimum_price" class="medium-text wpi-field-price" <?php disabled( $item->is_editable(), false ); ?> /><?php echo ( $position == 'right' ? '&nbsp;' . $symbol : '' );?>
280
+                <?php _e('Minimum Price', 'invoicing'); ?>
281
+                <?php echo ($position != 'right' ? $symbol . '&nbsp;' : ''); ?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount(0); ?>" value="<?php echo $minimum_price; ?>" id="wpinv_minimum_price" name="wpinv_minimum_price" class="medium-text wpi-field-price" <?php disabled($item->is_editable(), false); ?> /><?php echo ($position == 'right' ? '&nbsp;' . $symbol : ''); ?>
282 282
             </label>
283 283
 
284
-            <?php do_action( 'wpinv_prices_metabox_minimum_price_field', $item ); ?>
284
+            <?php do_action('wpinv_prices_metabox_minimum_price_field', $item); ?>
285 285
         </p>
286 286
 
287 287
     <?php } ?>
288 288
 
289 289
         <p class="wpinv-row-is-recurring">
290 290
             <label for="wpinv_is_recurring">
291
-                <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked( 1, $is_recurring ); ?> />
292
-                <?php echo apply_filters( 'wpinv_is_recurring_toggle_text', __( 'Is Recurring Item?', 'invoicing' ) ); ?>
291
+                <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked(1, $is_recurring); ?> />
292
+                <?php echo apply_filters('wpinv_is_recurring_toggle_text', __('Is Recurring Item?', 'invoicing')); ?>
293 293
             </label>
294
-            <?php do_action( 'wpinv_prices_metabox_is_recurring_field', $item ); ?>
294
+            <?php do_action('wpinv_prices_metabox_is_recurring_field', $item); ?>
295 295
         </p>
296
-        <p class="wpinv-row-recurring-fields <?php echo $class;?>">
297
-            <label class="wpinv-period" for="wpinv_recurring_period"><?php _e( 'Recurring', 'invoicing' );?> <select class="wpinv-select wpi_select2" id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e( 'day(s)', 'invoicing' ); ?>" <?php selected( 'D', $period );?>><?php _e( 'Daily', 'invoicing' ); ?></option><option value="W" data-text="<?php esc_attr_e( 'week(s)', 'invoicing' ); ?>" <?php selected( 'W', $period );?>><?php _e( 'Weekly', 'invoicing' ); ?></option><option value="M" data-text="<?php esc_attr_e( 'month(s)', 'invoicing' ); ?>" <?php selected( 'M', $period );?>><?php _e( 'Monthly', 'invoicing' ); ?></option><option value="Y" data-text="<?php esc_attr_e( 'year(s)', 'invoicing' ); ?>" <?php selected( 'Y', $period );?>><?php _e( 'Yearly', 'invoicing' ); ?></option></select></label>
298
-            <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e( 'at every', 'invoicing' );?> <?php echo wpinv_html_select( array(
296
+        <p class="wpinv-row-recurring-fields <?php echo $class; ?>">
297
+            <label class="wpinv-period" for="wpinv_recurring_period"><?php _e('Recurring', 'invoicing'); ?> <select class="wpinv-select wpi_select2" id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e('day(s)', 'invoicing'); ?>" <?php selected('D', $period); ?>><?php _e('Daily', 'invoicing'); ?></option><option value="W" data-text="<?php esc_attr_e('week(s)', 'invoicing'); ?>" <?php selected('W', $period); ?>><?php _e('Weekly', 'invoicing'); ?></option><option value="M" data-text="<?php esc_attr_e('month(s)', 'invoicing'); ?>" <?php selected('M', $period); ?>><?php _e('Monthly', 'invoicing'); ?></option><option value="Y" data-text="<?php esc_attr_e('year(s)', 'invoicing'); ?>" <?php selected('Y', $period); ?>><?php _e('Yearly', 'invoicing'); ?></option></select></label>
298
+            <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e('at every', 'invoicing'); ?> <?php echo wpinv_html_select(array(
299 299
                 'options'          => $intervals,
300 300
                 'name'             => 'wpinv_recurring_interval',
301 301
                 'id'               => 'wpinv_recurring_interval',
@@ -303,30 +303,30 @@  discard block
 block discarded – undo
303 303
                 'show_option_all'  => false,
304 304
                 'show_option_none' => false,
305 305
                 'class'            => 'wpi_select2',
306
-            ) ); ?> <span id="wpinv_interval_text"><?php _e( 'day(s)', 'invoicing' );?></span></label>
307
-            <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e( 'for', 'invoicing' );?> <input class="small-text" type="number" value="<?php echo $times;?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e( 'time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing' );?></label>
306
+            )); ?> <span id="wpinv_interval_text"><?php _e('day(s)', 'invoicing'); ?></span></label>
307
+            <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e('for', 'invoicing'); ?> <input class="small-text" type="number" value="<?php echo $times; ?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e('time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing'); ?></label>
308 308
             <span class="clear wpi-trial-clr"></span>
309 309
             <label class="wpinv-free-trial" for="wpinv_free_trial">
310
-                <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked( true, (bool)$free_trial ); ?> /> 
311
-                <?php echo __( 'Offer free trial for', 'invoicing' ); ?>
310
+                <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked(true, (bool) $free_trial); ?> /> 
311
+                <?php echo __('Offer free trial for', 'invoicing'); ?>
312 312
             </label>
313 313
             <label class="wpinv-trial-interval" for="wpinv_trial_interval">
314
-                <input class="small-text" type="number" value="<?php echo $trial_interval;?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select wpi_select2" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected( 'D', $trial_period );?>><?php _e( 'day(s)', 'invoicing' ); ?></option><option value="W" <?php selected( 'W', $trial_period );?>><?php _e( 'week(s)', 'invoicing' ); ?></option><option value="M" <?php selected( 'M', $trial_period );?>><?php _e( 'month(s)', 'invoicing' ); ?></option><option value="Y" <?php selected( 'Y', $trial_period );?>><?php _e( 'year(s)', 'invoicing' ); ?></option></select>
314
+                <input class="small-text" type="number" value="<?php echo $trial_interval; ?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select wpi_select2" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected('D', $trial_period); ?>><?php _e('day(s)', 'invoicing'); ?></option><option value="W" <?php selected('W', $trial_period); ?>><?php _e('week(s)', 'invoicing'); ?></option><option value="M" <?php selected('M', $trial_period); ?>><?php _e('month(s)', 'invoicing'); ?></option><option value="Y" <?php selected('Y', $trial_period); ?>><?php _e('year(s)', 'invoicing'); ?></option></select>
315 315
             </label>
316
-            <?php do_action( 'wpinv_prices_metabox_recurring_fields', $item ); ?>
316
+            <?php do_action('wpinv_prices_metabox_recurring_fields', $item); ?>
317 317
         </p>
318
-        <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type( $post->ID ); ?>" />
319
-        <?php do_action( 'wpinv_item_price_field', $post->ID ); ?>
318
+        <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type($post->ID); ?>" />
319
+        <?php do_action('wpinv_item_price_field', $post->ID); ?>
320 320
         <?php
321 321
     }
322 322
 
323
-    public static function vat_rules( $post ) {
323
+    public static function vat_rules($post) {
324 324
         global $wpinv_euvat;
325 325
 
326
-        $rule_type = $wpinv_euvat->get_item_rule( $post->ID );
326
+        $rule_type = $wpinv_euvat->get_item_rule($post->ID);
327 327
         ?>
328
-        <p><label for="wpinv_vat_rules"><strong><?php _e( 'Select how VAT rules will be applied:', 'invoicing' );?></strong></label>&nbsp;&nbsp;&nbsp;
329
-        <?php echo wpinv_html_select( array(
328
+        <p><label for="wpinv_vat_rules"><strong><?php _e('Select how VAT rules will be applied:', 'invoicing'); ?></strong></label>&nbsp;&nbsp;&nbsp;
329
+        <?php echo wpinv_html_select(array(
330 330
                     'options'          => $wpinv_euvat->get_rules(),
331 331
                     'name'             => 'wpinv_vat_rules',
332 332
                     'id'               => 'wpinv_vat_rules',
@@ -334,20 +334,20 @@  discard block
 block discarded – undo
334 334
                     'show_option_all'  => false,
335 335
                     'show_option_none' => false,
336 336
                     'class'            => 'gdmbx2-text-medium wpinv-vat-rules wpi_select2',
337
-                ) ); ?>
337
+                )); ?>
338 338
         </p>
339
-        <p class="wpi-m0"><?php _e( 'When you select physical product rules, only consumers and businesses in your country will be charged VAT.  The VAT rate used will be the rate in your country.', 'invoicing' ); ?></p>
340
-        <p class="wpi-m0"><?php _e( 'If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer.  Only businesses in your country will be charged VAT.', 'invoicing' ); ?></p>
341
-        <p class="wpi-m0"><?php _e( 'Select "Tax-Free" if you do not want to charge VAT for this item.', 'invoicing' ); ?></p>
339
+        <p class="wpi-m0"><?php _e('When you select physical product rules, only consumers and businesses in your country will be charged VAT.  The VAT rate used will be the rate in your country.', 'invoicing'); ?></p>
340
+        <p class="wpi-m0"><?php _e('If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer.  Only businesses in your country will be charged VAT.', 'invoicing'); ?></p>
341
+        <p class="wpi-m0"><?php _e('Select "Tax-Free" if you do not want to charge VAT for this item.', 'invoicing'); ?></p>
342 342
         <?php
343 343
     }
344 344
 
345
-    public static function vat_classes( $post ) {
345
+    public static function vat_classes($post) {
346 346
         global $wpinv_euvat;
347 347
         
348
-        $vat_class = $wpinv_euvat->get_item_class( $post->ID );
348
+        $vat_class = $wpinv_euvat->get_item_class($post->ID);
349 349
         ?>
350
-        <p><?php echo wpinv_html_select( array(
350
+        <p><?php echo wpinv_html_select(array(
351 351
                     'options'          => $wpinv_euvat->get_all_classes(),
352 352
                     'name'             => 'wpinv_vat_class',
353 353
                     'id'               => 'wpinv_vat_class',
@@ -355,18 +355,18 @@  discard block
 block discarded – undo
355 355
                     'show_option_all'  => false,
356 356
                     'show_option_none' => false,
357 357
                     'class'            => 'gdmbx2-text-medium wpinv-vat-class wpi_select2',
358
-                ) ); ?>
358
+                )); ?>
359 359
         </p>
360
-        <p class="wpi-m0"><?php _e( 'Select the VAT rate class to use for this invoice item.', 'invoicing' ); ?></p>
360
+        <p class="wpi-m0"><?php _e('Select the VAT rate class to use for this invoice item.', 'invoicing'); ?></p>
361 361
         <?php
362 362
     }
363 363
 
364
-    public static function item_info( $post ) {
365
-        $item_type = wpinv_get_item_type( $post->ID );
366
-        do_action( 'wpinv_item_info_metabox_before', $post );
364
+    public static function item_info($post) {
365
+        $item_type = wpinv_get_item_type($post->ID);
366
+        do_action('wpinv_item_info_metabox_before', $post);
367 367
         ?>
368
-        <p><label for="wpinv_item_type"><strong><?php _e( 'Type:', 'invoicing' );?></strong></label>&nbsp;&nbsp;&nbsp;
369
-        <?php echo wpinv_html_select( array(
368
+        <p><label for="wpinv_item_type"><strong><?php _e('Type:', 'invoicing'); ?></strong></label>&nbsp;&nbsp;&nbsp;
369
+        <?php echo wpinv_html_select(array(
370 370
                     'options'          => wpinv_get_item_types(),
371 371
                     'name'             => 'wpinv_item_type',
372 372
                     'id'               => 'wpinv_item_type',
@@ -374,127 +374,127 @@  discard block
 block discarded – undo
374 374
                     'show_option_all'  => false,
375 375
                     'show_option_none' => false,
376 376
                     'class'            => 'gdmbx2-text-medium wpinv-item-type',
377
-                ) ); ?>
377
+                )); ?>
378 378
         </p>
379
-        <p class="wpi-m0"><?php _e( 'Select item type.', 'invoicing' );?><br><?php _e( '<b>Standard:</b> Standard item type', 'invoicing' );?><br><?php _e( '<b>Fee:</b> Like Registration Fee, Sign up Fee etc.', 'invoicing' );?></p>
379
+        <p class="wpi-m0"><?php _e('Select item type.', 'invoicing'); ?><br><?php _e('<b>Standard:</b> Standard item type', 'invoicing'); ?><br><?php _e('<b>Fee:</b> Like Registration Fee, Sign up Fee etc.', 'invoicing'); ?></p>
380 380
         <?php
381
-        do_action( 'wpinv_item_info_metabox_after', $post );
381
+        do_action('wpinv_item_info_metabox_after', $post);
382 382
     }
383 383
 
384
-    public static function meta_values( $post ) {
385
-        $meta_keys = apply_filters( 'wpinv_show_meta_values_for_keys', array(
384
+    public static function meta_values($post) {
385
+        $meta_keys = apply_filters('wpinv_show_meta_values_for_keys', array(
386 386
             'type',
387 387
             'custom_id'
388
-        ) );
388
+        ));
389 389
 
390
-        if ( empty( $meta_keys ) ) {
390
+        if (empty($meta_keys)) {
391 391
             return;
392 392
         }
393 393
 
394
-        do_action( 'wpinv_meta_values_metabox_before', $post );
394
+        do_action('wpinv_meta_values_metabox_before', $post);
395 395
 
396
-        foreach ( $meta_keys as $meta_key ) {
396
+        foreach ($meta_keys as $meta_key) {
397 397
             ?>
398
-            <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta( $post->ID, '_wpinv_' . $meta_key, true ); ?></label></p>
398
+            <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta($post->ID, '_wpinv_' . $meta_key, true); ?></label></p>
399 399
             <?php 
400 400
         }
401 401
 
402
-        do_action( 'wpinv_meta_values_metabox_after', $post );
402
+        do_action('wpinv_meta_values_metabox_after', $post);
403 403
     }
404 404
 
405 405
     /**
406 406
      * Display the items buy now shortcode.
407 407
      */
408
-    public static function shortcode( $post ) {
408
+    public static function shortcode($post) {
409 409
 
410
-        if ( ! is_numeric( $post ) ) {
410
+        if (!is_numeric($post)) {
411 411
             $post = $post->ID;
412 412
         }
413 413
 
414 414
         echo "<input type='text' style='min-width: 100%; font-size: small;' value='[getpaid item=$post]' disabled>";
415 415
     }
416 416
 
417
-    public static function save( $post_id, $data, $post ) {
418
-        $invoice        = new WPInv_Invoice( $post_id );
417
+    public static function save($post_id, $data, $post) {
418
+        $invoice        = new WPInv_Invoice($post_id);
419 419
 
420 420
         // Billing
421
-        $first_name     = sanitize_text_field( $data['wpinv_first_name'] );
422
-        $last_name      = sanitize_text_field( $data['wpinv_last_name'] );
423
-        $company        = sanitize_text_field( $data['wpinv_company'] );
424
-        $vat_number     = sanitize_text_field( $data['wpinv_vat_number'] );
425
-        $phone          = sanitize_text_field( $data['wpinv_phone'] );
426
-        $address        = sanitize_text_field( $data['wpinv_address'] );
427
-        $city           = sanitize_text_field( $data['wpinv_city'] );
428
-        $zip            = sanitize_text_field( $data['wpinv_zip'] );
429
-        $country        = sanitize_text_field( $data['wpinv_country'] );
430
-        $state          = sanitize_text_field( $data['wpinv_state'] );
421
+        $first_name     = sanitize_text_field($data['wpinv_first_name']);
422
+        $last_name      = sanitize_text_field($data['wpinv_last_name']);
423
+        $company        = sanitize_text_field($data['wpinv_company']);
424
+        $vat_number     = sanitize_text_field($data['wpinv_vat_number']);
425
+        $phone          = sanitize_text_field($data['wpinv_phone']);
426
+        $address        = sanitize_text_field($data['wpinv_address']);
427
+        $city           = sanitize_text_field($data['wpinv_city']);
428
+        $zip            = sanitize_text_field($data['wpinv_zip']);
429
+        $country        = sanitize_text_field($data['wpinv_country']);
430
+        $state          = sanitize_text_field($data['wpinv_state']);
431 431
 
432 432
         // Details
433
-        $status         = sanitize_text_field( $data['wpinv_status'] );
434
-        $old_status     = !empty( $data['original_post_status'] ) ? sanitize_text_field( $data['original_post_status'] ) : $status;
435
-        $number         = sanitize_text_field( $data['wpinv_number'] );
436
-        $due_date       = isset( $data['wpinv_due_date'] ) ? sanitize_text_field( $data['wpinv_due_date'] ) : '';
437
-        $date_created   = isset( $data['date_created'] ) ? sanitize_text_field( $data['date_created'] ) : '';
433
+        $status         = sanitize_text_field($data['wpinv_status']);
434
+        $old_status     = !empty($data['original_post_status']) ? sanitize_text_field($data['original_post_status']) : $status;
435
+        $number         = sanitize_text_field($data['wpinv_number']);
436
+        $due_date       = isset($data['wpinv_due_date']) ? sanitize_text_field($data['wpinv_due_date']) : '';
437
+        $date_created   = isset($data['date_created']) ? sanitize_text_field($data['date_created']) : '';
438 438
         //$discounts      = sanitize_text_field( $data['wpinv_discounts'] );
439 439
         //$discount       = sanitize_text_field( $data['wpinv_discount'] );
440 440
 
441 441
         $disable_taxes = 0;
442 442
 
443
-        if ( ! empty( $data['disable_taxes'] ) ) {
443
+        if (!empty($data['disable_taxes'])) {
444 444
             $disable_taxes = 1;
445 445
         }
446 446
 
447
-        $ip             = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip();
448
-
449
-        $invoice->set( 'due_date', $due_date );
450
-        $invoice->set( 'first_name', $first_name );
451
-        $invoice->set( 'last_name', $last_name );
452
-        $invoice->set( 'company', $company );
453
-        $invoice->set( 'vat_number', $vat_number );
454
-        $invoice->set( 'phone', $phone );
455
-        $invoice->set( 'address', $address );
456
-        $invoice->set( 'city', $city );
457
-        $invoice->set( 'zip', $zip );
458
-        $invoice->set( 'country', $country );
459
-        $invoice->set( 'state', $state );
460
-        $invoice->set( 'status', $status );
461
-        $invoice->set( 'set', $status );
447
+        $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip();
448
+
449
+        $invoice->set('due_date', $due_date);
450
+        $invoice->set('first_name', $first_name);
451
+        $invoice->set('last_name', $last_name);
452
+        $invoice->set('company', $company);
453
+        $invoice->set('vat_number', $vat_number);
454
+        $invoice->set('phone', $phone);
455
+        $invoice->set('address', $address);
456
+        $invoice->set('city', $city);
457
+        $invoice->set('zip', $zip);
458
+        $invoice->set('country', $country);
459
+        $invoice->set('state', $state);
460
+        $invoice->set('status', $status);
461
+        $invoice->set('set', $status);
462 462
         //$invoice->set( 'number', $number );
463 463
         //$invoice->set( 'discounts', $discounts );
464 464
         //$invoice->set( 'discount', $discount );
465
-        $invoice->set( 'disable_taxes', $disable_taxes );
466
-        $invoice->set( 'ip', $ip );
465
+        $invoice->set('disable_taxes', $disable_taxes);
466
+        $invoice->set('ip', $ip);
467 467
         $invoice->old_status = $_POST['original_post_status'];
468 468
         
469 469
         $currency = $invoice->get_currency();
470
-        if ( ! empty( $data['wpinv_currency'] ) ) {
471
-            $currency = sanitize_text_field( $data['wpinv_currency'] );
470
+        if (!empty($data['wpinv_currency'])) {
471
+            $currency = sanitize_text_field($data['wpinv_currency']);
472 472
         }
473 473
 
474
-        if ( empty( $currency ) ) {
474
+        if (empty($currency)) {
475 475
             $currency = wpinv_get_currency();
476 476
         }
477 477
 
478
-        if ( ! $invoice->is_paid() ) {
478
+        if (!$invoice->is_paid()) {
479 479
             $invoice->currency = $currency;
480 480
         }
481 481
 
482
-        if ( !empty( $data['wpinv_gateway'] ) ) {
483
-            $invoice->set( 'gateway', sanitize_text_field( $data['wpinv_gateway'] ) );
482
+        if (!empty($data['wpinv_gateway'])) {
483
+            $invoice->set('gateway', sanitize_text_field($data['wpinv_gateway']));
484 484
         }
485 485
         $saved = $invoice->save();
486 486
 
487 487
         $emails = '';
488
-        if ( ! empty( $data['wpinv_cc'] ) ) {
489
-            $emails = wpinv_clean( $data['wpinv_cc'] );
488
+        if (!empty($data['wpinv_cc'])) {
489
+            $emails = wpinv_clean($data['wpinv_cc']);
490 490
         }
491
-        update_post_meta( $invoice->ID, 'wpinv_email_cc', $emails );
491
+        update_post_meta($invoice->ID, 'wpinv_email_cc', $emails);
492 492
 
493
-        if ( ! empty( $date_created ) && strtotime( $date_created, current_time( 'timestamp' ) ) ) {
493
+        if (!empty($date_created) && strtotime($date_created, current_time('timestamp'))) {
494 494
 
495
-            $time = strtotime( $date_created, current_time( 'timestamp' ) );
496
-            $date = date( 'Y-m-d H:i:s', $time );
497
-            $date_gmt = get_gmt_from_date( $date );
495
+            $time = strtotime($date_created, current_time('timestamp'));
496
+            $date = date('Y-m-d H:i:s', $time);
497
+            $date_gmt = get_gmt_from_date($date);
498 498
 
499 499
             wp_update_post(
500 500
                 array(
@@ -509,37 +509,37 @@  discard block
 block discarded – undo
509 509
         }
510 510
 
511 511
         // Check for payment notes
512
-        if ( !empty( $data['invoice_note'] ) ) {
513
-            $note               = wp_kses( $data['invoice_note'], array() );
514
-            $note_type          = sanitize_text_field( $data['invoice_note_type'] );
512
+        if (!empty($data['invoice_note'])) {
513
+            $note               = wp_kses($data['invoice_note'], array());
514
+            $note_type          = sanitize_text_field($data['invoice_note_type']);
515 515
             $is_customer_note   = $note_type == 'customer' ? 1 : 0;
516 516
 
517
-            wpinv_insert_payment_note( $invoice->ID, $note, $is_customer_note );
517
+            wpinv_insert_payment_note($invoice->ID, $note, $is_customer_note);
518 518
         }
519 519
 
520 520
         // Update user address if empty.
521
-        if ( $saved && !empty( $invoice ) ) {
522
-            if ( $user_id = $invoice->get_user_id() ) {
523
-                $user_address = wpinv_get_user_address( $user_id, false );
521
+        if ($saved && !empty($invoice)) {
522
+            if ($user_id = $invoice->get_user_id()) {
523
+                $user_address = wpinv_get_user_address($user_id, false);
524 524
 
525 525
                 if (empty($user_address['first_name'])) {
526
-                    update_user_meta( $user_id, '_wpinv_first_name', $first_name );
527
-                    update_user_meta( $user_id, '_wpinv_last_name', $last_name );
526
+                    update_user_meta($user_id, '_wpinv_first_name', $first_name);
527
+                    update_user_meta($user_id, '_wpinv_last_name', $last_name);
528 528
                 } else if (empty($user_address['last_name']) && $user_address['first_name'] == $first_name) {
529
-                    update_user_meta( $user_id, '_wpinv_last_name', $last_name );
529
+                    update_user_meta($user_id, '_wpinv_last_name', $last_name);
530 530
                 }
531 531
 
532 532
                 if (empty($user_address['address']) || empty($user_address['city']) || empty($user_address['state']) || empty($user_address['country'])) {
533
-                    update_user_meta( $user_id, '_wpinv_address', $address );
534
-                    update_user_meta( $user_id, '_wpinv_city', $city );
535
-                    update_user_meta( $user_id, '_wpinv_state', $state );
536
-                    update_user_meta( $user_id, '_wpinv_country', $country );
537
-                    update_user_meta( $user_id, '_wpinv_zip', $zip );
538
-                    update_user_meta( $user_id, '_wpinv_phone', $phone );
533
+                    update_user_meta($user_id, '_wpinv_address', $address);
534
+                    update_user_meta($user_id, '_wpinv_city', $city);
535
+                    update_user_meta($user_id, '_wpinv_state', $state);
536
+                    update_user_meta($user_id, '_wpinv_country', $country);
537
+                    update_user_meta($user_id, '_wpinv_zip', $zip);
538
+                    update_user_meta($user_id, '_wpinv_phone', $phone);
539 539
                 }
540 540
             }
541 541
 
542
-            do_action( 'wpinv_invoice_metabox_saved', $invoice );
542
+            do_action('wpinv_invoice_metabox_saved', $invoice);
543 543
         }
544 544
 
545 545
         return $saved;
Please login to merge, or discard this patch.
includes/wpinv-item-functions.php 1 patch
Spacing   +306 added lines, -306 removed lines patch added patch discarded remove patch
@@ -1,23 +1,23 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-function wpinv_get_item_by_id( $id ) {
6
-    return wpinv_get_item_by( 'id', $id );
5
+function wpinv_get_item_by_id($id) {
6
+    return wpinv_get_item_by('id', $id);
7 7
 }
8 8
 
9
-function wpinv_get_item_by( $field = '', $value = '', $type = '' ) {
10
-    if( empty( $field ) || empty( $value ) ) {
9
+function wpinv_get_item_by($field = '', $value = '', $type = '') {
10
+    if (empty($field) || empty($value)) {
11 11
         return false;
12 12
     }
13 13
     
14 14
     $posts = array();
15 15
 
16
-    switch( strtolower( $field ) ) {
16
+    switch (strtolower($field)) {
17 17
         case 'id':
18
-            $item = new WPInv_Item( $value );
18
+            $item = new WPInv_Item($value);
19 19
 
20
-            if ( !empty( $item ) && $item->post_type == 'wpi_item' ) {
20
+            if (!empty($item) && $item->post_type == 'wpi_item') {
21 21
                 return $item;
22 22
             }
23 23
             return false;
@@ -26,16 +26,16 @@  discard block
 block discarded – undo
26 26
 
27 27
         case 'slug':
28 28
         case 'name':
29
-            $posts = get_posts( array(
29
+            $posts = get_posts(array(
30 30
                 'post_type'      => 'wpi_item',
31 31
                 'name'           => $value,
32 32
                 'posts_per_page' => 1,
33 33
                 'post_status'    => 'any'
34
-            ) );
34
+            ));
35 35
 
36 36
             break;
37 37
         case 'custom_id':
38
-            if ( empty( $value ) || empty( $type ) ) {
38
+            if (empty($value) || empty($type)) {
39 39
                 return false;
40 40
             }
41 41
             
@@ -55,10 +55,10 @@  discard block
 block discarded – undo
55 55
                 'post_status'    => 'any',
56 56
                 'orderby'        => 'ID',
57 57
                 'order'          => 'ASC',
58
-                'meta_query'     => array( $meta_query )
58
+                'meta_query'     => array($meta_query)
59 59
             );
60 60
             
61
-            $posts = get_posts( $args );
61
+            $posts = get_posts($args);
62 62
 
63 63
             break;
64 64
 
@@ -66,10 +66,10 @@  discard block
 block discarded – undo
66 66
             return false;
67 67
     }
68 68
     
69
-    if ( !empty( $posts[0] ) ) {
70
-        $item = new WPInv_Item( $posts[0]->ID );
69
+    if (!empty($posts[0])) {
70
+        $item = new WPInv_Item($posts[0]->ID);
71 71
 
72
-        if ( !empty( $item ) && $item->post_type == 'wpi_item' ) {
72
+        if (!empty($item) && $item->post_type == 'wpi_item') {
73 73
             return $item;
74 74
         }
75 75
     }
@@ -77,10 +77,10 @@  discard block
 block discarded – undo
77 77
     return false;
78 78
 }
79 79
 
80
-function wpinv_get_item( $item = 0 ) {
81
-    if ( is_numeric( $item ) ) {
82
-        $item = get_post( $item );
83
-        if ( ! $item || 'wpi_item' !== $item->post_type )
80
+function wpinv_get_item($item = 0) {
81
+    if (is_numeric($item)) {
82
+        $item = get_post($item);
83
+        if (!$item || 'wpi_item' !== $item->post_type)
84 84
             return null;
85 85
         return $item;
86 86
     }
@@ -93,18 +93,18 @@  discard block
 block discarded – undo
93 93
 
94 94
     $item = get_posts($args);
95 95
 
96
-    if ( $item ) {
96
+    if ($item) {
97 97
         return $item[0];
98 98
     }
99 99
 
100 100
     return null;
101 101
 }
102 102
 
103
-function wpinv_get_all_items( $args = array() ) {
103
+function wpinv_get_all_items($args = array()) {
104 104
 
105
-    $args = wp_parse_args( $args, array(
106
-        'status'         => array( 'publish' ),
107
-        'limit'          => get_option( 'posts_per_page' ),
105
+    $args = wp_parse_args($args, array(
106
+        'status'         => array('publish'),
107
+        'limit'          => get_option('posts_per_page'),
108 108
         'page'           => 1,
109 109
         'exclude'        => array(),
110 110
         'orderby'        => 'date',
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
         'meta_query'     => array(),
114 114
         'return'         => 'objects',
115 115
         'paginate'       => false,
116
-    ) );
116
+    ));
117 117
 
118 118
     $wp_query_args = array(
119 119
         'post_type'      => 'wpi_item',
@@ -123,26 +123,26 @@  discard block
 block discarded – undo
123 123
         'fields'         => 'ids',
124 124
         'orderby'        => $args['orderby'],
125 125
         'order'          => $args['order'],
126
-        'paged'          => absint( $args['page'] ),
126
+        'paged'          => absint($args['page']),
127 127
     );
128 128
 
129
-    if ( ! empty( $args['exclude'] ) ) {
130
-        $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] );
129
+    if (!empty($args['exclude'])) {
130
+        $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']);
131 131
     }
132 132
 
133
-    if ( ! $args['paginate' ] ) {
133
+    if (!$args['paginate']) {
134 134
         $wp_query_args['no_found_rows'] = true;
135 135
     }
136 136
 
137
-    if ( ! empty( $args['search'] ) ) {
137
+    if (!empty($args['search'])) {
138 138
         $wp_query_args['s'] = $args['search'];
139 139
     }
140 140
 
141
-    if ( ! empty( $args['type'] ) && $args['type'] !== wpinv_item_types() ) {
142
-        $types = wpinv_parse_list( $args['type'] );
141
+    if (!empty($args['type']) && $args['type'] !== wpinv_item_types()) {
142
+        $types = wpinv_parse_list($args['type']);
143 143
         $wp_query_args['meta_query'][] = array(
144 144
             'key'     => '_wpinv_type',
145
-            'value'   => implode( ',', $types ),
145
+            'value'   => implode(',', $types),
146 146
             'compare' => 'IN',
147 147
         );
148 148
     }
@@ -150,17 +150,17 @@  discard block
 block discarded – undo
150 150
     $wp_query_args = apply_filters('wpinv_get_items_args', $wp_query_args, $args);
151 151
 
152 152
     // Get results.
153
-    $items = new WP_Query( $wp_query_args );
153
+    $items = new WP_Query($wp_query_args);
154 154
 
155
-    if ( 'objects' === $args['return'] ) {
156
-        $return = array_map( 'wpinv_get_item_by_id', $items->posts );
157
-    } elseif ( 'self' === $args['return'] ) {
155
+    if ('objects' === $args['return']) {
156
+        $return = array_map('wpinv_get_item_by_id', $items->posts);
157
+    } elseif ('self' === $args['return']) {
158 158
         return $items;
159 159
     } else {
160 160
         $return = $items->posts;
161 161
     }
162 162
 
163
-    if ( $args['paginate' ] ) {
163
+    if ($args['paginate']) {
164 164
         return (object) array(
165 165
             'items'      => $return,
166 166
             'total'         => $items->found_posts,
@@ -172,12 +172,12 @@  discard block
 block discarded – undo
172 172
 
173 173
 }
174 174
 
175
-function wpinv_is_free_item( $item_id = 0 ) {
176
-    if( empty( $item_id ) ) {
175
+function wpinv_is_free_item($item_id = 0) {
176
+    if (empty($item_id)) {
177 177
         return false;
178 178
     }
179 179
 
180
-    $item = new WPInv_Item( $item_id );
180
+    $item = new WPInv_Item($item_id);
181 181
     
182 182
     return $item->is_free();
183 183
 }
@@ -187,128 +187,128 @@  discard block
 block discarded – undo
187 187
  * 
188 188
  * @param WP_Post|WPInv_Item|Int $item The item to check for.
189 189
  */
190
-function wpinv_item_is_editable( $item = 0 ) {
190
+function wpinv_item_is_editable($item = 0) {
191 191
 
192 192
     // Fetch the item.
193
-    $item = new WPInv_Item( $item );
193
+    $item = new WPInv_Item($item);
194 194
 
195 195
     // Check if it is editable.
196 196
     return $item->is_editable();
197 197
 }
198 198
 
199
-function wpinv_get_item_price( $item_id = 0 ) {
200
-    if( empty( $item_id ) ) {
199
+function wpinv_get_item_price($item_id = 0) {
200
+    if (empty($item_id)) {
201 201
         return false;
202 202
     }
203 203
 
204
-    $item = new WPInv_Item( $item_id );
204
+    $item = new WPInv_Item($item_id);
205 205
     
206 206
     return $item->get_price();
207 207
 }
208 208
 
209
-function wpinv_is_recurring_item( $item_id = 0 ) {
210
-    if( empty( $item_id ) ) {
209
+function wpinv_is_recurring_item($item_id = 0) {
210
+    if (empty($item_id)) {
211 211
         return false;
212 212
     }
213 213
 
214
-    $item = new WPInv_Item( $item_id );
214
+    $item = new WPInv_Item($item_id);
215 215
     
216 216
     return $item->is_recurring();
217 217
 }
218 218
 
219
-function wpinv_item_price( $item_id = 0 ) {
220
-    if( empty( $item_id ) ) {
219
+function wpinv_item_price($item_id = 0) {
220
+    if (empty($item_id)) {
221 221
         return false;
222 222
     }
223 223
 
224
-    $price = wpinv_get_item_price( $item_id );
225
-    $price = wpinv_price( wpinv_format_amount( $price ) );
224
+    $price = wpinv_get_item_price($item_id);
225
+    $price = wpinv_price(wpinv_format_amount($price));
226 226
     
227
-    return apply_filters( 'wpinv_item_price', $price, $item_id );
227
+    return apply_filters('wpinv_item_price', $price, $item_id);
228 228
 }
229 229
 
230
-function wpinv_item_show_price( $item_id = 0, $echo = true ) {
231
-    if ( empty( $item_id ) ) {
230
+function wpinv_item_show_price($item_id = 0, $echo = true) {
231
+    if (empty($item_id)) {
232 232
         $item_id = get_the_ID();
233 233
     }
234 234
 
235
-    $price = wpinv_item_price( $item_id );
235
+    $price = wpinv_item_price($item_id);
236 236
 
237
-    $price           = apply_filters( 'wpinv_item_price', wpinv_sanitize_amount( $price ), $item_id );
237
+    $price           = apply_filters('wpinv_item_price', wpinv_sanitize_amount($price), $item_id);
238 238
     $formatted_price = '<span class="wpinv_price" id="wpinv_item_' . $item_id . '">' . $price . '</span>';
239
-    $formatted_price = apply_filters( 'wpinv_item_price_after_html', $formatted_price, $item_id, $price );
239
+    $formatted_price = apply_filters('wpinv_item_price_after_html', $formatted_price, $item_id, $price);
240 240
 
241
-    if ( $echo ) {
241
+    if ($echo) {
242 242
         echo $formatted_price;
243 243
     } else {
244 244
         return $formatted_price;
245 245
     }
246 246
 }
247 247
 
248
-function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) {
249
-    if ( is_null( $amount_override ) ) {
250
-        $original_price = get_post_meta( $item_id, '_wpinv_price', true );
248
+function wpinv_get_item_final_price($item_id = 0, $amount_override = null) {
249
+    if (is_null($amount_override)) {
250
+        $original_price = get_post_meta($item_id, '_wpinv_price', true);
251 251
     } else {
252 252
         $original_price = $amount_override;
253 253
     }
254 254
     
255 255
     $price = $original_price;
256 256
 
257
-    return apply_filters( 'wpinv_get_item_final_price', $price, $item_id );
257
+    return apply_filters('wpinv_get_item_final_price', $price, $item_id);
258 258
 }
259 259
 
260
-function wpinv_item_custom_singular_name( $item_id ) {
261
-    if( empty( $item_id ) ) {
260
+function wpinv_item_custom_singular_name($item_id) {
261
+    if (empty($item_id)) {
262 262
         return false;
263 263
     }
264 264
 
265
-    $item = new WPInv_Item( $item_id );
265
+    $item = new WPInv_Item($item_id);
266 266
     
267 267
     return $item->get_custom_singular_name();
268 268
 }
269 269
 
270 270
 function wpinv_get_item_types() {
271 271
     $item_types = array(
272
-            'custom'    => __( 'Standard', 'invoicing' ),
273
-            'fee'       => __( 'Fee', 'invoicing' ),
272
+            'custom'    => __('Standard', 'invoicing'),
273
+            'fee'       => __('Fee', 'invoicing'),
274 274
         );
275
-    return apply_filters( 'wpinv_get_item_types', $item_types );
275
+    return apply_filters('wpinv_get_item_types', $item_types);
276 276
 }
277 277
 
278 278
 function wpinv_item_types() {
279 279
     $item_types = wpinv_get_item_types();
280 280
     
281
-    return ( !empty( $item_types ) ? array_keys( $item_types ) : array() );
281
+    return (!empty($item_types) ? array_keys($item_types) : array());
282 282
 }
283 283
 
284
-function wpinv_get_item_type( $item_id ) {
285
-    if( empty( $item_id ) ) {
284
+function wpinv_get_item_type($item_id) {
285
+    if (empty($item_id)) {
286 286
         return false;
287 287
     }
288 288
 
289
-    $item = new WPInv_Item( $item_id );
289
+    $item = new WPInv_Item($item_id);
290 290
     
291 291
     return $item->get_type();
292 292
 }
293 293
 
294
-function wpinv_item_type( $item_id ) {
294
+function wpinv_item_type($item_id) {
295 295
     $item_types = wpinv_get_item_types();
296 296
     
297
-    $item_type = wpinv_get_item_type( $item_id );
297
+    $item_type = wpinv_get_item_type($item_id);
298 298
     
299
-    if ( empty( $item_type ) ) {
299
+    if (empty($item_type)) {
300 300
         $item_type = '-';
301 301
     }
302 302
     
303
-    $item_type = isset( $item_types[$item_type] ) ? $item_types[$item_type] : __( $item_type, 'invoicing' );
303
+    $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing');
304 304
 
305
-    return apply_filters( 'wpinv_item_type', $item_type, $item_id );
305
+    return apply_filters('wpinv_item_type', $item_type, $item_id);
306 306
 }
307 307
 
308
-function wpinv_record_item_in_log( $item_id = 0, $file_id, $user_info, $ip, $invoice_id ) {
308
+function wpinv_record_item_in_log($item_id = 0, $file_id, $user_info, $ip, $invoice_id) {
309 309
     global $wpinv_logs;
310 310
     
311
-    if ( empty( $wpinv_logs ) ) {
311
+    if (empty($wpinv_logs)) {
312 312
         return false;
313 313
     }
314 314
 
@@ -317,278 +317,278 @@  discard block
 block discarded – undo
317 317
         'log_type'		=> 'wpi_item'
318 318
     );
319 319
 
320
-    $user_id = isset( $user_info['user_id'] ) ? $user_info['user_id'] : (int) -1;
320
+    $user_id = isset($user_info['user_id']) ? $user_info['user_id'] : (int) -1;
321 321
 
322 322
     $log_meta = array(
323 323
         'user_info'	=> $user_info,
324 324
         'user_id'	=> $user_id,
325
-        'file_id'	=> (int)$file_id,
325
+        'file_id'	=> (int) $file_id,
326 326
         'ip'		=> $ip,
327 327
         'invoice_id'=> $invoice_id,
328 328
     );
329 329
 
330
-    $wpinv_logs->insert_log( $log_data, $log_meta );
330
+    $wpinv_logs->insert_log($log_data, $log_meta);
331 331
 }
332 332
 
333
-function wpinv_remove_item_logs_on_delete( $item_id = 0 ) {
334
-    if ( 'wpi_item' !== get_post_type( $item_id ) )
333
+function wpinv_remove_item_logs_on_delete($item_id = 0) {
334
+    if ('wpi_item' !== get_post_type($item_id))
335 335
         return;
336 336
 
337 337
     global $wpinv_logs;
338 338
     
339
-    if ( empty( $wpinv_logs ) ) {
339
+    if (empty($wpinv_logs)) {
340 340
         return false;
341 341
     }
342 342
 
343 343
     // Remove all log entries related to this item
344
-    $wpinv_logs->delete_logs( $item_id );
344
+    $wpinv_logs->delete_logs($item_id);
345 345
 }
346
-add_action( 'delete_post', 'wpinv_remove_item_logs_on_delete' );
346
+add_action('delete_post', 'wpinv_remove_item_logs_on_delete');
347 347
 
348
-function wpinv_get_random_item( $post_ids = true ) {
349
-    wpinv_get_random_items( 1, $post_ids );
348
+function wpinv_get_random_item($post_ids = true) {
349
+    wpinv_get_random_items(1, $post_ids);
350 350
 }
351 351
 
352
-function wpinv_get_random_items( $num = 3, $post_ids = true ) {
353
-    if ( $post_ids ) {
354
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids' );
352
+function wpinv_get_random_items($num = 3, $post_ids = true) {
353
+    if ($post_ids) {
354
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids');
355 355
     } else {
356
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num );
356
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num);
357 357
     }
358 358
     
359
-    $args  = apply_filters( 'wpinv_get_random_items', $args );
359
+    $args = apply_filters('wpinv_get_random_items', $args);
360 360
     
361
-    return get_posts( $args );
361
+    return get_posts($args);
362 362
 }
363 363
 
364
-function wpinv_get_item_token( $url = '' ) {
364
+function wpinv_get_item_token($url = '') {
365 365
     $args    = array();
366
-    $hash    = apply_filters( 'wpinv_get_url_token_algorithm', 'sha256' );
367
-    $secret  = apply_filters( 'wpinv_get_url_token_secret', hash( $hash, wp_salt() ) );
366
+    $hash    = apply_filters('wpinv_get_url_token_algorithm', 'sha256');
367
+    $secret  = apply_filters('wpinv_get_url_token_secret', hash($hash, wp_salt()));
368 368
 
369
-    $parts   = parse_url( $url );
369
+    $parts   = parse_url($url);
370 370
     $options = array();
371 371
 
372
-    if ( isset( $parts['query'] ) ) {
373
-        wp_parse_str( $parts['query'], $query_args );
372
+    if (isset($parts['query'])) {
373
+        wp_parse_str($parts['query'], $query_args);
374 374
 
375
-        if ( ! empty( $query_args['o'] ) ) {
376
-            $options = explode( ':', rawurldecode( $query_args['o'] ) );
375
+        if (!empty($query_args['o'])) {
376
+            $options = explode(':', rawurldecode($query_args['o']));
377 377
 
378
-            if ( in_array( 'ip', $options ) ) {
378
+            if (in_array('ip', $options)) {
379 379
                 $args['ip'] = wpinv_get_ip();
380 380
             }
381 381
 
382
-            if ( in_array( 'ua', $options ) ) {
382
+            if (in_array('ua', $options)) {
383 383
                 $ua = wpinv_get_user_agent();
384
-                $args['user_agent'] = rawurlencode( $ua );
384
+                $args['user_agent'] = rawurlencode($ua);
385 385
             }
386 386
         }
387 387
     }
388 388
 
389
-    $args = apply_filters( 'wpinv_get_url_token_args', $args, $url, $options );
389
+    $args = apply_filters('wpinv_get_url_token_args', $args, $url, $options);
390 390
 
391 391
     $args['secret'] = $secret;
392 392
     $args['token']  = false;
393 393
 
394
-    $url   = add_query_arg( $args, $url );
395
-    $parts = parse_url( $url );
394
+    $url   = add_query_arg($args, $url);
395
+    $parts = parse_url($url);
396 396
 
397
-    if ( ! isset( $parts['path'] ) ) {
397
+    if (!isset($parts['path'])) {
398 398
         $parts['path'] = '';
399 399
     }
400 400
 
401
-    $token = md5( $parts['path'] . '?' . $parts['query'] );
401
+    $token = md5($parts['path'] . '?' . $parts['query']);
402 402
 
403 403
     return $token;
404 404
 }
405 405
 
406
-function wpinv_validate_url_token( $url = '' ) {
406
+function wpinv_validate_url_token($url = '') {
407 407
     $ret   = false;
408
-    $parts = parse_url( $url );
408
+    $parts = parse_url($url);
409 409
 
410
-    if ( isset( $parts['query'] ) ) {
411
-        wp_parse_str( $parts['query'], $query_args );
410
+    if (isset($parts['query'])) {
411
+        wp_parse_str($parts['query'], $query_args);
412 412
 
413
-        $allowed = apply_filters( 'wpinv_url_token_allowed_params', array(
413
+        $allowed = apply_filters('wpinv_url_token_allowed_params', array(
414 414
             'item',
415 415
             'ttl',
416 416
             'token'
417
-        ) );
417
+        ));
418 418
 
419 419
         $remove = array();
420 420
 
421
-        foreach( $query_args as $key => $value ) {
422
-            if( false === in_array( $key, $allowed ) ) {
421
+        foreach ($query_args as $key => $value) {
422
+            if (false === in_array($key, $allowed)) {
423 423
                 $remove[] = $key;
424 424
             }
425 425
         }
426 426
 
427
-        if( ! empty( $remove ) ) {
428
-            $url = remove_query_arg( $remove, $url );
427
+        if (!empty($remove)) {
428
+            $url = remove_query_arg($remove, $url);
429 429
         }
430 430
 
431
-        if ( isset( $query_args['ttl'] ) && current_time( 'timestamp' ) > $query_args['ttl'] ) {
432
-            wp_die( apply_filters( 'wpinv_item_link_expired_text', __( 'Sorry but your item link has expired.', 'invoicing' ) ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
431
+        if (isset($query_args['ttl']) && current_time('timestamp') > $query_args['ttl']) {
432
+            wp_die(apply_filters('wpinv_item_link_expired_text', __('Sorry but your item link has expired.', 'invoicing')), __('Error', 'invoicing'), array('response' => 403));
433 433
         }
434 434
 
435
-        if ( isset( $query_args['token'] ) && $query_args['token'] == wpinv_get_item_token( $url ) ) {
435
+        if (isset($query_args['token']) && $query_args['token'] == wpinv_get_item_token($url)) {
436 436
             $ret = true;
437 437
         }
438 438
 
439 439
     }
440 440
 
441
-    return apply_filters( 'wpinv_validate_url_token', $ret, $url, $query_args );
441
+    return apply_filters('wpinv_validate_url_token', $ret, $url, $query_args);
442 442
 }
443 443
 
444
-function wpinv_item_in_cart( $item_id = 0, $options = array() ) {
444
+function wpinv_item_in_cart($item_id = 0, $options = array()) {
445 445
     $cart_items = wpinv_get_cart_contents();
446 446
 
447 447
     $ret = false;
448 448
 
449
-    if ( is_array( $cart_items ) ) {
450
-        foreach ( $cart_items as $item ) {
451
-            if ( $item['id'] == $item_id ) {
449
+    if (is_array($cart_items)) {
450
+        foreach ($cart_items as $item) {
451
+            if ($item['id'] == $item_id) {
452 452
                 $ret = true;
453 453
                 break;
454 454
             }
455 455
         }
456 456
     }
457 457
 
458
-    return (bool) apply_filters( 'wpinv_item_in_cart', $ret, $item_id, $options );
458
+    return (bool) apply_filters('wpinv_item_in_cart', $ret, $item_id, $options);
459 459
 }
460 460
 
461
-function wpinv_get_cart_item_tax( $item_id = 0, $subtotal = '', $options = array() ) {
461
+function wpinv_get_cart_item_tax($item_id = 0, $subtotal = '', $options = array()) {
462 462
     $tax = 0;
463
-    if ( ! wpinv_item_is_tax_exclusive( $item_id ) ) {
464
-        $country = !empty( $_POST['country'] ) ? $_POST['country'] : false;
465
-        $state   = isset( $_POST['state'] ) ? $_POST['state'] : '';
463
+    if (!wpinv_item_is_tax_exclusive($item_id)) {
464
+        $country = !empty($_POST['country']) ? $_POST['country'] : false;
465
+        $state   = isset($_POST['state']) ? $_POST['state'] : '';
466 466
 
467
-        $tax = wpinv_calculate_tax( $subtotal, $country, $state, $item_id );
467
+        $tax = wpinv_calculate_tax($subtotal, $country, $state, $item_id);
468 468
     }
469 469
 
470
-    return apply_filters( 'wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options );
470
+    return apply_filters('wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options);
471 471
 }
472 472
 
473
-function wpinv_cart_item_price( $item, $currency = '' ) {
473
+function wpinv_cart_item_price($item, $currency = '') {
474 474
 
475
-    if( empty( $currency ) ) {
475
+    if (empty($currency)) {
476 476
         $currency = wpinv_get_currency();
477 477
     }
478 478
 
479
-    $item_id    = isset( $item['id'] ) ? $item['id'] : 0;
480
-    $price      = isset( $item['item_price'] ) ? wpinv_round_amount( $item['item_price'] ) : 0;
481
-    $tax        = wpinv_price( wpinv_format_amount( $item['tax'] ) );
479
+    $item_id    = isset($item['id']) ? $item['id'] : 0;
480
+    $price      = isset($item['item_price']) ? wpinv_round_amount($item['item_price']) : 0;
481
+    $tax        = wpinv_price(wpinv_format_amount($item['tax']));
482 482
     
483
-    if ( !wpinv_is_free_item( $item_id ) && !wpinv_item_is_tax_exclusive( $item_id ) ) {
484
-        if ( wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax() ) {
483
+    if (!wpinv_is_free_item($item_id) && !wpinv_item_is_tax_exclusive($item_id)) {
484
+        if (wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax()) {
485 485
             $price += $tax;
486 486
         }
487 487
         
488
-        if( !wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax() ) {
488
+        if (!wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax()) {
489 489
             $price -= $tax;
490 490
         }        
491 491
     }
492 492
 
493
-    $price = wpinv_price( wpinv_format_amount( $price ), $currency );
493
+    $price = wpinv_price(wpinv_format_amount($price), $currency);
494 494
 
495
-    return apply_filters( 'wpinv_cart_item_price_label', $price, $item );
495
+    return apply_filters('wpinv_cart_item_price_label', $price, $item);
496 496
 }
497 497
 
498
-function wpinv_cart_item_subtotal( $item, $currency = '' ) {
498
+function wpinv_cart_item_subtotal($item, $currency = '') {
499 499
 
500
-    if( empty( $currency ) ) {
500
+    if (empty($currency)) {
501 501
         $currency = wpinv_get_currency();
502 502
     }
503 503
 
504
-    $subtotal   = isset( $item['subtotal'] ) ? $item['subtotal'] : 0;
505
-    $subtotal   = wpinv_price( wpinv_format_amount( $subtotal ), $currency );
504
+    $subtotal   = isset($item['subtotal']) ? $item['subtotal'] : 0;
505
+    $subtotal   = wpinv_price(wpinv_format_amount($subtotal), $currency);
506 506
 
507
-    return apply_filters( 'wpinv_cart_item_subtotal_label', $subtotal, $item );
507
+    return apply_filters('wpinv_cart_item_subtotal_label', $subtotal, $item);
508 508
 }
509 509
 
510
-function wpinv_cart_item_tax( $item, $currency = '' ) {
510
+function wpinv_cart_item_tax($item, $currency = '') {
511 511
     $tax        = '';
512 512
     $tax_rate   = '';
513 513
 
514
-    if( empty( $currency ) ) {
514
+    if (empty($currency)) {
515 515
         $currency = wpinv_get_currency();
516 516
     }
517 517
     
518
-    if ( isset( $item['tax'] ) && $item['tax'] > 0 && $item['subtotal'] > 0 ) {
519
-        $tax      = wpinv_price( wpinv_format_amount( $item['tax'] ), $currency );
520
-        $tax_rate = !empty( $item['vat_rate'] ) ? $item['vat_rate'] : ( $item['tax'] / $item['subtotal'] ) * 100;
521
-        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
518
+    if (isset($item['tax']) && $item['tax'] > 0 && $item['subtotal'] > 0) {
519
+        $tax      = wpinv_price(wpinv_format_amount($item['tax']), $currency);
520
+        $tax_rate = !empty($item['vat_rate']) ? $item['vat_rate'] : ($item['tax'] / $item['subtotal']) * 100;
521
+        $tax_rate = $tax_rate > 0 ? (float) wpinv_round_amount($tax_rate, 4) : '';
522 522
         $tax_rate = $tax_rate != '' ? ' <small class="tax-rate normal small">(' . $tax_rate . '%)</small>' : '';
523 523
     }
524 524
     
525
-    $tax        = $tax . $tax_rate;
525
+    $tax = $tax . $tax_rate;
526 526
     
527
-    if ( $tax === '' ) {
527
+    if ($tax === '') {
528 528
         $tax = 0; // Zero tax
529 529
     }
530 530
 
531
-    return apply_filters( 'wpinv_cart_item_tax_label', $tax, $item );
531
+    return apply_filters('wpinv_cart_item_tax_label', $tax, $item);
532 532
 }
533 533
 
534
-function wpinv_get_cart_item_price( $item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false ) {
534
+function wpinv_get_cart_item_price($item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false) {
535 535
     $price = 0;
536 536
     
537 537
     // Set custom price
538
-    if ( isset( $cart_item['custom_price'] ) && $cart_item['custom_price'] !== '' ) {
538
+    if (isset($cart_item['custom_price']) && $cart_item['custom_price'] !== '') {
539 539
         $price = $cart_item['custom_price'];
540 540
     } else {
541
-        $variable_prices = wpinv_has_variable_prices( $item_id );
541
+        $variable_prices = wpinv_has_variable_prices($item_id);
542 542
 
543
-        if ( $variable_prices ) {
544
-            $prices = wpinv_get_variable_prices( $item_id );
543
+        if ($variable_prices) {
544
+            $prices = wpinv_get_variable_prices($item_id);
545 545
 
546
-            if ( $prices ) {
547
-                if( ! empty( $options ) ) {
548
-                    $price = isset( $prices[ $options['price_id'] ] ) ? $prices[ $options['price_id'] ]['amount'] : false;
546
+            if ($prices) {
547
+                if (!empty($options)) {
548
+                    $price = isset($prices[$options['price_id']]) ? $prices[$options['price_id']]['amount'] : false;
549 549
                 } else {
550 550
                     $price = false;
551 551
                 }
552 552
             }
553 553
         }
554 554
 
555
-        if( ! $variable_prices || false === $price ) {
556
-            if($cart_item['item_price'] > 0){
555
+        if (!$variable_prices || false === $price) {
556
+            if ($cart_item['item_price'] > 0) {
557 557
                 $price = $cart_item['item_price'];
558 558
             } else {
559 559
                 // Get the standard Item price if not using variable prices
560
-                $price = wpinv_get_item_price( $item_id );
560
+                $price = wpinv_get_item_price($item_id);
561 561
             }
562 562
         }
563 563
     }
564 564
 
565
-    if ( $remove_tax_from_inclusive && wpinv_prices_include_tax() ) {
566
-        $price -= wpinv_get_cart_item_tax( $item_id, $price, $options );
565
+    if ($remove_tax_from_inclusive && wpinv_prices_include_tax()) {
566
+        $price -= wpinv_get_cart_item_tax($item_id, $price, $options);
567 567
     }
568 568
 
569
-    return apply_filters( 'wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive );
569
+    return apply_filters('wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive);
570 570
 }
571 571
 
572
-function wpinv_get_cart_item_price_id( $item = array() ) {
573
-    if( isset( $item['item_number'] ) ) {
574
-        $price_id = isset( $item['item_number']['options']['price_id'] ) ? $item['item_number']['options']['price_id'] : null;
572
+function wpinv_get_cart_item_price_id($item = array()) {
573
+    if (isset($item['item_number'])) {
574
+        $price_id = isset($item['item_number']['options']['price_id']) ? $item['item_number']['options']['price_id'] : null;
575 575
     } else {
576
-        $price_id = isset( $item['options']['price_id'] ) ? $item['options']['price_id'] : null;
576
+        $price_id = isset($item['options']['price_id']) ? $item['options']['price_id'] : null;
577 577
     }
578 578
     return $price_id;
579 579
 }
580 580
 
581
-function wpinv_get_cart_item_price_name( $item = array() ) {
582
-    $price_id = (int)wpinv_get_cart_item_price_id( $item );
583
-    $prices   = wpinv_get_variable_prices( $item['id'] );
584
-    $name     = ! empty( $prices[ $price_id ] ) ? $prices[ $price_id ]['name'] : '';
585
-    return apply_filters( 'wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item );
581
+function wpinv_get_cart_item_price_name($item = array()) {
582
+    $price_id = (int) wpinv_get_cart_item_price_id($item);
583
+    $prices   = wpinv_get_variable_prices($item['id']);
584
+    $name     = !empty($prices[$price_id]) ? $prices[$price_id]['name'] : '';
585
+    return apply_filters('wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item);
586 586
 }
587 587
 
588
-function wpinv_get_cart_item_name( $item = array() ) {
589
-    $item_title = !empty( $item['name'] ) ? $item['name'] : get_the_title( $item['id'] );
588
+function wpinv_get_cart_item_name($item = array()) {
589
+    $item_title = !empty($item['name']) ? $item['name'] : get_the_title($item['id']);
590 590
 
591
-    if ( empty( $item_title ) ) {
591
+    if (empty($item_title)) {
592 592
         $item_title = $item['id'];
593 593
     }
594 594
 
@@ -598,23 +598,23 @@  discard block
 block discarded – undo
598 598
     }
599 599
     */
600 600
 
601
-    return apply_filters( 'wpinv_get_cart_item_name', $item_title, $item['id'], $item );
601
+    return apply_filters('wpinv_get_cart_item_name', $item_title, $item['id'], $item);
602 602
 }
603 603
 
604
-function wpinv_has_variable_prices( $item_id = 0 ) {
604
+function wpinv_has_variable_prices($item_id = 0) {
605 605
     return false;
606 606
 }
607 607
 
608
-function wpinv_get_item_position_in_cart( $item_id = 0, $options = array() ) {
608
+function wpinv_get_item_position_in_cart($item_id = 0, $options = array()) {
609 609
     $cart_items = wpinv_get_cart_contents();
610 610
 
611
-    if ( !is_array( $cart_items ) ) {
611
+    if (!is_array($cart_items)) {
612 612
         return false; // Empty cart
613 613
     } else {
614
-        foreach ( $cart_items as $position => $item ) {
615
-            if ( $item['id'] == $item_id ) {
616
-                if ( isset( $options['price_id'] ) && isset( $item['options']['price_id'] ) ) {
617
-                    if ( (int) $options['price_id'] == (int) $item['options']['price_id'] ) {
614
+        foreach ($cart_items as $position => $item) {
615
+            if ($item['id'] == $item_id) {
616
+                if (isset($options['price_id']) && isset($item['options']['price_id'])) {
617
+                    if ((int) $options['price_id'] == (int) $item['options']['price_id']) {
618 618
                         return $position;
619 619
                     }
620 620
                 } else {
@@ -627,80 +627,80 @@  discard block
 block discarded – undo
627 627
     return false; // Not found
628 628
 }
629 629
 
630
-function wpinv_get_cart_item_quantity( $item ) {
631
-    if ( wpinv_item_quantities_enabled() ) {
632
-        $quantity = !empty( $item['quantity'] ) && (int)$item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
630
+function wpinv_get_cart_item_quantity($item) {
631
+    if (wpinv_item_quantities_enabled()) {
632
+        $quantity = !empty($item['quantity']) && (int) $item['quantity'] > 0 ? absint($item['quantity']) : 1;
633 633
     } else {
634 634
         $quantity = 1;
635 635
     }
636 636
     
637
-    if ( $quantity < 1 ) {
637
+    if ($quantity < 1) {
638 638
         $quantity = 1;
639 639
     }
640 640
     
641
-    return apply_filters( 'wpinv_get_cart_item_quantity', $quantity, $item );
641
+    return apply_filters('wpinv_get_cart_item_quantity', $quantity, $item);
642 642
 }
643 643
 
644
-function wpinv_get_item_suffix( $item, $html = true ) {
645
-    if ( empty( $item ) ) {
644
+function wpinv_get_item_suffix($item, $html = true) {
645
+    if (empty($item)) {
646 646
         return NULL;
647 647
     }
648 648
     
649
-    if ( is_int( $item ) ) {
650
-        $item = new WPInv_Item( $item );
649
+    if (is_int($item)) {
650
+        $item = new WPInv_Item($item);
651 651
     }
652 652
     
653
-    if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) {
653
+    if (!(is_object($item) && is_a($item, 'WPInv_Item'))) {
654 654
         return NULL;
655 655
     }
656 656
     
657
-    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '';
657
+    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : '';
658 658
     
659
-    if ( !$html && $suffix ) {
660
-        $suffix = strip_tags( $suffix );
659
+    if (!$html && $suffix) {
660
+        $suffix = strip_tags($suffix);
661 661
     }
662 662
     
663
-    return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html );
663
+    return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html);
664 664
 }
665 665
 
666
-function wpinv_remove_item( $item = 0, $force_delete = false ) {
667
-    if ( empty( $item ) ) {
666
+function wpinv_remove_item($item = 0, $force_delete = false) {
667
+    if (empty($item)) {
668 668
         return NULL;
669 669
     }
670 670
     
671
-    if ( is_int( $item ) ) {
672
-        $item = new WPInv_Item( $item );
671
+    if (is_int($item)) {
672
+        $item = new WPInv_Item($item);
673 673
     }
674 674
     
675
-    if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) {
675
+    if (!(is_object($item) && is_a($item, 'WPInv_Item'))) {
676 676
         return NULL;
677 677
     }
678 678
     
679
-    do_action( 'wpinv_pre_delete_item', $item );
679
+    do_action('wpinv_pre_delete_item', $item);
680 680
 
681
-    wp_delete_post( $item->ID, $force_delete );
681
+    wp_delete_post($item->ID, $force_delete);
682 682
 
683
-    do_action( 'wpinv_post_delete_item', $item );
683
+    do_action('wpinv_post_delete_item', $item);
684 684
 }
685 685
 
686
-function wpinv_can_delete_item( $post_id ) {
686
+function wpinv_can_delete_item($post_id) {
687 687
     $return = wpinv_current_user_can_manage_invoicing() ? true : false;
688 688
     
689
-    if ( $return && wpinv_item_in_use( $post_id ) ) {
689
+    if ($return && wpinv_item_in_use($post_id)) {
690 690
         $return = false; // Don't delete item already use in invoices.
691 691
     }
692 692
     
693
-    return apply_filters( 'wpinv_can_delete_item', $return, $post_id );
693
+    return apply_filters('wpinv_can_delete_item', $return, $post_id);
694 694
 }
695 695
 
696 696
 function wpinv_admin_action_delete() {
697 697
     $screen = get_current_screen();
698 698
     
699
-    if ( !empty( $screen->post_type ) && $screen->post_type == 'wpi_item' && !empty( $_REQUEST['post'] ) && is_array( $_REQUEST['post'] ) ) {
699
+    if (!empty($screen->post_type) && $screen->post_type == 'wpi_item' && !empty($_REQUEST['post']) && is_array($_REQUEST['post'])) {
700 700
         $post_ids = array();
701 701
         
702
-        foreach ( $_REQUEST['post'] as $post_id ) {
703
-            if ( !wpinv_can_delete_item( $post_id ) ) {
702
+        foreach ($_REQUEST['post'] as $post_id) {
703
+            if (!wpinv_can_delete_item($post_id)) {
704 704
                 continue;
705 705
             }
706 706
             
@@ -710,88 +710,88 @@  discard block
 block discarded – undo
710 710
         $_REQUEST['post'] = $post_ids;
711 711
     }
712 712
 }
713
-add_action( 'admin_action_trash', 'wpinv_admin_action_delete', -10 );
714
-add_action( 'admin_action_delete', 'wpinv_admin_action_delete', -10 );
713
+add_action('admin_action_trash', 'wpinv_admin_action_delete', -10);
714
+add_action('admin_action_delete', 'wpinv_admin_action_delete', -10);
715 715
 
716
-function wpinv_check_delete_item( $check, $post, $force_delete ) {
717
-    if ( $post->post_type == 'wpi_item' ) {
718
-        if ( $force_delete && !wpinv_can_delete_item( $post->ID ) ) {
716
+function wpinv_check_delete_item($check, $post, $force_delete) {
717
+    if ($post->post_type == 'wpi_item') {
718
+        if ($force_delete && !wpinv_can_delete_item($post->ID)) {
719 719
             return true;
720 720
         }
721 721
     }
722 722
     
723 723
     return $check;
724 724
 }
725
-add_filter( 'pre_delete_post', 'wpinv_check_delete_item', 10, 3 );
725
+add_filter('pre_delete_post', 'wpinv_check_delete_item', 10, 3);
726 726
 
727
-function wpinv_item_in_use( $item_id ) {
727
+function wpinv_item_in_use($item_id) {
728 728
     global $wpdb, $wpi_items_in_use;
729 729
     
730
-    if ( !$item_id > 0 ) {
730
+    if (!$item_id > 0) {
731 731
         return false;
732 732
     }
733 733
     
734
-    if ( !empty( $wpi_items_in_use ) ) {
735
-        if ( isset( $wpi_items_in_use[$item_id] ) ) {
734
+    if (!empty($wpi_items_in_use)) {
735
+        if (isset($wpi_items_in_use[$item_id])) {
736 736
             return $wpi_items_in_use[$item_id];
737 737
         }
738 738
     } else {
739 739
         $wpi_items_in_use = array();
740 740
     }
741 741
     
742
-    $statuses   = array_keys( wpinv_get_invoice_statuses( true, true ) );
742
+    $statuses = array_keys(wpinv_get_invoice_statuses(true, true));
743 743
     
744
-    $query  = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode( "','", $statuses ) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )";
745
-    $in_use = $wpdb->get_var( $query ) > 0 ? true : false;
744
+    $query  = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode("','", $statuses) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int) $item_id . "', pm.meta_value )";
745
+    $in_use = $wpdb->get_var($query) > 0 ? true : false;
746 746
     
747 747
     $wpi_items_in_use[$item_id] = $in_use;
748 748
     
749 749
     return $in_use;
750 750
 }
751 751
 
752
-function wpinv_create_item( $args = array(), $wp_error = false, $force_update = false ) {
752
+function wpinv_create_item($args = array(), $wp_error = false, $force_update = false) {
753 753
     // Set some defaults
754 754
     $defaults = array(
755
-        'type'                 => 'custom',                                                // Optional. Item type. Default 'custom'.
756
-        'title'                => '',                                                      // Required. Item title.
757
-        'custom_id'            => 0,                                                       // Optional. Any integer or non numeric id. Must be unique within item type.
758
-        'price'                => '0.00',                                                  // Optional. Item price. Default '0.00'.
759
-        'status'               => 'pending',                                               // Optional. pending, publish
760
-        'custom_name'          => '',                                                      // Optional. Plural sub title for item.
761
-        'custom_singular_name' => '',                                                      // Optional. Singular sub title for item.
762
-        'vat_rule'             => 'digital',                                               // Optional. digital => Digital item, physical => Physical item
763
-        'editable'             => true,                                                    // Optional. Item editable from Items list page? Default true.
764
-        'excerpt'              => '',                                                      // Optional. Item short description
755
+        'type'                 => 'custom', // Optional. Item type. Default 'custom'.
756
+        'title'                => '', // Required. Item title.
757
+        'custom_id'            => 0, // Optional. Any integer or non numeric id. Must be unique within item type.
758
+        'price'                => '0.00', // Optional. Item price. Default '0.00'.
759
+        'status'               => 'pending', // Optional. pending, publish
760
+        'custom_name'          => '', // Optional. Plural sub title for item.
761
+        'custom_singular_name' => '', // Optional. Singular sub title for item.
762
+        'vat_rule'             => 'digital', // Optional. digital => Digital item, physical => Physical item
763
+        'editable'             => true, // Optional. Item editable from Items list page? Default true.
764
+        'excerpt'              => '', // Optional. Item short description
765 765
         /* Recurring item fields */
766
-        'is_recurring'         => 0,                                                       // Optional. 1 => Allow recurring or 0 => Don't allow recurring
767
-        'recurring_period'     => 'M',                                                     // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
768
-        'recurring_interval'   => 0,                                                       // Optional. Integer value between 1 - 90.
769
-        'recurring_limit'      => 0,                                                       // Optional. Any integer number. 0 for recurring forever until cancelled.
770
-        'free_trial'           => 0,                                                       // Optional. 1 => Allow free trial or 0 => Don't free trial
771
-        'trial_period'         => 'M',                                                     // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
772
-        'trial_interval'       => 0,                                                       // Optional. Any integer number.
773
-        'minimum_price'        => '0.00',                                                  // Optional. Minimum allowed prices for items with dynamic pricing.
774
-        'dynamic_pricing'      => 0,                                                       // Optional. Whether or not the item supports dynamic prices.
766
+        'is_recurring'         => 0, // Optional. 1 => Allow recurring or 0 => Don't allow recurring
767
+        'recurring_period'     => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
768
+        'recurring_interval'   => 0, // Optional. Integer value between 1 - 90.
769
+        'recurring_limit'      => 0, // Optional. Any integer number. 0 for recurring forever until cancelled.
770
+        'free_trial'           => 0, // Optional. 1 => Allow free trial or 0 => Don't free trial
771
+        'trial_period'         => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
772
+        'trial_interval'       => 0, // Optional. Any integer number.
773
+        'minimum_price'        => '0.00', // Optional. Minimum allowed prices for items with dynamic pricing.
774
+        'dynamic_pricing'      => 0, // Optional. Whether or not the item supports dynamic prices.
775 775
     );
776 776
 
777
-    $data = wp_parse_args( $args, $defaults );
777
+    $data = wp_parse_args($args, $defaults);
778 778
 
779
-    if ( empty( $data['type'] ) ) {
779
+    if (empty($data['type'])) {
780 780
         $data['type'] = 'custom';
781 781
     }
782 782
 
783
-    if ( !empty( $data['custom_id'] ) ) {
784
-        $item = wpinv_get_item_by( 'custom_id', $data['custom_id'], $data['type'] );
783
+    if (!empty($data['custom_id'])) {
784
+        $item = wpinv_get_item_by('custom_id', $data['custom_id'], $data['type']);
785 785
     } else {
786 786
         $item = NULL;
787 787
     }
788 788
 
789
-    if ( !empty( $item ) ) {
790
-        if ( $force_update ) {
791
-            if ( empty( $args['ID'] ) ) {
789
+    if (!empty($item)) {
790
+        if ($force_update) {
791
+            if (empty($args['ID'])) {
792 792
                 $args['ID'] = $item->ID;
793 793
             }
794
-            return wpinv_update_item( $args, $wp_error );
794
+            return wpinv_update_item($args, $wp_error);
795 795
         }
796 796
 
797 797
         return $item;
@@ -802,21 +802,21 @@  discard block
 block discarded – undo
802 802
     $meta['custom_id']              = $data['custom_id'];
803 803
     $meta['custom_singular_name']   = $data['custom_singular_name'];
804 804
     $meta['custom_name']            = $data['custom_name'];
805
-    $meta['price']                  = wpinv_round_amount( $data['price'] );
806
-    $meta['editable']               = (int)$data['editable'];
805
+    $meta['price']                  = wpinv_round_amount($data['price']);
806
+    $meta['editable']               = (int) $data['editable'];
807 807
     $meta['vat_rule']               = $data['vat_rule'];
808 808
     $meta['vat_class']              = '_standard';
809 809
     $meta['dynamic_pricing']        = (int) $data['dynamic_pricing'];
810
-    $meta['minimum_price']          = wpinv_round_amount( $data['minimum_price'] );
810
+    $meta['minimum_price']          = wpinv_round_amount($data['minimum_price']);
811 811
     
812
-    if ( !empty( $data['is_recurring'] ) ) {
812
+    if (!empty($data['is_recurring'])) {
813 813
         $meta['is_recurring']       = $data['is_recurring'];
814 814
         $meta['recurring_period']   = $data['recurring_period'];
815
-        $meta['recurring_interval'] = absint( $data['recurring_interval'] );
816
-        $meta['recurring_limit']    = absint( $data['recurring_limit'] );
815
+        $meta['recurring_interval'] = absint($data['recurring_interval']);
816
+        $meta['recurring_limit']    = absint($data['recurring_limit']);
817 817
         $meta['free_trial']         = $data['free_trial'];
818 818
         $meta['trial_period']       = $data['trial_period'];
819
-        $meta['trial_interval']     = absint( $data['trial_interval'] );
819
+        $meta['trial_interval']     = absint($data['trial_interval']);
820 820
     } else {
821 821
         $meta['is_recurring']       = 0;
822 822
         $meta['recurring_period']   = '';
@@ -827,7 +827,7 @@  discard block
 block discarded – undo
827 827
         $meta['trial_interval']     = '';
828 828
     }
829 829
     
830
-    $post_data  = array( 
830
+    $post_data = array( 
831 831
         'post_title'    => $data['title'],
832 832
         'post_excerpt'  => $data['excerpt'],
833 833
         'post_status'   => $data['status'],
@@ -835,34 +835,34 @@  discard block
 block discarded – undo
835 835
     );
836 836
 
837 837
     $item = new WPInv_Item();
838
-    $return = $item->create( $post_data, $wp_error );
838
+    $return = $item->create($post_data, $wp_error);
839 839
 
840
-    if ( $return && !empty( $item ) && !is_wp_error( $return ) ) {
840
+    if ($return && !empty($item) && !is_wp_error($return)) {
841 841
         return $item;
842 842
     }
843 843
 
844
-    if ( $wp_error && is_wp_error( $return ) ) {
844
+    if ($wp_error && is_wp_error($return)) {
845 845
         return $return;
846 846
     }
847 847
     return 0;
848 848
 }
849 849
 
850
-function wpinv_update_item( $args = array(), $wp_error = false ) {
851
-    $item = !empty( $args['ID'] ) ? new WPInv_Item( $args['ID'] ) : NULL;
850
+function wpinv_update_item($args = array(), $wp_error = false) {
851
+    $item = !empty($args['ID']) ? new WPInv_Item($args['ID']) : NULL;
852 852
 
853
-    if ( empty( $item ) || !( !empty( $item->post_type ) && $item->post_type == 'wpi_item' ) ) {
854
-        if ( $wp_error ) {
855
-            return new WP_Error( 'wpinv_invalid_item', __( 'Invalid item.', 'invoicing' ) );
853
+    if (empty($item) || !(!empty($item->post_type) && $item->post_type == 'wpi_item')) {
854
+        if ($wp_error) {
855
+            return new WP_Error('wpinv_invalid_item', __('Invalid item.', 'invoicing'));
856 856
         }
857 857
         return 0;
858 858
     }
859 859
     
860
-    if ( !empty( $args['custom_id'] ) ) {
861
-        $item_exists = wpinv_get_item_by( 'custom_id', $args['custom_id'], ( !empty( $args['type'] ) ? $args['type'] : $item->type ) );
860
+    if (!empty($args['custom_id'])) {
861
+        $item_exists = wpinv_get_item_by('custom_id', $args['custom_id'], (!empty($args['type']) ? $args['type'] : $item->type));
862 862
         
863
-        if ( !empty( $item_exists ) && $item_exists->ID != $args['ID'] ) {
864
-            if ( $wp_error ) {
865
-                return new WP_Error( 'wpinv_invalid_custom_id', __( 'Item with custom id already exists.', 'invoicing' ) );
863
+        if (!empty($item_exists) && $item_exists->ID != $args['ID']) {
864
+            if ($wp_error) {
865
+                return new WP_Error('wpinv_invalid_custom_id', __('Item with custom id already exists.', 'invoicing'));
866 866
             }
867 867
             return 0;
868 868
         }
@@ -889,54 +889,54 @@  discard block
 block discarded – undo
889 889
     );
890 890
 
891 891
     $post_data = array();
892
-    if ( isset( $args['title'] ) ) { 
892
+    if (isset($args['title'])) { 
893 893
         $post_data['post_title'] = $args['title'];
894 894
     }
895
-    if ( isset( $args['excerpt'] ) ) { 
895
+    if (isset($args['excerpt'])) { 
896 896
         $post_data['post_excerpt'] = $args['excerpt'];
897 897
     }
898
-    if ( isset( $args['status'] ) ) { 
898
+    if (isset($args['status'])) { 
899 899
         $post_data['post_status'] = $args['status'];
900 900
     }
901 901
     
902
-    foreach ( $meta_fields as $meta_field ) {
903
-        if ( isset( $args[ $meta_field ] ) ) { 
904
-            $value = $args[ $meta_field ];
902
+    foreach ($meta_fields as $meta_field) {
903
+        if (isset($args[$meta_field])) { 
904
+            $value = $args[$meta_field];
905 905
 
906
-            switch ( $meta_field ) {
906
+            switch ($meta_field) {
907 907
                 case 'price':
908 908
                 case 'minimum_price':
909
-                    $value = wpinv_round_amount( $value );
909
+                    $value = wpinv_round_amount($value);
910 910
                 break;
911 911
                 case 'recurring_interval':
912 912
                 case 'recurring_limit':
913 913
                 case 'trial_interval':
914
-                    $value = absint( $value );
914
+                    $value = absint($value);
915 915
                 break;
916 916
 				case 'editable':
917 917
                     $value = (int) $value;
918 918
                 break;
919 919
             }
920 920
 
921
-            $post_data['meta'][ $meta_field ] = $value;
921
+            $post_data['meta'][$meta_field] = $value;
922 922
         };
923 923
     }
924 924
 
925
-    if ( empty( $post_data ) ) {
926
-        if ( $wp_error ) {
927
-            return new WP_Error( 'wpinv_invalid_item_data', __( 'Invalid item data.', 'invoicing' ) );
925
+    if (empty($post_data)) {
926
+        if ($wp_error) {
927
+            return new WP_Error('wpinv_invalid_item_data', __('Invalid item data.', 'invoicing'));
928 928
         }
929 929
         return 0;
930 930
     }
931 931
     $post_data['ID'] = $args['ID'];
932 932
 
933
-    $return = $item->update( $post_data, $wp_error );
933
+    $return = $item->update($post_data, $wp_error);
934 934
 
935
-    if ( $return && !empty( $item ) && !is_wp_error( $return ) ) {
935
+    if ($return && !empty($item) && !is_wp_error($return)) {
936 936
         return $item;
937 937
     }
938 938
 
939
-    if ( $wp_error && is_wp_error( $return ) ) {
939
+    if ($wp_error && is_wp_error($return)) {
940 940
         return $return;
941 941
     }
942 942
     return 0;
@@ -945,7 +945,7 @@  discard block
 block discarded – undo
945 945
 /**
946 946
  * Sanitizes a recurring period
947 947
  */
948
-function getpaid_sanitize_recurring_period( $period, $full = false ) {
948
+function getpaid_sanitize_recurring_period($period, $full = false) {
949 949
 
950 950
     $periods = array(
951 951
         'D' => 'day',
@@ -954,10 +954,10 @@  discard block
 block discarded – undo
954 954
         'Y' => 'year',
955 955
     );
956 956
 
957
-    if ( ! isset( $periods[ $period ] ) ) {
957
+    if (!isset($periods[$period])) {
958 958
         $period = 'D';
959 959
     }
960 960
     
961
-    return $full ? $periods[ $period ] : $period;
961
+    return $full ? $periods[$period] : $period;
962 962
 
963 963
 }
Please login to merge, or discard this patch.
includes/class-wpinv.php 2 patches
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -140,13 +140,13 @@  discard block
 block discarded – undo
140 140
         require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
141 141
 
142 142
         // load AUI
143
-		require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' );
143
+        require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' );
144 144
 
145 145
         // Register autoloader.
146
-		try {
147
-			spl_autoload_register( array( $this, 'autoload' ), true );
148
-		} catch ( Exception $e ) {
149
-			log_noptin_message( $e->getMessage() );
146
+        try {
147
+            spl_autoload_register( array( $this, 'autoload' ), true );
148
+        } catch ( Exception $e ) {
149
+            log_noptin_message( $e->getMessage() );
150 150
         }
151 151
 
152 152
         require_once( WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php' );
@@ -184,11 +184,11 @@  discard block
 block discarded – undo
184 184
         require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
185 185
         require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
186 186
         require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
187
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
188
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
189
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
190
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
191
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
187
+        require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
188
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
189
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
190
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
191
+        require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
192 192
         require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
193 193
         require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' );
194 194
         require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php' );
@@ -250,47 +250,47 @@  discard block
 block discarded – undo
250 250
     }
251 251
 
252 252
     /**
253
-	 * Class autoloader
254
-	 *
255
-	 * @param       string $class_name The name of the class to load.
256
-	 * @access      public
257
-	 * @since       1.0.19
258
-	 * @return      void
259
-	 */
260
-	public function autoload( $class_name ) {
261
-
262
-		// Normalize the class name...
263
-		$class_name  = strtolower( $class_name );
264
-
265
-		// ... and make sure it is our class.
266
-		if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
267
-			return;
268
-		}
269
-
270
-		// Next, prepare the file name from the class.
271
-		$file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
272
-
273
-		// And an array of possible locations in order of importance.
274
-		$locations = array(
275
-			'includes',
276
-			'includes/data-stores',
253
+     * Class autoloader
254
+     *
255
+     * @param       string $class_name The name of the class to load.
256
+     * @access      public
257
+     * @since       1.0.19
258
+     * @return      void
259
+     */
260
+    public function autoload( $class_name ) {
261
+
262
+        // Normalize the class name...
263
+        $class_name  = strtolower( $class_name );
264
+
265
+        // ... and make sure it is our class.
266
+        if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
267
+            return;
268
+        }
269
+
270
+        // Next, prepare the file name from the class.
271
+        $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
272
+
273
+        // And an array of possible locations in order of importance.
274
+        $locations = array(
275
+            'includes',
276
+            'includes/data-stores',
277 277
             'includes/admin',
278 278
             'includes/admin/meta-boxes'
279
-		);
279
+        );
280 280
 
281
-		// Base path of the classes.
282
-		$plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
281
+        // Base path of the classes.
282
+        $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
283 283
 
284
-		foreach ( $locations as $location ) {
284
+        foreach ( $locations as $location ) {
285 285
 
286
-			if ( file_exists( "$plugin_path/$location/$file_name" ) ) {
287
-				include "$plugin_path/$location/$file_name";
288
-				break;
289
-			}
286
+            if ( file_exists( "$plugin_path/$location/$file_name" ) ) {
287
+                include "$plugin_path/$location/$file_name";
288
+                break;
289
+            }
290 290
 
291
-		}
291
+        }
292 292
 
293
-	}
293
+    }
294 294
 
295 295
     public function init() {
296 296
     }
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
             wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' );
381 381
             wp_enqueue_style( 'jquery-ui-css' );
382 382
             wp_deregister_style( 'yoast-seo-select2' );
383
-	        wp_deregister_style( 'yoast-seo-monorepo' );
383
+            wp_deregister_style( 'yoast-seo-monorepo' );
384 384
         }
385 385
 
386 386
         wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION );
@@ -394,7 +394,7 @@  discard block
 block discarded – undo
394 394
         if ( $page == 'wpinv-subscriptions' ) {
395 395
             wp_enqueue_script( 'jquery-ui-datepicker' );
396 396
             wp_deregister_style( 'yoast-seo-select2' );
397
-	        wp_deregister_style( 'yoast-seo-monorepo' );
397
+            wp_deregister_style( 'yoast-seo-monorepo' );
398 398
         }
399 399
         
400 400
         if ( $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ) ) {
@@ -559,19 +559,19 @@  discard block
 block discarded – undo
559 559
         require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
560 560
     }
561 561
 
562
-	/**
563
-	 * Register widgets
564
-	 *
565
-	 */
566
-	public function register_widgets() {
567
-		register_widget( "WPInv_Checkout_Widget" );
568
-		register_widget( "WPInv_History_Widget" );
569
-		register_widget( "WPInv_Receipt_Widget" );
570
-		register_widget( "WPInv_Subscriptions_Widget" );
571
-		register_widget( "WPInv_Buy_Item_Widget" );
562
+    /**
563
+     * Register widgets
564
+     *
565
+     */
566
+    public function register_widgets() {
567
+        register_widget( "WPInv_Checkout_Widget" );
568
+        register_widget( "WPInv_History_Widget" );
569
+        register_widget( "WPInv_Receipt_Widget" );
570
+        register_widget( "WPInv_Subscriptions_Widget" );
571
+        register_widget( "WPInv_Buy_Item_Widget" );
572 572
         register_widget( "WPInv_Messages_Widget" );
573 573
         register_widget( 'WPInv_GetPaid_Widget' );
574
-	}
574
+    }
575 575
     
576 576
     /**
577 577
      * Remove our pages from yoast sitemaps.
Please login to merge, or discard this patch.
Spacing   +266 added lines, -266 removed lines patch added patch discarded remove patch
@@ -7,15 +7,15 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 class WPInv_Plugin {
15 15
     private static $instance;
16 16
     
17 17
     public static function run() {
18
-        if ( !isset( self::$instance ) && !( self::$instance instanceof WPInv_Plugin ) ) {
18
+        if (!isset(self::$instance) && !(self::$instance instanceof WPInv_Plugin)) {
19 19
             self::$instance = new WPInv_Plugin;
20 20
             self::$instance->includes();
21 21
             self::$instance->actions();
@@ -33,35 +33,35 @@  discard block
 block discarded – undo
33 33
     }
34 34
     
35 35
     public function define_constants() {
36
-        define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
37
-        define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
36
+        define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE));
37
+        define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE));
38 38
     }
39 39
     
40 40
     private function actions() {
41 41
         /* Internationalize the text strings used. */
42
-        add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
42
+        add_action('plugins_loaded', array(&$this, 'plugins_loaded'));
43 43
         
44 44
         /* Perform actions on admin initialization. */
45
-        add_action( 'admin_init', array( &$this, 'admin_init') );
46
-        add_action( 'init', array( &$this, 'init' ), 3 );
47
-        add_action( 'init', array( &$this, 'wpinv_actions' ) );
45
+        add_action('admin_init', array(&$this, 'admin_init'));
46
+        add_action('init', array(&$this, 'init'), 3);
47
+        add_action('init', array(&$this, 'wpinv_actions'));
48 48
         
49
-        if ( class_exists( 'BuddyPress' ) ) {
50
-            add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) );
49
+        if (class_exists('BuddyPress')) {
50
+            add_action('bp_include', array(&$this, 'bp_invoicing_init'));
51 51
         }
52 52
 
53
-        add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) );
54
-        add_action( 'wp_footer', array( &$this, 'wp_footer' ) );
55
-        add_action( 'widgets_init', array( &$this, 'register_widgets' ) );
56
-        add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
53
+        add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts'));
54
+        add_action('wp_footer', array(&$this, 'wp_footer'));
55
+        add_action('widgets_init', array(&$this, 'register_widgets'));
56
+        add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids'));
57 57
 
58
-        if ( is_admin() ) {
59
-            add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) );
60
-            add_filter( 'admin_body_class', array( &$this, 'admin_body_class' ) );
61
-            add_action( 'admin_init', array( &$this, 'init_ayecode_connect_helper' ) );
58
+        if (is_admin()) {
59
+            add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts'));
60
+            add_filter('admin_body_class', array(&$this, 'admin_body_class'));
61
+            add_action('admin_init', array(&$this, 'init_ayecode_connect_helper'));
62 62
 
63 63
         } else {
64
-            add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
64
+            add_filter('pre_get_posts', array(&$this, 'pre_get_posts'));
65 65
         }
66 66
         
67 67
         /**
@@ -71,28 +71,28 @@  discard block
 block discarded – undo
71 71
          *
72 72
          * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference.
73 73
          */
74
-        do_action_ref_array( 'wpinv_actions', array( &$this ) );
74
+        do_action_ref_array('wpinv_actions', array(&$this));
75 75
 
76
-        add_action( 'admin_init', array( &$this, 'activation_redirect') );
76
+        add_action('admin_init', array(&$this, 'activation_redirect'));
77 77
     }
78 78
 
79 79
     /**
80 80
      * Maybe show the AyeCode Connect Notice.
81 81
      */
82
-    public function init_ayecode_connect_helper(){
82
+    public function init_ayecode_connect_helper() {
83 83
         // AyeCode Connect notice
84
-        if ( is_admin() ){
84
+        if (is_admin()) {
85 85
             // set the strings so they can be translated
86 86
             $strings = array(
87
-                'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
88
-                'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
89
-                'connect'           => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ),
90
-                'connect_button'    => __("Connect Site","invoicing"),
91
-                'connecting_button'    => __("Connecting...","invoicing"),
92
-                'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
93
-                'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
87
+                'connect_title' => __("WP Invoicing - an AyeCode product!", "invoicing"),
88
+                'connect_external'  => __("Please confirm you wish to connect your site?", "invoicing"),
89
+                'connect'           => sprintf(__("<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s", "invoicing"), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>"),
90
+                'connect_button'    => __("Connect Site", "invoicing"),
91
+                'connecting_button'    => __("Connecting...", "invoicing"),
92
+                'error_localhost'   => __("This service will only work with a live domain, not a localhost.", "invoicing"),
93
+                'error'             => __("Something went wrong, please refresh and try again.", "invoicing"),
94 94
             );
95
-            new AyeCode_Connect_Helper($strings,array('wpi-addons'));
95
+            new AyeCode_Connect_Helper($strings, array('wpi-addons'));
96 96
         }
97 97
     }
98 98
     
@@ -100,10 +100,10 @@  discard block
 block discarded – undo
100 100
         /* Internationalize the text strings used. */
101 101
         $this->load_textdomain();
102 102
 
103
-        do_action( 'wpinv_loaded' );
103
+        do_action('wpinv_loaded');
104 104
 
105 105
         // Fix oxygen page builder conflict
106
-        if ( function_exists( 'ct_css_output' ) ) {
106
+        if (function_exists('ct_css_output')) {
107 107
             wpinv_oxygen_fix_conflict();
108 108
         }
109 109
     }
@@ -113,140 +113,140 @@  discard block
 block discarded – undo
113 113
      *
114 114
      * @since 1.0
115 115
      */
116
-    public function load_textdomain( $locale = NULL ) {
117
-        if ( empty( $locale ) ) {
118
-            $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
116
+    public function load_textdomain($locale = NULL) {
117
+        if (empty($locale)) {
118
+            $locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale();
119 119
         }
120 120
 
121
-        $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
121
+        $locale = apply_filters('plugin_locale', $locale, 'invoicing');
122 122
         
123
-        unload_textdomain( 'invoicing' );
124
-        load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
125
-        load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
123
+        unload_textdomain('invoicing');
124
+        load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo');
125
+        load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages');
126 126
         
127 127
         /**
128 128
          * Define language constants.
129 129
          */
130
-        require_once( WPINV_PLUGIN_DIR . 'language.php' );
130
+        require_once(WPINV_PLUGIN_DIR . 'language.php');
131 131
     }
132 132
 
133 133
     public function includes() {
134 134
         global $wpinv_options;
135 135
 
136
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
136
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php');
137 137
         $wpinv_options = wpinv_get_settings();
138 138
 
139 139
         // Load composer packages.
140
-        require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
140
+        require_once(WPINV_PLUGIN_DIR . 'vendor/autoload.php');
141 141
 
142 142
         // load AUI
143
-		require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' );
143
+		require_once(WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php');
144 144
 
145 145
         // Register autoloader.
146 146
 		try {
147
-			spl_autoload_register( array( $this, 'autoload' ), true );
148
-		} catch ( Exception $e ) {
149
-			log_noptin_message( $e->getMessage() );
150
-        }
151
-
152
-        require_once( WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php' );
153
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
154
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
155
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
156
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
157
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
158
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
159
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' );
160
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
161
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
162
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
163
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
164
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' );
165
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' );
166
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' );
167
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' );
168
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-discount.php' );
169
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' );
170
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' );
171
-        require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' );
172
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' );
173
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
174
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
175
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' );
176
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
177
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
178
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
179
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
180
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' );
181
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
182
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php' );
183
-        require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' );
184
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
185
-        require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
186
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
187
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
188
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
189
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
190
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
191
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
192
-        require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
193
-        require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' );
194
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php' );
195
-
196
-        if ( !class_exists( 'WPInv_EUVat' ) ) {
197
-            require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' );
147
+			spl_autoload_register(array($this, 'autoload'), true);
148
+		} catch (Exception $e) {
149
+			log_noptin_message($e->getMessage());
150
+        }
151
+
152
+        require_once(WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php');
153
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php');
154
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php');
155
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php');
156
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php');
157
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php');
158
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php');
159
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php');
160
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php');
161
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php');
162
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php');
163
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php');
164
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php');
165
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php');
166
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php');
167
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php');
168
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-discount.php');
169
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php');
170
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php');
171
+        require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php');
172
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php');
173
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php');
174
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php');
175
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php');
176
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php');
177
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php');
178
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php');
179
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php');
180
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php');
181
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php');
182
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php');
183
+        require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php');
184
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php');
185
+        require_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php');
186
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php');
187
+	    require_once(WPINV_PLUGIN_DIR . 'widgets/checkout.php');
188
+	    require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-history.php');
189
+	    require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php');
190
+	    require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php');
191
+	    require_once(WPINV_PLUGIN_DIR . 'widgets/subscriptions.php');
192
+        require_once(WPINV_PLUGIN_DIR . 'widgets/buy-item.php');
193
+        require_once(WPINV_PLUGIN_DIR . 'widgets/getpaid.php');
194
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php');
195
+
196
+        if (!class_exists('WPInv_EUVat')) {
197
+            require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php');
198 198
         }
199 199
         
200
-        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
201
-        if ( !empty( $gateways ) ) {
202
-            foreach ( $gateways as $gateway ) {
203
-                if ( $gateway == 'manual' ) {
200
+        $gateways = array_keys(wpinv_get_enabled_payment_gateways());
201
+        if (!empty($gateways)) {
202
+            foreach ($gateways as $gateway) {
203
+                if ($gateway == 'manual') {
204 204
                     continue;
205 205
                 }
206 206
                 
207 207
                 $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php';
208 208
                 
209
-                if ( file_exists( $gateway_file ) ) {
210
-                    require_once( $gateway_file );
209
+                if (file_exists($gateway_file)) {
210
+                    require_once($gateway_file);
211 211
                 }
212 212
             }
213 213
         }
214
-        require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' );
214
+        require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php');
215 215
         
216
-        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
217
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' );
218
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
219
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' );
216
+        if (is_admin() || (defined('WP_CLI') && WP_CLI)) {
217
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php');
218
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php');
219
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php');
220 220
             //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' );
221
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' );
222
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' );
223
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
224
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
225
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' );
226
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
227
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
228
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
229
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' );
221
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php');
222
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php');
223
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php');
224
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php');
225
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php');
226
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php');
227
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php');
228
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php');
229
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php');
230 230
             //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
231 231
             // load the user class only on the users.php page
232 232
             global $pagenow;
233
-            if($pagenow=='users.php'){
233
+            if ($pagenow == 'users.php') {
234 234
                 new WPInv_Admin_Users();
235 235
             }
236 236
         }
237 237
 
238 238
         // Register cli commands
239
-        if ( defined( 'WP_CLI' ) && WP_CLI ) {
240
-            require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
241
-            WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
239
+        if (defined('WP_CLI') && WP_CLI) {
240
+            require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php');
241
+            WP_CLI::add_command('invoicing', 'WPInv_CLI');
242 242
         }
243 243
         
244 244
         // include css inliner
245
-        if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) {
246
-            include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' );
245
+        if (!class_exists('Emogrifier') && class_exists('DOMDocument')) {
246
+            include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php');
247 247
         }
248 248
         
249
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' );
249
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php');
250 250
     }
251 251
 
252 252
     /**
@@ -257,18 +257,18 @@  discard block
 block discarded – undo
257 257
 	 * @since       1.0.19
258 258
 	 * @return      void
259 259
 	 */
260
-	public function autoload( $class_name ) {
260
+	public function autoload($class_name) {
261 261
 
262 262
 		// Normalize the class name...
263
-		$class_name  = strtolower( $class_name );
263
+		$class_name = strtolower($class_name);
264 264
 
265 265
 		// ... and make sure it is our class.
266
-		if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
266
+		if (false === strpos($class_name, 'getpaid_') && false === strpos($class_name, 'wpinv_')) {
267 267
 			return;
268 268
 		}
269 269
 
270 270
 		// Next, prepare the file name from the class.
271
-		$file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
271
+		$file_name = 'class-' . str_replace('_', '-', $class_name) . '.php';
272 272
 
273 273
 		// And an array of possible locations in order of importance.
274 274
 		$locations = array(
@@ -279,11 +279,11 @@  discard block
 block discarded – undo
279 279
 		);
280 280
 
281 281
 		// Base path of the classes.
282
-		$plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
282
+		$plugin_path = untrailingslashit(WPINV_PLUGIN_DIR);
283 283
 
284
-		foreach ( $locations as $location ) {
284
+		foreach ($locations as $location) {
285 285
 
286
-			if ( file_exists( "$plugin_path/$location/$file_name" ) ) {
286
+			if (file_exists("$plugin_path/$location/$file_name")) {
287 287
 				include "$plugin_path/$location/$file_name";
288 288
 				break;
289 289
 			}
@@ -297,114 +297,114 @@  discard block
 block discarded – undo
297 297
     
298 298
     public function admin_init() {
299 299
         self::$instance->default_payment_form = wpinv_get_default_payment_form();
300
-        add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) );
300
+        add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php'));
301 301
     }
302 302
 
303 303
     public function activation_redirect() {
304 304
         // Bail if no activation redirect
305
-        if ( !get_transient( '_wpinv_activation_redirect' ) ) {
305
+        if (!get_transient('_wpinv_activation_redirect')) {
306 306
             return;
307 307
         }
308 308
 
309 309
         // Delete the redirect transient
310
-        delete_transient( '_wpinv_activation_redirect' );
310
+        delete_transient('_wpinv_activation_redirect');
311 311
 
312 312
         // Bail if activating from network, or bulk
313
-        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
313
+        if (is_network_admin() || isset($_GET['activate-multi'])) {
314 314
             return;
315 315
         }
316 316
 
317
-        wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
317
+        wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general'));
318 318
         exit;
319 319
     }
320 320
     
321 321
     public function enqueue_scripts() {
322
-        $suffix       = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
322
+        $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
323 323
         
324
-        wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION );
325
-        wp_enqueue_style( 'wpinv_front_style' );
324
+        wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION);
325
+        wp_enqueue_style('wpinv_front_style');
326 326
                
327 327
         // Register scripts
328
-        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
329
-        wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ),  filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) );
328
+        wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
329
+        wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array('jquery'), filemtime(WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js'));
330 330
 
331 331
         $localize                         = array();
332
-        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
333
-        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
332
+        $localize['ajax_url']             = admin_url('admin-ajax.php');
333
+        $localize['nonce']                = wp_create_nonce('wpinv-nonce');
334 334
         $localize['currency_symbol']      = wpinv_currency_symbol();
335 335
         $localize['currency_pos']         = wpinv_currency_position();
336 336
         $localize['thousand_sep']         = wpinv_thousands_separator();
337 337
         $localize['decimal_sep']          = wpinv_decimal_separator();
338 338
         $localize['decimals']             = wpinv_decimals();
339
-        $localize['txtComplete']          = __( 'Continue', 'invoicing' );
339
+        $localize['txtComplete']          = __('Continue', 'invoicing');
340 340
         $localize['UseTaxes']             = wpinv_use_taxes();
341
-        $localize['checkoutNonce']        = wp_create_nonce( 'wpinv_checkout_nonce' );
341
+        $localize['checkoutNonce']        = wp_create_nonce('wpinv_checkout_nonce');
342 342
 
343
-        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
343
+        $localize = apply_filters('wpinv_front_js_localize', $localize);
344 344
         
345
-        wp_enqueue_script( 'jquery-blockui' );
345
+        wp_enqueue_script('jquery-blockui');
346 346
         $autofill_api = wpinv_get_option('address_autofill_api');
347 347
         $autofill_active = wpinv_get_option('address_autofill_active');
348
-        if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) {
349
-            if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) {
350
-                wp_dequeue_script( 'google-maps-api' );
348
+        if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api) && wpinv_is_checkout()) {
349
+            if (wp_script_is('google-maps-api', 'enqueued')) {
350
+                wp_dequeue_script('google-maps-api');
351 351
             }
352
-            wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false );
353
-            wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true );
352
+            wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false);
353
+            wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery', 'google-maps-api'), '', true);
354 354
         }
355 355
 
356
-        wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' );
357
-        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION );
356
+        wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all');
357
+        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION);
358 358
 
359
-        wp_enqueue_script( 'wpinv-front-script' );
360
-        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
359
+        wp_enqueue_script('wpinv-front-script');
360
+        wp_localize_script('wpinv-front-script', 'WPInv', $localize);
361 361
 
362
-        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
363
-        wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ),  $version, true );
362
+        $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js');
363
+        wp_enqueue_script('wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array('wpinv-front-script', 'wp-hooks'), $version, true);
364 364
     }
365 365
 
366
-    public function admin_enqueue_scripts( $hook ) {
366
+    public function admin_enqueue_scripts($hook) {
367 367
         global $post, $pagenow;
368 368
         
369 369
         $post_type  = wpinv_admin_post_type();
370
-        $suffix     = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
371
-        $page       = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : '';
370
+        $suffix     = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
371
+        $page       = isset($_GET['page']) ? strtolower($_GET['page']) : '';
372 372
 
373 373
         $jquery_ui_css = false;
374
-        if ( ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount' ) && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) {
374
+        if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) {
375 375
             $jquery_ui_css = true;
376
-        } else if ( $page == 'wpinv-settings' || $page == 'wpinv-reports' ) {
376
+        } else if ($page == 'wpinv-settings' || $page == 'wpinv-reports') {
377 377
             $jquery_ui_css = true;
378 378
         }
379
-        if ( $jquery_ui_css ) {
380
-            wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' );
381
-            wp_enqueue_style( 'jquery-ui-css' );
382
-            wp_deregister_style( 'yoast-seo-select2' );
383
-	        wp_deregister_style( 'yoast-seo-monorepo' );
379
+        if ($jquery_ui_css) {
380
+            wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16');
381
+            wp_enqueue_style('jquery-ui-css');
382
+            wp_deregister_style('yoast-seo-select2');
383
+	        wp_deregister_style('yoast-seo-monorepo');
384 384
         }
385 385
 
386
-        wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION );
387
-        wp_enqueue_style( 'wpinv_meta_box_style' );
386
+        wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION);
387
+        wp_enqueue_style('wpinv_meta_box_style');
388 388
         
389
-        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' );
390
-        wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), $version );
391
-        wp_enqueue_style( 'wpinv_admin_style' );
389
+        $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/admin.css');
390
+        wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), $version);
391
+        wp_enqueue_style('wpinv_admin_style');
392 392
 
393
-        $enqueue = ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) );
394
-        if ( $page == 'wpinv-subscriptions' ) {
395
-            wp_enqueue_script( 'jquery-ui-datepicker' );
396
-            wp_deregister_style( 'yoast-seo-select2' );
397
-	        wp_deregister_style( 'yoast-seo-monorepo' );
393
+        $enqueue = ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php'));
394
+        if ($page == 'wpinv-subscriptions') {
395
+            wp_enqueue_script('jquery-ui-datepicker');
396
+            wp_deregister_style('yoast-seo-select2');
397
+	        wp_deregister_style('yoast-seo-monorepo');
398 398
         }
399 399
         
400
-        if ( $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ) ) {
401
-            wp_enqueue_script( 'jquery-ui-datepicker' );
400
+        if ($enqueue_datepicker = apply_filters('wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue)) {
401
+            wp_enqueue_script('jquery-ui-datepicker');
402 402
         }
403 403
 
404
-        wp_enqueue_style( 'wp-color-picker' );
405
-        wp_enqueue_script( 'wp-color-picker' );
404
+        wp_enqueue_style('wp-color-picker');
405
+        wp_enqueue_script('wp-color-picker');
406 406
         
407
-        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
407
+        wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
408 408
 
409 409
         if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) {
410 410
             $autofill_api = wpinv_get_option('address_autofill_api');
@@ -415,21 +415,21 @@  discard block
 block discarded – undo
415 415
             }
416 416
         }
417 417
 
418
-        wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' );
419
-        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION );
418
+        wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all');
419
+        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION);
420 420
 
421
-        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' );
422
-        wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip' ),  $version );
423
-        wp_enqueue_script( 'wpinv-admin-script' );
421
+        $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin.js');
422
+        wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip'), $version);
423
+        wp_enqueue_script('wpinv-admin-script');
424 424
         
425 425
         $localize                               = array();
426
-        $localize['ajax_url']                   = admin_url( 'admin-ajax.php' );
427
-        $localize['post_ID']                    = isset( $post->ID ) ? $post->ID : '';
428
-        $localize['wpinv_nonce']                = wp_create_nonce( 'wpinv-nonce' );
429
-        $localize['add_invoice_note_nonce']     = wp_create_nonce( 'add-invoice-note' );
430
-        $localize['delete_invoice_note_nonce']  = wp_create_nonce( 'delete-invoice-note' );
431
-        $localize['invoice_item_nonce']         = wp_create_nonce( 'invoice-item' );
432
-        $localize['billing_details_nonce']      = wp_create_nonce( 'get-billing-details' );
426
+        $localize['ajax_url']                   = admin_url('admin-ajax.php');
427
+        $localize['post_ID']                    = isset($post->ID) ? $post->ID : '';
428
+        $localize['wpinv_nonce']                = wp_create_nonce('wpinv-nonce');
429
+        $localize['add_invoice_note_nonce']     = wp_create_nonce('add-invoice-note');
430
+        $localize['delete_invoice_note_nonce']  = wp_create_nonce('delete-invoice-note');
431
+        $localize['invoice_item_nonce']         = wp_create_nonce('invoice-item');
432
+        $localize['billing_details_nonce']      = wp_create_nonce('get-billing-details');
433 433
         $localize['tax']                        = wpinv_tax_amount();
434 434
         $localize['discount']                   = wpinv_discount_amount();
435 435
         $localize['currency_symbol']            = wpinv_currency_symbol();
@@ -437,100 +437,100 @@  discard block
 block discarded – undo
437 437
         $localize['thousand_sep']               = wpinv_thousands_separator();
438 438
         $localize['decimal_sep']                = wpinv_decimal_separator();
439 439
         $localize['decimals']                   = wpinv_decimals();
440
-        $localize['save_invoice']               = __( 'Save Invoice', 'invoicing' );
441
-        $localize['status_publish']             = wpinv_status_nicename( 'publish' );
442
-        $localize['status_pending']             = wpinv_status_nicename( 'wpi-pending' );
443
-        $localize['delete_tax_rate']            = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' );
444
-        $localize['OneItemMin']                 = __( 'Invoice must contain at least one item', 'invoicing' );
445
-        $localize['DeleteInvoiceItem']          = __( 'Are you sure you wish to delete this item?', 'invoicing' );
446
-        $localize['FillBillingDetails']         = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' );
447
-        $localize['confirmCalcTotals']          = __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' );
448
-        $localize['AreYouSure']                 = __( 'Are you sure?', 'invoicing' );
449
-        $localize['emptyInvoice']               = __( 'Add at least one item to save invoice!', 'invoicing' );
450
-        $localize['errDeleteItem']              = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' );
451
-        $localize['delete_subscription']        = __( 'Are you sure you want to delete this subscription?', 'invoicing' );
452
-        $localize['action_edit']                = __( 'Edit', 'invoicing' );
453
-        $localize['action_cancel']              = __( 'Cancel', 'invoicing' );
454
-
455
-        $localize = apply_filters( 'wpinv_admin_js_localize', $localize );
456
-
457
-        wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize );
440
+        $localize['save_invoice']               = __('Save Invoice', 'invoicing');
441
+        $localize['status_publish']             = wpinv_status_nicename('publish');
442
+        $localize['status_pending']             = wpinv_status_nicename('wpi-pending');
443
+        $localize['delete_tax_rate']            = __('Are you sure you wish to delete this tax rate?', 'invoicing');
444
+        $localize['OneItemMin']                 = __('Invoice must contain at least one item', 'invoicing');
445
+        $localize['DeleteInvoiceItem']          = __('Are you sure you wish to delete this item?', 'invoicing');
446
+        $localize['FillBillingDetails']         = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing');
447
+        $localize['confirmCalcTotals']          = __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing');
448
+        $localize['AreYouSure']                 = __('Are you sure?', 'invoicing');
449
+        $localize['emptyInvoice']               = __('Add at least one item to save invoice!', 'invoicing');
450
+        $localize['errDeleteItem']              = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing');
451
+        $localize['delete_subscription']        = __('Are you sure you want to delete this subscription?', 'invoicing');
452
+        $localize['action_edit']                = __('Edit', 'invoicing');
453
+        $localize['action_cancel']              = __('Cancel', 'invoicing');
454
+
455
+        $localize = apply_filters('wpinv_admin_js_localize', $localize);
456
+
457
+        wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize);
458 458
 
459 459
         // Load payment form scripts on our admin pages only.
460
-        if ( ( $hook == 'post-new.php' || $hook == 'post.php' ) && 'wpi_payment_form' === $post->post_type ) {
460
+        if (($hook == 'post-new.php' || $hook == 'post.php') && 'wpi_payment_form' === $post->post_type) {
461 461
 
462
-            wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION );
463
-            wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
464
-            wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
462
+            wp_enqueue_script('vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION);
463
+            wp_enqueue_script('sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION);
464
+            wp_enqueue_script('vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array('sortable', 'vue'), WPINV_VERSION);
465 465
 
466
-            $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
467
-            wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
466
+            $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js');
467
+            wp_register_script('wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array('wpinv-admin-script', 'vue_draggable'), $version);
468 468
         
469
-            wp_localize_script( 'wpinv-admin-payment-form-script', 'wpinvPaymentFormAdmin', array(
469
+            wp_localize_script('wpinv-admin-payment-form-script', 'wpinvPaymentFormAdmin', array(
470 470
                 'elements'      => $this->form_elements->get_elements(),
471
-                'form_elements' => $this->form_elements->get_form_elements( $post->ID ),
471
+                'form_elements' => $this->form_elements->get_form_elements($post->ID),
472 472
                 'all_items'     => $this->form_elements->get_published_items(),
473 473
                 'currency'      => wpinv_currency_symbol(),
474 474
                 'position'      => wpinv_currency_position(),
475 475
                 'decimals'      => (int) wpinv_decimals(),
476 476
                 'thousands_sep' => wpinv_thousands_separator(),
477 477
                 'decimals_sep'  => wpinv_decimal_separator(),
478
-                'form_items'    => $this->form_elements->get_form_items( $post->ID ),
478
+                'form_items'    => $this->form_elements->get_form_items($post->ID),
479 479
                 'is_default'    => $post->ID == $this->default_payment_form,
480
-            ) );
480
+            ));
481 481
 
482
-            wp_enqueue_script( 'wpinv-admin-payment-form-script' );
482
+            wp_enqueue_script('wpinv-admin-payment-form-script');
483 483
         }
484 484
 
485
-        if ( $page == 'wpinv-subscriptions' ) {
486
-            wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ),  WPINV_VERSION );
487
-            wp_enqueue_script( 'wpinv-sub-admin-script' );
485
+        if ($page == 'wpinv-subscriptions') {
486
+            wp_register_script('wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array('wpinv-admin-script'), WPINV_VERSION);
487
+            wp_enqueue_script('wpinv-sub-admin-script');
488 488
         }
489 489
 
490
-        if ( $page == 'wpinv-reports' ) {
491
-            wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' );
490
+        if ($page == 'wpinv-reports') {
491
+            wp_enqueue_script('jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array('jquery'), '0.7');
492 492
         }
493 493
 
494 494
     }
495 495
 
496
-    public function admin_body_class( $classes ) {
496
+    public function admin_body_class($classes) {
497 497
         global $pagenow, $post, $current_screen;
498 498
         
499
-        if ( !empty( $current_screen->post_type ) && ( $current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_payment_form' || $current_screen->post_type == 'wpi_quote' ) ) {
499
+        if (!empty($current_screen->post_type) && ($current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_payment_form' || $current_screen->post_type == 'wpi_quote')) {
500 500
             $classes .= ' wpinv-cpt';
501 501
         }
502 502
         
503
-        $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false;
503
+        $page = isset($_GET['page']) ? strtolower($_GET['page']) : false;
504 504
 
505
-        $add_class = $page && $pagenow == 'admin.php' && strpos( $page, 'wpinv-' ) === 0 ? true : false;
506
-        if ( $add_class ) {
507
-            $classes .= ' wpi-' . wpinv_sanitize_key( $page );
505
+        $add_class = $page && $pagenow == 'admin.php' && strpos($page, 'wpinv-') === 0 ? true : false;
506
+        if ($add_class) {
507
+            $classes .= ' wpi-' . wpinv_sanitize_key($page);
508 508
         }
509 509
         
510 510
         $settings_class = array();
511
-        if ( $page == 'wpinv-settings' ) {
512
-            if ( !empty( $_REQUEST['tab'] ) ) {
513
-                $settings_class[] = sanitize_text_field( $_REQUEST['tab'] );
511
+        if ($page == 'wpinv-settings') {
512
+            if (!empty($_REQUEST['tab'])) {
513
+                $settings_class[] = sanitize_text_field($_REQUEST['tab']);
514 514
             }
515 515
             
516
-            if ( !empty( $_REQUEST['section'] ) ) {
517
-                $settings_class[] = sanitize_text_field( $_REQUEST['section'] );
516
+            if (!empty($_REQUEST['section'])) {
517
+                $settings_class[] = sanitize_text_field($_REQUEST['section']);
518 518
             }
519 519
             
520
-            $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main';
520
+            $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main';
521 521
         }
522 522
         
523
-        if ( !empty( $settings_class ) ) {
524
-            $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) );
523
+        if (!empty($settings_class)) {
524
+            $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-'));
525 525
         }
526 526
         
527 527
         $post_type = wpinv_admin_post_type();
528 528
 
529
-        if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) {
529
+        if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) {
530 530
             return $classes .= ' wpinv';
531 531
         }
532 532
         
533
-        if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) {
533
+        if ($pagenow == 'post.php' && $post_type == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) {
534 534
             $classes .= ' wpi-editable-n';
535 535
         }
536 536
 
@@ -542,21 +542,21 @@  discard block
 block discarded – undo
542 542
     }
543 543
     
544 544
     public function wpinv_actions() {
545
-        if ( isset( $_REQUEST['wpi_action'] ) ) {
546
-            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
545
+        if (isset($_REQUEST['wpi_action'])) {
546
+            do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST);
547 547
         }
548 548
     }
549 549
     
550
-    public function pre_get_posts( $wp_query ) {
551
-        if ( !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
552
-            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() );
550
+    public function pre_get_posts($wp_query) {
551
+        if (!empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query()) {
552
+            $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses());
553 553
         }
554 554
         
555 555
         return $wp_query;
556 556
     }
557 557
     
558 558
     public function bp_invoicing_init() {
559
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
559
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php');
560 560
     }
561 561
 
562 562
 	/**
@@ -564,13 +564,13 @@  discard block
 block discarded – undo
564 564
 	 *
565 565
 	 */
566 566
 	public function register_widgets() {
567
-		register_widget( "WPInv_Checkout_Widget" );
568
-		register_widget( "WPInv_History_Widget" );
569
-		register_widget( "WPInv_Receipt_Widget" );
570
-		register_widget( "WPInv_Subscriptions_Widget" );
571
-		register_widget( "WPInv_Buy_Item_Widget" );
572
-        register_widget( "WPInv_Messages_Widget" );
573
-        register_widget( 'WPInv_GetPaid_Widget' );
567
+		register_widget("WPInv_Checkout_Widget");
568
+		register_widget("WPInv_History_Widget");
569
+		register_widget("WPInv_Receipt_Widget");
570
+		register_widget("WPInv_Subscriptions_Widget");
571
+		register_widget("WPInv_Buy_Item_Widget");
572
+        register_widget("WPInv_Messages_Widget");
573
+        register_widget('WPInv_GetPaid_Widget');
574 574
 	}
575 575
     
576 576
     /**
@@ -579,10 +579,10 @@  discard block
 block discarded – undo
579 579
      * @since 1.0.19
580 580
      * @param int[] $excluded_posts_ids
581 581
      */
582
-    public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
582
+    public function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) {
583 583
 
584 584
         // Ensure that we have an array.
585
-        if ( ! is_array( $excluded_posts_ids ) ) {
585
+        if (!is_array($excluded_posts_ids)) {
586 586
             $excluded_posts_ids = array();
587 587
         }
588 588
 
@@ -590,24 +590,24 @@  discard block
 block discarded – undo
590 590
         $our_pages = array();
591 591
     
592 592
         // Checkout page.
593
-        $our_pages[] = wpinv_get_option( 'checkout_page', false );
593
+        $our_pages[] = wpinv_get_option('checkout_page', false);
594 594
 
595 595
         // Success page.
596
-        $our_pages[] = wpinv_get_option( 'success_page', false );
596
+        $our_pages[] = wpinv_get_option('success_page', false);
597 597
 
598 598
         // Failure page.
599
-        $our_pages[] = wpinv_get_option( 'failure_page', false );
599
+        $our_pages[] = wpinv_get_option('failure_page', false);
600 600
 
601 601
         // History page.
602
-        $our_pages[] = wpinv_get_option( 'invoice_history_page', false );
602
+        $our_pages[] = wpinv_get_option('invoice_history_page', false);
603 603
 
604 604
         // Subscriptions page.
605
-        $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
605
+        $our_pages[] = wpinv_get_option('invoice_subscription_page', false);
606 606
 
607
-        $our_pages   = array_map( 'intval', array_filter( $our_pages ) );
607
+        $our_pages   = array_map('intval', array_filter($our_pages));
608 608
 
609 609
         $excluded_posts_ids = $excluded_posts_ids + $our_pages;
610
-        return array_unique( $excluded_posts_ids );
610
+        return array_unique($excluded_posts_ids);
611 611
 
612 612
     }
613 613
 
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-data.php 2 patches
Indentation   +772 added lines, -772 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
  */
10 10
 
11 11
 if ( ! defined( 'ABSPATH' ) ) {
12
-	exit;
12
+    exit;
13 13
 }
14 14
 
15 15
 /**
@@ -21,775 +21,775 @@  discard block
 block discarded – undo
21 21
  */
22 22
 abstract class GetPaid_Data {
23 23
 
24
-	/**
25
-	 * ID for this object.
26
-	 *
27
-	 * @since 1.0.19
28
-	 * @var int
29
-	 */
30
-	protected $id = 0;
31
-
32
-	/**
33
-	 * Core data for this object. Name value pairs (name + default value).
34
-	 *
35
-	 * @since 1.0.19
36
-	 * @var array
37
-	 */
38
-	protected $data = array();
39
-
40
-	/**
41
-	 * Core data changes for this object.
42
-	 *
43
-	 * @since 1.0.19
44
-	 * @var array
45
-	 */
46
-	protected $changes = array();
47
-
48
-	/**
49
-	 * This is false until the object is read from the DB.
50
-	 *
51
-	 * @since 1.0.19
52
-	 * @var bool
53
-	 */
54
-	protected $object_read = false;
55
-
56
-	/**
57
-	 * This is the name of this object type.
58
-	 *
59
-	 * @since 1.0.19
60
-	 * @var string
61
-	 */
62
-	protected $object_type = 'data';
63
-
64
-	/**
65
-	 * Extra data for this object. Name value pairs (name + default value).
66
-	 * Used as a standard way for sub classes (like item types) to add
67
-	 * additional information to an inherited class.
68
-	 *
69
-	 * @since 1.0.19
70
-	 * @var array
71
-	 */
72
-	protected $extra_data = array();
73
-
74
-	/**
75
-	 * Set to _data on construct so we can track and reset data if needed.
76
-	 *
77
-	 * @since 1.0.19
78
-	 * @var array
79
-	 */
80
-	protected $default_data = array();
81
-
82
-	/**
83
-	 * Contains a reference to the data store for this class.
84
-	 *
85
-	 * @since 1.0.19
86
-	 * @var GetPaid_Data_Store
87
-	 */
88
-	protected $data_store;
89
-
90
-	/**
91
-	 * Stores meta in cache for future reads.
92
-	 * A group must be set to to enable caching.
93
-	 *
94
-	 * @since 1.0.19
95
-	 * @var string
96
-	 */
97
-	protected $cache_group = '';
98
-
99
-	/**
100
-	 * Stores the last error.
101
-	 *
102
-	 * @since 1.0.19
103
-	 * @var string
104
-	 */
105
-	public $last_error = '';
106
-
107
-	/**
108
-	 * Stores additional meta data.
109
-	 *
110
-	 * @since 1.0.19
111
-	 * @var array
112
-	 */
113
-	protected $meta_data = null;
114
-
115
-	/**
116
-	 * Default constructor.
117
-	 *
118
-	 * @param int|object|array $read ID to load from the DB (optional) or already queried data.
119
-	 */
120
-	public function __construct( $read = 0 ) {
121
-		$this->data         = array_merge( $this->data, $this->extra_data );
122
-		$this->default_data = $this->data;
123
-	}
124
-
125
-	/**
126
-	 * Only store the object ID to avoid serializing the data object instance.
127
-	 *
128
-	 * @return array
129
-	 */
130
-	public function __sleep() {
131
-		return array( 'id' );
132
-	}
133
-
134
-	/**
135
-	 * Re-run the constructor with the object ID.
136
-	 *
137
-	 * If the object no longer exists, remove the ID.
138
-	 */
139
-	public function __wakeup() {
140
-		try {
141
-			$this->__construct( absint( $this->id ) );
142
-		} catch ( Exception $e ) {
143
-			$this->set_id( 0 );
144
-			$this->set_object_read( true );
145
-		}
146
-	}
147
-
148
-	/**
149
-	 * When the object is cloned, make sure meta is duplicated correctly.
150
-	 *
151
-	 * @since 1.0.19
152
-	 */
153
-	public function __clone() {
154
-		$this->maybe_read_meta_data();
155
-		if ( ! empty( $this->meta_data ) ) {
156
-			foreach ( $this->meta_data as $array_key => $meta ) {
157
-				$this->meta_data[ $array_key ] = clone $meta;
158
-				if ( ! empty( $meta->id ) ) {
159
-					$this->meta_data[ $array_key ]->id = null;
160
-				}
161
-			}
162
-		}
163
-	}
164
-
165
-	/**
166
-	 * Get the data store.
167
-	 *
168
-	 * @since  1.0.19
169
-	 * @return object
170
-	 */
171
-	public function get_data_store() {
172
-		return $this->data_store;
173
-	}
174
-
175
-	/**
176
-	 * Returns the unique ID for this object.
177
-	 *
178
-	 * @since  1.0.19
179
-	 * @return int
180
-	 */
181
-	public function get_id() {
182
-		return $this->id;
183
-	}
184
-
185
-	/**
186
-	 * Delete an object, set the ID to 0, and return result.
187
-	 *
188
-	 * @since  1.0.19
189
-	 * @param  bool $force_delete Should the data be deleted permanently.
190
-	 * @return bool result
191
-	 */
192
-	public function delete( $force_delete = false ) {
193
-		if ( $this->data_store ) {
194
-			$this->data_store->delete( $this, array( 'force_delete' => $force_delete ) );
195
-			$this->set_id( 0 );
196
-			return true;
197
-		}
198
-		return false;
199
-	}
200
-
201
-	/**
202
-	 * Save should create or update based on object existence.
203
-	 *
204
-	 * @since  1.0.19
205
-	 * @return int
206
-	 */
207
-	public function save() {
208
-		if ( ! $this->data_store ) {
209
-			return $this->get_id();
210
-		}
211
-
212
-		/**
213
-		 * Trigger action before saving to the DB. Allows you to adjust object props before save.
214
-		 *
215
-		 * @param GetPaid_Data          $this The object being saved.
216
-		 * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
217
-		 */
218
-		do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store );
219
-
220
-		if ( $this->get_id() ) {
221
-			$this->data_store->update( $this );
222
-		} else {
223
-			$this->data_store->create( $this );
224
-		}
225
-
226
-		/**
227
-		 * Trigger action after saving to the DB.
228
-		 *
229
-		 * @param GetPaid_Data          $this The object being saved.
230
-		 * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
231
-		 */
232
-		do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store );
233
-
234
-		return $this->get_id();
235
-	}
236
-
237
-	/**
238
-	 * Change data to JSON format.
239
-	 *
240
-	 * @since  1.0.19
241
-	 * @return string Data in JSON format.
242
-	 */
243
-	public function __toString() {
244
-		return wp_json_encode( $this->get_data() );
245
-	}
246
-
247
-	/**
248
-	 * Returns all data for this object.
249
-	 *
250
-	 * @since  1.0.19
251
-	 * @return array
252
-	 */
253
-	public function get_data() {
254
-		return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) );
255
-	}
256
-
257
-	/**
258
-	 * Returns array of expected data keys for this object.
259
-	 *
260
-	 * @since   1.0.19
261
-	 * @return array
262
-	 */
263
-	public function get_data_keys() {
264
-		return array_keys( $this->data );
265
-	}
266
-
267
-	/**
268
-	 * Returns all "extra" data keys for an object (for sub objects like item types).
269
-	 *
270
-	 * @since  1.0.19
271
-	 * @return array
272
-	 */
273
-	public function get_extra_data_keys() {
274
-		return array_keys( $this->extra_data );
275
-	}
276
-
277
-	/**
278
-	 * Filter null meta values from array.
279
-	 *
280
-	 * @since  1.0.19
281
-	 * @param mixed $meta Meta value to check.
282
-	 * @return bool
283
-	 */
284
-	protected function filter_null_meta( $meta ) {
285
-		return ! is_null( $meta->value );
286
-	}
287
-
288
-	/**
289
-	 * Get All Meta Data.
290
-	 *
291
-	 * @since 1.0.19
292
-	 * @return array of objects.
293
-	 */
294
-	public function get_meta_data() {
295
-		$this->maybe_read_meta_data();
296
-		return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) );
297
-	}
298
-
299
-	/**
300
-	 * Check if the key is an internal one.
301
-	 *
302
-	 * @since  1.0.19
303
-	 * @param  string $key Key to check.
304
-	 * @return bool   true if it's an internal key, false otherwise
305
-	 */
306
-	protected function is_internal_meta_key( $key ) {
307
-		$internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true );
308
-
309
-		if ( ! $internal_meta_key ) {
310
-			return false;
311
-		}
312
-
313
-		$has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) );
314
-
315
-		if ( ! $has_setter_or_getter ) {
316
-			return false;
317
-		}
318
-
319
-		/* translators: %s: $key Key to check */
320
-		getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
321
-
322
-		return true;
323
-	}
324
-
325
-	/**
326
-	 * Get Meta Data by Key.
327
-	 *
328
-	 * @since  1.0.19
329
-	 * @param  string $key Meta Key.
330
-	 * @param  bool   $single return first found meta with key, or all with $key.
331
-	 * @param  string $context What the value is for. Valid values are view and edit.
332
-	 * @return mixed
333
-	 */
334
-	public function get_meta( $key = '', $single = true, $context = 'view' ) {
335
-
336
-		// Check if this is an internal meta key.
337
-		if ( $this->is_internal_meta_key( $key ) ) {
338
-			$function = 'get_' . $key;
339
-
340
-			if ( is_callable( array( $this, $function ) ) ) {
341
-				return $this->{$function}();
342
-			}
343
-		}
344
-
345
-		// Read the meta data if not yet read.
346
-		$this->maybe_read_meta_data();
347
-		$meta_data  = $this->get_meta_data();
348
-		$array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true );
349
-		$value      = $single ? '' : array();
350
-
351
-		if ( ! empty( $array_keys ) ) {
352
-			// We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()).
353
-			if ( $single ) {
354
-				$value = $meta_data[ current( $array_keys ) ]->value;
355
-			} else {
356
-				$value = array_intersect_key( $meta_data, array_flip( $array_keys ) );
357
-			}
358
-		}
359
-
360
-		if ( 'view' === $context ) {
361
-			$value = apply_filters( $this->get_hook_prefix() . $key, $value, $this );
362
-		}
363
-
364
-		return $value;
365
-	}
366
-
367
-	/**
368
-	 * See if meta data exists, since get_meta always returns a '' or array().
369
-	 *
370
-	 * @since  1.0.19
371
-	 * @param  string $key Meta Key.
372
-	 * @return boolean
373
-	 */
374
-	public function meta_exists( $key = '' ) {
375
-		$this->maybe_read_meta_data();
376
-		$array_keys = wp_list_pluck( $this->get_meta_data(), 'key' );
377
-		return in_array( $key, $array_keys, true );
378
-	}
379
-
380
-	/**
381
-	 * Set all meta data from array.
382
-	 *
383
-	 * @since 1.0.19
384
-	 * @param array $data Key/Value pairs.
385
-	 */
386
-	public function set_meta_data( $data ) {
387
-		if ( ! empty( $data ) && is_array( $data ) ) {
388
-			$this->maybe_read_meta_data();
389
-			foreach ( $data as $meta ) {
390
-				$meta = (array) $meta;
391
-				if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) {
392
-					$this->meta_data[] = new GetPaid_Meta_Data(
393
-						array(
394
-							'id'    => $meta['id'],
395
-							'key'   => $meta['key'],
396
-							'value' => $meta['value'],
397
-						)
398
-					);
399
-				}
400
-			}
401
-		}
402
-	}
403
-
404
-	/**
405
-	 * Add meta data.
406
-	 *
407
-	 * @since 1.0.19
408
-	 *
409
-	 * @param string       $key Meta key.
410
-	 * @param string|array $value Meta value.
411
-	 * @param bool         $unique Should this be a unique key?.
412
-	 */
413
-	public function add_meta_data( $key, $value, $unique = false ) {
414
-		if ( $this->is_internal_meta_key( $key ) ) {
415
-			$function = 'set_' . $key;
416
-
417
-			if ( is_callable( array( $this, $function ) ) ) {
418
-				return $this->{$function}( $value );
419
-			}
420
-		}
421
-
422
-		$this->maybe_read_meta_data();
423
-		if ( $unique ) {
424
-			$this->delete_meta_data( $key );
425
-		}
426
-		$this->meta_data[] = new GetPaid_Meta_Data(
427
-			array(
428
-				'key'   => $key,
429
-				'value' => $value,
430
-			)
431
-		);
432
-	}
433
-
434
-	/**
435
-	 * Update meta data by key or ID, if provided.
436
-	 *
437
-	 * @since  1.0.19
438
-	 *
439
-	 * @param  string       $key Meta key.
440
-	 * @param  string|array $value Meta value.
441
-	 * @param  int          $meta_id Meta ID.
442
-	 */
443
-	public function update_meta_data( $key, $value, $meta_id = 0 ) {
444
-		if ( $this->is_internal_meta_key( $key ) ) {
445
-			$function = 'set_' . $key;
446
-
447
-			if ( is_callable( array( $this, $function ) ) ) {
448
-				return $this->{$function}( $value );
449
-			}
450
-		}
451
-
452
-		$this->maybe_read_meta_data();
453
-
454
-		$array_key = false;
455
-
456
-		if ( $meta_id ) {
457
-			$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true );
458
-			$array_key  = $array_keys ? current( $array_keys ) : false;
459
-		} else {
460
-			// Find matches by key.
461
-			$matches = array();
462
-			foreach ( $this->meta_data as $meta_data_array_key => $meta ) {
463
-				if ( $meta->key === $key ) {
464
-					$matches[] = $meta_data_array_key;
465
-				}
466
-			}
467
-
468
-			if ( ! empty( $matches ) ) {
469
-				// Set matches to null so only one key gets the new value.
470
-				foreach ( $matches as $meta_data_array_key ) {
471
-					$this->meta_data[ $meta_data_array_key ]->value = null;
472
-				}
473
-				$array_key = current( $matches );
474
-			}
475
-		}
476
-
477
-		if ( false !== $array_key ) {
478
-			$meta        = $this->meta_data[ $array_key ];
479
-			$meta->key   = $key;
480
-			$meta->value = $value;
481
-		} else {
482
-			$this->add_meta_data( $key, $value, true );
483
-		}
484
-	}
485
-
486
-	/**
487
-	 * Delete meta data.
488
-	 *
489
-	 * @since 1.0.19
490
-	 * @param string $key Meta key.
491
-	 */
492
-	public function delete_meta_data( $key ) {
493
-		$this->maybe_read_meta_data();
494
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true );
495
-
496
-		if ( $array_keys ) {
497
-			foreach ( $array_keys as $array_key ) {
498
-				$this->meta_data[ $array_key ]->value = null;
499
-			}
500
-		}
501
-	}
502
-
503
-	/**
504
-	 * Delete meta data.
505
-	 *
506
-	 * @since 1.0.19
507
-	 * @param int $mid Meta ID.
508
-	 */
509
-	public function delete_meta_data_by_mid( $mid ) {
510
-		$this->maybe_read_meta_data();
511
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true );
512
-
513
-		if ( $array_keys ) {
514
-			foreach ( $array_keys as $array_key ) {
515
-				$this->meta_data[ $array_key ]->value = null;
516
-			}
517
-		}
518
-	}
519
-
520
-	/**
521
-	 * Read meta data if null.
522
-	 *
523
-	 * @since 1.0.19
524
-	 */
525
-	protected function maybe_read_meta_data() {
526
-		if ( is_null( $this->meta_data ) ) {
527
-			$this->read_meta_data();
528
-		}
529
-	}
530
-
531
-	/**
532
-	 * Read Meta Data from the database. Ignore any internal properties.
533
-	 * Uses it's own caches because get_metadata does not provide meta_ids.
534
-	 *
535
-	 * @since 1.0.19
536
-	 * @param bool $force_read True to force a new DB read (and update cache).
537
-	 */
538
-	public function read_meta_data( $force_read = false ) {
539
-		$this->meta_data = array();
540
-		$cache_loaded    = false;
541
-
542
-		if ( ! $this->get_id() ) {
543
-			return;
544
-		}
545
-
546
-		if ( ! $this->data_store ) {
547
-			return;
548
-		}
549
-
550
-		if ( ! empty( $this->cache_group ) ) {
551
-			$cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
552
-		}
553
-
554
-		if ( ! $force_read ) {
555
-			if ( ! empty( $this->cache_group ) ) {
556
-				$cached_meta  = wp_cache_get( $cache_key, $this->cache_group );
557
-				$cache_loaded = ! empty( $cached_meta );
558
-			}
559
-		}
560
-
561
-		$raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta( $this );
562
-		if ( $raw_meta_data ) {
563
-			foreach ( $raw_meta_data as $meta ) {
564
-				$this->meta_data[] = new GetPaid_Meta_Data(
565
-					array(
566
-						'id'    => (int) $meta->meta_id,
567
-						'key'   => $meta->meta_key,
568
-						'value' => maybe_unserialize( $meta->meta_value ),
569
-					)
570
-				);
571
-			}
572
-
573
-			if ( ! $cache_loaded && ! empty( $this->cache_group ) ) {
574
-				wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group );
575
-			}
576
-		}
577
-	}
578
-
579
-	/**
580
-	 * Update Meta Data in the database.
581
-	 *
582
-	 * @since 1.0.19
583
-	 */
584
-	public function save_meta_data() {
585
-		if ( ! $this->data_store || is_null( $this->meta_data ) ) {
586
-			return;
587
-		}
588
-		foreach ( $this->meta_data as $array_key => $meta ) {
589
-			if ( is_null( $meta->value ) ) {
590
-				if ( ! empty( $meta->id ) ) {
591
-					$this->data_store->delete_meta( $this, $meta );
592
-					unset( $this->meta_data[ $array_key ] );
593
-				}
594
-			} elseif ( empty( $meta->id ) ) {
595
-				$meta->id = $this->data_store->add_meta( $this, $meta );
596
-				$meta->apply_changes();
597
-			} else {
598
-				if ( $meta->get_changes() ) {
599
-					$this->data_store->update_meta( $this, $meta );
600
-					$meta->apply_changes();
601
-				}
602
-			}
603
-		}
604
-		if ( ! empty( $this->cache_group ) ) {
605
-			$cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
606
-			wp_cache_delete( $cache_key, $this->cache_group );
607
-		}
608
-	}
609
-
610
-	/**
611
-	 * Set ID.
612
-	 *
613
-	 * @since 1.0.19
614
-	 * @param int $id ID.
615
-	 */
616
-	public function set_id( $id ) {
617
-		$this->id = absint( $id );
618
-	}
619
-
620
-	/**
621
-	 * Set all props to default values.
622
-	 *
623
-	 * @since 1.0.19
624
-	 */
625
-	public function set_defaults() {
626
-		$this->data    = $this->default_data;
627
-		$this->changes = array();
628
-		$this->set_object_read( false );
629
-	}
630
-
631
-	/**
632
-	 * Set object read property.
633
-	 *
634
-	 * @since 1.0.19
635
-	 * @param boolean $read Should read?.
636
-	 */
637
-	public function set_object_read( $read = true ) {
638
-		$this->object_read = (bool) $read;
639
-	}
640
-
641
-	/**
642
-	 * Get object read property.
643
-	 *
644
-	 * @since  1.0.19
645
-	 * @return boolean
646
-	 */
647
-	public function get_object_read() {
648
-		return (bool) $this->object_read;
649
-	}
650
-
651
-	/**
652
-	 * Set a collection of props in one go, collect any errors, and return the result.
653
-	 * Only sets using public methods.
654
-	 *
655
-	 * @since  1.0.19
656
-	 *
657
-	 * @param array  $props Key value pairs to set. Key is the prop and should map to a setter function name.
658
-	 * @param string $context In what context to run this.
659
-	 *
660
-	 * @return bool|WP_Error
661
-	 */
662
-	public function set_props( $props, $context = 'set' ) {
663
-		$errors = false;
664
-
665
-		foreach ( $props as $prop => $value ) {
666
-			try {
667
-				/**
668
-				 * Checks if the prop being set is allowed, and the value is not null.
669
-				 */
670
-				if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) {
671
-					continue;
672
-				}
673
-				$setter = "set_$prop";
674
-
675
-				if ( is_callable( array( $this, $setter ) ) ) {
676
-					$this->{$setter}( $value );
677
-				}
678
-			} catch ( Exception $e ) {
679
-				if ( ! $errors ) {
680
-					$errors = new WP_Error();
681
-				}
682
-				$errors->add( $e->getCode(), $e->getMessage() );
683
-				$this->last_error = $e->getMessage();
684
-			}
685
-		}
686
-
687
-		return $errors && count( $errors->get_error_codes() ) ? $errors : true;
688
-	}
689
-
690
-	/**
691
-	 * Sets a prop for a setter method.
692
-	 *
693
-	 * This stores changes in a special array so we can track what needs saving
694
-	 * the the DB later.
695
-	 *
696
-	 * @since 1.0.19
697
-	 * @param string $prop Name of prop to set.
698
-	 * @param mixed  $value Value of the prop.
699
-	 */
700
-	protected function set_prop( $prop, $value ) {
701
-		if ( array_key_exists( $prop, $this->data ) ) {
702
-			if ( true === $this->object_read ) {
703
-				if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) {
704
-					$this->changes[ $prop ] = $value;
705
-				}
706
-			} else {
707
-				$this->data[ $prop ] = $value;
708
-			}
709
-		}
710
-	}
711
-
712
-	/**
713
-	 * Return data changes only.
714
-	 *
715
-	 * @since 1.0.19
716
-	 * @return array
717
-	 */
718
-	public function get_changes() {
719
-		return $this->changes;
720
-	}
721
-
722
-	/**
723
-	 * Merge changes with data and clear.
724
-	 *
725
-	 * @since 1.0.19
726
-	 */
727
-	public function apply_changes() {
728
-		$this->data    = array_replace_recursive( $this->data, $this->changes );
729
-		$this->changes = array();
730
-	}
731
-
732
-	/**
733
-	 * Prefix for action and filter hooks on data.
734
-	 *
735
-	 * @since  1.0.19
736
-	 * @return string
737
-	 */
738
-	protected function get_hook_prefix() {
739
-		return 'wpinv_get_' . $this->object_type . '_';
740
-	}
741
-
742
-	/**
743
-	 * Gets a prop for a getter method.
744
-	 *
745
-	 * Gets the value from either current pending changes, or the data itself.
746
-	 * Context controls what happens to the value before it's returned.
747
-	 *
748
-	 * @since  1.0.19
749
-	 * @param  string $prop Name of prop to get.
750
-	 * @param  string $context What the value is for. Valid values are view and edit.
751
-	 * @return mixed
752
-	 */
753
-	protected function get_prop( $prop, $context = 'view' ) {
754
-		$value = null;
755
-
756
-		if ( array_key_exists( $prop, $this->data ) ) {
757
-			$value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ];
758
-
759
-			if ( 'view' === $context ) {
760
-				$value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );
761
-			}
762
-		}
763
-
764
-		return $value;
765
-	}
766
-
767
-	/**
768
-	 * Sets a date prop whilst handling formatting and datetime objects.
769
-	 *
770
-	 * @since 1.0.19
771
-	 * @param string         $prop Name of prop to set.
772
-	 * @param string|integer $value Value of the prop.
773
-	 */
774
-	protected function set_date_prop( $prop, $value ) {
775
-
776
-		if ( empty( $value ) ) {
777
-			$this->set_prop( $prop, null );
778
-			return;
779
-		}
780
-		$this->set_prop( $prop, $value );
781
-
782
-	}
783
-
784
-	/**
785
-	 * When invalid data is found, throw an exception unless reading from the DB.
786
-	 *
787
-	 * @throws Exception Data Exception.
788
-	 * @since 1.0.19
789
-	 * @param string $code             Error code.
790
-	 * @param string $message          Error message.
791
-	 */
792
-	protected function error( $code, $message ) {
793
-		throw new Exception( $message, $code );
794
-	}
24
+    /**
25
+     * ID for this object.
26
+     *
27
+     * @since 1.0.19
28
+     * @var int
29
+     */
30
+    protected $id = 0;
31
+
32
+    /**
33
+     * Core data for this object. Name value pairs (name + default value).
34
+     *
35
+     * @since 1.0.19
36
+     * @var array
37
+     */
38
+    protected $data = array();
39
+
40
+    /**
41
+     * Core data changes for this object.
42
+     *
43
+     * @since 1.0.19
44
+     * @var array
45
+     */
46
+    protected $changes = array();
47
+
48
+    /**
49
+     * This is false until the object is read from the DB.
50
+     *
51
+     * @since 1.0.19
52
+     * @var bool
53
+     */
54
+    protected $object_read = false;
55
+
56
+    /**
57
+     * This is the name of this object type.
58
+     *
59
+     * @since 1.0.19
60
+     * @var string
61
+     */
62
+    protected $object_type = 'data';
63
+
64
+    /**
65
+     * Extra data for this object. Name value pairs (name + default value).
66
+     * Used as a standard way for sub classes (like item types) to add
67
+     * additional information to an inherited class.
68
+     *
69
+     * @since 1.0.19
70
+     * @var array
71
+     */
72
+    protected $extra_data = array();
73
+
74
+    /**
75
+     * Set to _data on construct so we can track and reset data if needed.
76
+     *
77
+     * @since 1.0.19
78
+     * @var array
79
+     */
80
+    protected $default_data = array();
81
+
82
+    /**
83
+     * Contains a reference to the data store for this class.
84
+     *
85
+     * @since 1.0.19
86
+     * @var GetPaid_Data_Store
87
+     */
88
+    protected $data_store;
89
+
90
+    /**
91
+     * Stores meta in cache for future reads.
92
+     * A group must be set to to enable caching.
93
+     *
94
+     * @since 1.0.19
95
+     * @var string
96
+     */
97
+    protected $cache_group = '';
98
+
99
+    /**
100
+     * Stores the last error.
101
+     *
102
+     * @since 1.0.19
103
+     * @var string
104
+     */
105
+    public $last_error = '';
106
+
107
+    /**
108
+     * Stores additional meta data.
109
+     *
110
+     * @since 1.0.19
111
+     * @var array
112
+     */
113
+    protected $meta_data = null;
114
+
115
+    /**
116
+     * Default constructor.
117
+     *
118
+     * @param int|object|array $read ID to load from the DB (optional) or already queried data.
119
+     */
120
+    public function __construct( $read = 0 ) {
121
+        $this->data         = array_merge( $this->data, $this->extra_data );
122
+        $this->default_data = $this->data;
123
+    }
124
+
125
+    /**
126
+     * Only store the object ID to avoid serializing the data object instance.
127
+     *
128
+     * @return array
129
+     */
130
+    public function __sleep() {
131
+        return array( 'id' );
132
+    }
133
+
134
+    /**
135
+     * Re-run the constructor with the object ID.
136
+     *
137
+     * If the object no longer exists, remove the ID.
138
+     */
139
+    public function __wakeup() {
140
+        try {
141
+            $this->__construct( absint( $this->id ) );
142
+        } catch ( Exception $e ) {
143
+            $this->set_id( 0 );
144
+            $this->set_object_read( true );
145
+        }
146
+    }
147
+
148
+    /**
149
+     * When the object is cloned, make sure meta is duplicated correctly.
150
+     *
151
+     * @since 1.0.19
152
+     */
153
+    public function __clone() {
154
+        $this->maybe_read_meta_data();
155
+        if ( ! empty( $this->meta_data ) ) {
156
+            foreach ( $this->meta_data as $array_key => $meta ) {
157
+                $this->meta_data[ $array_key ] = clone $meta;
158
+                if ( ! empty( $meta->id ) ) {
159
+                    $this->meta_data[ $array_key ]->id = null;
160
+                }
161
+            }
162
+        }
163
+    }
164
+
165
+    /**
166
+     * Get the data store.
167
+     *
168
+     * @since  1.0.19
169
+     * @return object
170
+     */
171
+    public function get_data_store() {
172
+        return $this->data_store;
173
+    }
174
+
175
+    /**
176
+     * Returns the unique ID for this object.
177
+     *
178
+     * @since  1.0.19
179
+     * @return int
180
+     */
181
+    public function get_id() {
182
+        return $this->id;
183
+    }
184
+
185
+    /**
186
+     * Delete an object, set the ID to 0, and return result.
187
+     *
188
+     * @since  1.0.19
189
+     * @param  bool $force_delete Should the data be deleted permanently.
190
+     * @return bool result
191
+     */
192
+    public function delete( $force_delete = false ) {
193
+        if ( $this->data_store ) {
194
+            $this->data_store->delete( $this, array( 'force_delete' => $force_delete ) );
195
+            $this->set_id( 0 );
196
+            return true;
197
+        }
198
+        return false;
199
+    }
200
+
201
+    /**
202
+     * Save should create or update based on object existence.
203
+     *
204
+     * @since  1.0.19
205
+     * @return int
206
+     */
207
+    public function save() {
208
+        if ( ! $this->data_store ) {
209
+            return $this->get_id();
210
+        }
211
+
212
+        /**
213
+         * Trigger action before saving to the DB. Allows you to adjust object props before save.
214
+         *
215
+         * @param GetPaid_Data          $this The object being saved.
216
+         * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
217
+         */
218
+        do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store );
219
+
220
+        if ( $this->get_id() ) {
221
+            $this->data_store->update( $this );
222
+        } else {
223
+            $this->data_store->create( $this );
224
+        }
225
+
226
+        /**
227
+         * Trigger action after saving to the DB.
228
+         *
229
+         * @param GetPaid_Data          $this The object being saved.
230
+         * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
231
+         */
232
+        do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store );
233
+
234
+        return $this->get_id();
235
+    }
236
+
237
+    /**
238
+     * Change data to JSON format.
239
+     *
240
+     * @since  1.0.19
241
+     * @return string Data in JSON format.
242
+     */
243
+    public function __toString() {
244
+        return wp_json_encode( $this->get_data() );
245
+    }
246
+
247
+    /**
248
+     * Returns all data for this object.
249
+     *
250
+     * @since  1.0.19
251
+     * @return array
252
+     */
253
+    public function get_data() {
254
+        return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) );
255
+    }
256
+
257
+    /**
258
+     * Returns array of expected data keys for this object.
259
+     *
260
+     * @since   1.0.19
261
+     * @return array
262
+     */
263
+    public function get_data_keys() {
264
+        return array_keys( $this->data );
265
+    }
266
+
267
+    /**
268
+     * Returns all "extra" data keys for an object (for sub objects like item types).
269
+     *
270
+     * @since  1.0.19
271
+     * @return array
272
+     */
273
+    public function get_extra_data_keys() {
274
+        return array_keys( $this->extra_data );
275
+    }
276
+
277
+    /**
278
+     * Filter null meta values from array.
279
+     *
280
+     * @since  1.0.19
281
+     * @param mixed $meta Meta value to check.
282
+     * @return bool
283
+     */
284
+    protected function filter_null_meta( $meta ) {
285
+        return ! is_null( $meta->value );
286
+    }
287
+
288
+    /**
289
+     * Get All Meta Data.
290
+     *
291
+     * @since 1.0.19
292
+     * @return array of objects.
293
+     */
294
+    public function get_meta_data() {
295
+        $this->maybe_read_meta_data();
296
+        return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) );
297
+    }
298
+
299
+    /**
300
+     * Check if the key is an internal one.
301
+     *
302
+     * @since  1.0.19
303
+     * @param  string $key Key to check.
304
+     * @return bool   true if it's an internal key, false otherwise
305
+     */
306
+    protected function is_internal_meta_key( $key ) {
307
+        $internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true );
308
+
309
+        if ( ! $internal_meta_key ) {
310
+            return false;
311
+        }
312
+
313
+        $has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) );
314
+
315
+        if ( ! $has_setter_or_getter ) {
316
+            return false;
317
+        }
318
+
319
+        /* translators: %s: $key Key to check */
320
+        getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
321
+
322
+        return true;
323
+    }
324
+
325
+    /**
326
+     * Get Meta Data by Key.
327
+     *
328
+     * @since  1.0.19
329
+     * @param  string $key Meta Key.
330
+     * @param  bool   $single return first found meta with key, or all with $key.
331
+     * @param  string $context What the value is for. Valid values are view and edit.
332
+     * @return mixed
333
+     */
334
+    public function get_meta( $key = '', $single = true, $context = 'view' ) {
335
+
336
+        // Check if this is an internal meta key.
337
+        if ( $this->is_internal_meta_key( $key ) ) {
338
+            $function = 'get_' . $key;
339
+
340
+            if ( is_callable( array( $this, $function ) ) ) {
341
+                return $this->{$function}();
342
+            }
343
+        }
344
+
345
+        // Read the meta data if not yet read.
346
+        $this->maybe_read_meta_data();
347
+        $meta_data  = $this->get_meta_data();
348
+        $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true );
349
+        $value      = $single ? '' : array();
350
+
351
+        if ( ! empty( $array_keys ) ) {
352
+            // We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()).
353
+            if ( $single ) {
354
+                $value = $meta_data[ current( $array_keys ) ]->value;
355
+            } else {
356
+                $value = array_intersect_key( $meta_data, array_flip( $array_keys ) );
357
+            }
358
+        }
359
+
360
+        if ( 'view' === $context ) {
361
+            $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this );
362
+        }
363
+
364
+        return $value;
365
+    }
366
+
367
+    /**
368
+     * See if meta data exists, since get_meta always returns a '' or array().
369
+     *
370
+     * @since  1.0.19
371
+     * @param  string $key Meta Key.
372
+     * @return boolean
373
+     */
374
+    public function meta_exists( $key = '' ) {
375
+        $this->maybe_read_meta_data();
376
+        $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' );
377
+        return in_array( $key, $array_keys, true );
378
+    }
379
+
380
+    /**
381
+     * Set all meta data from array.
382
+     *
383
+     * @since 1.0.19
384
+     * @param array $data Key/Value pairs.
385
+     */
386
+    public function set_meta_data( $data ) {
387
+        if ( ! empty( $data ) && is_array( $data ) ) {
388
+            $this->maybe_read_meta_data();
389
+            foreach ( $data as $meta ) {
390
+                $meta = (array) $meta;
391
+                if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) {
392
+                    $this->meta_data[] = new GetPaid_Meta_Data(
393
+                        array(
394
+                            'id'    => $meta['id'],
395
+                            'key'   => $meta['key'],
396
+                            'value' => $meta['value'],
397
+                        )
398
+                    );
399
+                }
400
+            }
401
+        }
402
+    }
403
+
404
+    /**
405
+     * Add meta data.
406
+     *
407
+     * @since 1.0.19
408
+     *
409
+     * @param string       $key Meta key.
410
+     * @param string|array $value Meta value.
411
+     * @param bool         $unique Should this be a unique key?.
412
+     */
413
+    public function add_meta_data( $key, $value, $unique = false ) {
414
+        if ( $this->is_internal_meta_key( $key ) ) {
415
+            $function = 'set_' . $key;
416
+
417
+            if ( is_callable( array( $this, $function ) ) ) {
418
+                return $this->{$function}( $value );
419
+            }
420
+        }
421
+
422
+        $this->maybe_read_meta_data();
423
+        if ( $unique ) {
424
+            $this->delete_meta_data( $key );
425
+        }
426
+        $this->meta_data[] = new GetPaid_Meta_Data(
427
+            array(
428
+                'key'   => $key,
429
+                'value' => $value,
430
+            )
431
+        );
432
+    }
433
+
434
+    /**
435
+     * Update meta data by key or ID, if provided.
436
+     *
437
+     * @since  1.0.19
438
+     *
439
+     * @param  string       $key Meta key.
440
+     * @param  string|array $value Meta value.
441
+     * @param  int          $meta_id Meta ID.
442
+     */
443
+    public function update_meta_data( $key, $value, $meta_id = 0 ) {
444
+        if ( $this->is_internal_meta_key( $key ) ) {
445
+            $function = 'set_' . $key;
446
+
447
+            if ( is_callable( array( $this, $function ) ) ) {
448
+                return $this->{$function}( $value );
449
+            }
450
+        }
451
+
452
+        $this->maybe_read_meta_data();
453
+
454
+        $array_key = false;
455
+
456
+        if ( $meta_id ) {
457
+            $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true );
458
+            $array_key  = $array_keys ? current( $array_keys ) : false;
459
+        } else {
460
+            // Find matches by key.
461
+            $matches = array();
462
+            foreach ( $this->meta_data as $meta_data_array_key => $meta ) {
463
+                if ( $meta->key === $key ) {
464
+                    $matches[] = $meta_data_array_key;
465
+                }
466
+            }
467
+
468
+            if ( ! empty( $matches ) ) {
469
+                // Set matches to null so only one key gets the new value.
470
+                foreach ( $matches as $meta_data_array_key ) {
471
+                    $this->meta_data[ $meta_data_array_key ]->value = null;
472
+                }
473
+                $array_key = current( $matches );
474
+            }
475
+        }
476
+
477
+        if ( false !== $array_key ) {
478
+            $meta        = $this->meta_data[ $array_key ];
479
+            $meta->key   = $key;
480
+            $meta->value = $value;
481
+        } else {
482
+            $this->add_meta_data( $key, $value, true );
483
+        }
484
+    }
485
+
486
+    /**
487
+     * Delete meta data.
488
+     *
489
+     * @since 1.0.19
490
+     * @param string $key Meta key.
491
+     */
492
+    public function delete_meta_data( $key ) {
493
+        $this->maybe_read_meta_data();
494
+        $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true );
495
+
496
+        if ( $array_keys ) {
497
+            foreach ( $array_keys as $array_key ) {
498
+                $this->meta_data[ $array_key ]->value = null;
499
+            }
500
+        }
501
+    }
502
+
503
+    /**
504
+     * Delete meta data.
505
+     *
506
+     * @since 1.0.19
507
+     * @param int $mid Meta ID.
508
+     */
509
+    public function delete_meta_data_by_mid( $mid ) {
510
+        $this->maybe_read_meta_data();
511
+        $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true );
512
+
513
+        if ( $array_keys ) {
514
+            foreach ( $array_keys as $array_key ) {
515
+                $this->meta_data[ $array_key ]->value = null;
516
+            }
517
+        }
518
+    }
519
+
520
+    /**
521
+     * Read meta data if null.
522
+     *
523
+     * @since 1.0.19
524
+     */
525
+    protected function maybe_read_meta_data() {
526
+        if ( is_null( $this->meta_data ) ) {
527
+            $this->read_meta_data();
528
+        }
529
+    }
530
+
531
+    /**
532
+     * Read Meta Data from the database. Ignore any internal properties.
533
+     * Uses it's own caches because get_metadata does not provide meta_ids.
534
+     *
535
+     * @since 1.0.19
536
+     * @param bool $force_read True to force a new DB read (and update cache).
537
+     */
538
+    public function read_meta_data( $force_read = false ) {
539
+        $this->meta_data = array();
540
+        $cache_loaded    = false;
541
+
542
+        if ( ! $this->get_id() ) {
543
+            return;
544
+        }
545
+
546
+        if ( ! $this->data_store ) {
547
+            return;
548
+        }
549
+
550
+        if ( ! empty( $this->cache_group ) ) {
551
+            $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
552
+        }
553
+
554
+        if ( ! $force_read ) {
555
+            if ( ! empty( $this->cache_group ) ) {
556
+                $cached_meta  = wp_cache_get( $cache_key, $this->cache_group );
557
+                $cache_loaded = ! empty( $cached_meta );
558
+            }
559
+        }
560
+
561
+        $raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta( $this );
562
+        if ( $raw_meta_data ) {
563
+            foreach ( $raw_meta_data as $meta ) {
564
+                $this->meta_data[] = new GetPaid_Meta_Data(
565
+                    array(
566
+                        'id'    => (int) $meta->meta_id,
567
+                        'key'   => $meta->meta_key,
568
+                        'value' => maybe_unserialize( $meta->meta_value ),
569
+                    )
570
+                );
571
+            }
572
+
573
+            if ( ! $cache_loaded && ! empty( $this->cache_group ) ) {
574
+                wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group );
575
+            }
576
+        }
577
+    }
578
+
579
+    /**
580
+     * Update Meta Data in the database.
581
+     *
582
+     * @since 1.0.19
583
+     */
584
+    public function save_meta_data() {
585
+        if ( ! $this->data_store || is_null( $this->meta_data ) ) {
586
+            return;
587
+        }
588
+        foreach ( $this->meta_data as $array_key => $meta ) {
589
+            if ( is_null( $meta->value ) ) {
590
+                if ( ! empty( $meta->id ) ) {
591
+                    $this->data_store->delete_meta( $this, $meta );
592
+                    unset( $this->meta_data[ $array_key ] );
593
+                }
594
+            } elseif ( empty( $meta->id ) ) {
595
+                $meta->id = $this->data_store->add_meta( $this, $meta );
596
+                $meta->apply_changes();
597
+            } else {
598
+                if ( $meta->get_changes() ) {
599
+                    $this->data_store->update_meta( $this, $meta );
600
+                    $meta->apply_changes();
601
+                }
602
+            }
603
+        }
604
+        if ( ! empty( $this->cache_group ) ) {
605
+            $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
606
+            wp_cache_delete( $cache_key, $this->cache_group );
607
+        }
608
+    }
609
+
610
+    /**
611
+     * Set ID.
612
+     *
613
+     * @since 1.0.19
614
+     * @param int $id ID.
615
+     */
616
+    public function set_id( $id ) {
617
+        $this->id = absint( $id );
618
+    }
619
+
620
+    /**
621
+     * Set all props to default values.
622
+     *
623
+     * @since 1.0.19
624
+     */
625
+    public function set_defaults() {
626
+        $this->data    = $this->default_data;
627
+        $this->changes = array();
628
+        $this->set_object_read( false );
629
+    }
630
+
631
+    /**
632
+     * Set object read property.
633
+     *
634
+     * @since 1.0.19
635
+     * @param boolean $read Should read?.
636
+     */
637
+    public function set_object_read( $read = true ) {
638
+        $this->object_read = (bool) $read;
639
+    }
640
+
641
+    /**
642
+     * Get object read property.
643
+     *
644
+     * @since  1.0.19
645
+     * @return boolean
646
+     */
647
+    public function get_object_read() {
648
+        return (bool) $this->object_read;
649
+    }
650
+
651
+    /**
652
+     * Set a collection of props in one go, collect any errors, and return the result.
653
+     * Only sets using public methods.
654
+     *
655
+     * @since  1.0.19
656
+     *
657
+     * @param array  $props Key value pairs to set. Key is the prop and should map to a setter function name.
658
+     * @param string $context In what context to run this.
659
+     *
660
+     * @return bool|WP_Error
661
+     */
662
+    public function set_props( $props, $context = 'set' ) {
663
+        $errors = false;
664
+
665
+        foreach ( $props as $prop => $value ) {
666
+            try {
667
+                /**
668
+                 * Checks if the prop being set is allowed, and the value is not null.
669
+                 */
670
+                if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) {
671
+                    continue;
672
+                }
673
+                $setter = "set_$prop";
674
+
675
+                if ( is_callable( array( $this, $setter ) ) ) {
676
+                    $this->{$setter}( $value );
677
+                }
678
+            } catch ( Exception $e ) {
679
+                if ( ! $errors ) {
680
+                    $errors = new WP_Error();
681
+                }
682
+                $errors->add( $e->getCode(), $e->getMessage() );
683
+                $this->last_error = $e->getMessage();
684
+            }
685
+        }
686
+
687
+        return $errors && count( $errors->get_error_codes() ) ? $errors : true;
688
+    }
689
+
690
+    /**
691
+     * Sets a prop for a setter method.
692
+     *
693
+     * This stores changes in a special array so we can track what needs saving
694
+     * the the DB later.
695
+     *
696
+     * @since 1.0.19
697
+     * @param string $prop Name of prop to set.
698
+     * @param mixed  $value Value of the prop.
699
+     */
700
+    protected function set_prop( $prop, $value ) {
701
+        if ( array_key_exists( $prop, $this->data ) ) {
702
+            if ( true === $this->object_read ) {
703
+                if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) {
704
+                    $this->changes[ $prop ] = $value;
705
+                }
706
+            } else {
707
+                $this->data[ $prop ] = $value;
708
+            }
709
+        }
710
+    }
711
+
712
+    /**
713
+     * Return data changes only.
714
+     *
715
+     * @since 1.0.19
716
+     * @return array
717
+     */
718
+    public function get_changes() {
719
+        return $this->changes;
720
+    }
721
+
722
+    /**
723
+     * Merge changes with data and clear.
724
+     *
725
+     * @since 1.0.19
726
+     */
727
+    public function apply_changes() {
728
+        $this->data    = array_replace_recursive( $this->data, $this->changes );
729
+        $this->changes = array();
730
+    }
731
+
732
+    /**
733
+     * Prefix for action and filter hooks on data.
734
+     *
735
+     * @since  1.0.19
736
+     * @return string
737
+     */
738
+    protected function get_hook_prefix() {
739
+        return 'wpinv_get_' . $this->object_type . '_';
740
+    }
741
+
742
+    /**
743
+     * Gets a prop for a getter method.
744
+     *
745
+     * Gets the value from either current pending changes, or the data itself.
746
+     * Context controls what happens to the value before it's returned.
747
+     *
748
+     * @since  1.0.19
749
+     * @param  string $prop Name of prop to get.
750
+     * @param  string $context What the value is for. Valid values are view and edit.
751
+     * @return mixed
752
+     */
753
+    protected function get_prop( $prop, $context = 'view' ) {
754
+        $value = null;
755
+
756
+        if ( array_key_exists( $prop, $this->data ) ) {
757
+            $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ];
758
+
759
+            if ( 'view' === $context ) {
760
+                $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );
761
+            }
762
+        }
763
+
764
+        return $value;
765
+    }
766
+
767
+    /**
768
+     * Sets a date prop whilst handling formatting and datetime objects.
769
+     *
770
+     * @since 1.0.19
771
+     * @param string         $prop Name of prop to set.
772
+     * @param string|integer $value Value of the prop.
773
+     */
774
+    protected function set_date_prop( $prop, $value ) {
775
+
776
+        if ( empty( $value ) ) {
777
+            $this->set_prop( $prop, null );
778
+            return;
779
+        }
780
+        $this->set_prop( $prop, $value );
781
+
782
+    }
783
+
784
+    /**
785
+     * When invalid data is found, throw an exception unless reading from the DB.
786
+     *
787
+     * @throws Exception Data Exception.
788
+     * @since 1.0.19
789
+     * @param string $code             Error code.
790
+     * @param string $message          Error message.
791
+     */
792
+    protected function error( $code, $message ) {
793
+        throw new Exception( $message, $code );
794
+    }
795 795
 }
Please login to merge, or discard this patch.
Spacing   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  *
9 9
  */
10 10
 
11
-if ( ! defined( 'ABSPATH' ) ) {
11
+if (!defined('ABSPATH')) {
12 12
 	exit;
13 13
 }
14 14
 
@@ -117,8 +117,8 @@  discard block
 block discarded – undo
117 117
 	 *
118 118
 	 * @param int|object|array $read ID to load from the DB (optional) or already queried data.
119 119
 	 */
120
-	public function __construct( $read = 0 ) {
121
-		$this->data         = array_merge( $this->data, $this->extra_data );
120
+	public function __construct($read = 0) {
121
+		$this->data         = array_merge($this->data, $this->extra_data);
122 122
 		$this->default_data = $this->data;
123 123
 	}
124 124
 
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 	 * @return array
129 129
 	 */
130 130
 	public function __sleep() {
131
-		return array( 'id' );
131
+		return array('id');
132 132
 	}
133 133
 
134 134
 	/**
@@ -138,10 +138,10 @@  discard block
 block discarded – undo
138 138
 	 */
139 139
 	public function __wakeup() {
140 140
 		try {
141
-			$this->__construct( absint( $this->id ) );
142
-		} catch ( Exception $e ) {
143
-			$this->set_id( 0 );
144
-			$this->set_object_read( true );
141
+			$this->__construct(absint($this->id));
142
+		} catch (Exception $e) {
143
+			$this->set_id(0);
144
+			$this->set_object_read(true);
145 145
 		}
146 146
 	}
147 147
 
@@ -152,11 +152,11 @@  discard block
 block discarded – undo
152 152
 	 */
153 153
 	public function __clone() {
154 154
 		$this->maybe_read_meta_data();
155
-		if ( ! empty( $this->meta_data ) ) {
156
-			foreach ( $this->meta_data as $array_key => $meta ) {
157
-				$this->meta_data[ $array_key ] = clone $meta;
158
-				if ( ! empty( $meta->id ) ) {
159
-					$this->meta_data[ $array_key ]->id = null;
155
+		if (!empty($this->meta_data)) {
156
+			foreach ($this->meta_data as $array_key => $meta) {
157
+				$this->meta_data[$array_key] = clone $meta;
158
+				if (!empty($meta->id)) {
159
+					$this->meta_data[$array_key]->id = null;
160 160
 				}
161 161
 			}
162 162
 		}
@@ -189,10 +189,10 @@  discard block
 block discarded – undo
189 189
 	 * @param  bool $force_delete Should the data be deleted permanently.
190 190
 	 * @return bool result
191 191
 	 */
192
-	public function delete( $force_delete = false ) {
193
-		if ( $this->data_store ) {
194
-			$this->data_store->delete( $this, array( 'force_delete' => $force_delete ) );
195
-			$this->set_id( 0 );
192
+	public function delete($force_delete = false) {
193
+		if ($this->data_store) {
194
+			$this->data_store->delete($this, array('force_delete' => $force_delete));
195
+			$this->set_id(0);
196 196
 			return true;
197 197
 		}
198 198
 		return false;
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
 	 * @return int
206 206
 	 */
207 207
 	public function save() {
208
-		if ( ! $this->data_store ) {
208
+		if (!$this->data_store) {
209 209
 			return $this->get_id();
210 210
 		}
211 211
 
@@ -215,12 +215,12 @@  discard block
 block discarded – undo
215 215
 		 * @param GetPaid_Data          $this The object being saved.
216 216
 		 * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
217 217
 		 */
218
-		do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store );
218
+		do_action('getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store);
219 219
 
220
-		if ( $this->get_id() ) {
221
-			$this->data_store->update( $this );
220
+		if ($this->get_id()) {
221
+			$this->data_store->update($this);
222 222
 		} else {
223
-			$this->data_store->create( $this );
223
+			$this->data_store->create($this);
224 224
 		}
225 225
 
226 226
 		/**
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 		 * @param GetPaid_Data          $this The object being saved.
230 230
 		 * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
231 231
 		 */
232
-		do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store );
232
+		do_action('getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store);
233 233
 
234 234
 		return $this->get_id();
235 235
 	}
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 	 * @return string Data in JSON format.
242 242
 	 */
243 243
 	public function __toString() {
244
-		return wp_json_encode( $this->get_data() );
244
+		return wp_json_encode($this->get_data());
245 245
 	}
246 246
 
247 247
 	/**
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
 	 * @return array
252 252
 	 */
253 253
 	public function get_data() {
254
-		return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) );
254
+		return array_merge(array('id' => $this->get_id()), $this->data, array('meta_data' => $this->get_meta_data()));
255 255
 	}
256 256
 
257 257
 	/**
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
 	 * @return array
262 262
 	 */
263 263
 	public function get_data_keys() {
264
-		return array_keys( $this->data );
264
+		return array_keys($this->data);
265 265
 	}
266 266
 
267 267
 	/**
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 	 * @return array
272 272
 	 */
273 273
 	public function get_extra_data_keys() {
274
-		return array_keys( $this->extra_data );
274
+		return array_keys($this->extra_data);
275 275
 	}
276 276
 
277 277
 	/**
@@ -281,8 +281,8 @@  discard block
 block discarded – undo
281 281
 	 * @param mixed $meta Meta value to check.
282 282
 	 * @return bool
283 283
 	 */
284
-	protected function filter_null_meta( $meta ) {
285
-		return ! is_null( $meta->value );
284
+	protected function filter_null_meta($meta) {
285
+		return !is_null($meta->value);
286 286
 	}
287 287
 
288 288
 	/**
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
 	 */
294 294
 	public function get_meta_data() {
295 295
 		$this->maybe_read_meta_data();
296
-		return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) );
296
+		return array_values(array_filter($this->meta_data, array($this, 'filter_null_meta')));
297 297
 	}
298 298
 
299 299
 	/**
@@ -303,21 +303,21 @@  discard block
 block discarded – undo
303 303
 	 * @param  string $key Key to check.
304 304
 	 * @return bool   true if it's an internal key, false otherwise
305 305
 	 */
306
-	protected function is_internal_meta_key( $key ) {
307
-		$internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true );
306
+	protected function is_internal_meta_key($key) {
307
+		$internal_meta_key = !empty($key) && $this->data_store && in_array($key, $this->data_store->get_internal_meta_keys(), true);
308 308
 
309
-		if ( ! $internal_meta_key ) {
309
+		if (!$internal_meta_key) {
310 310
 			return false;
311 311
 		}
312 312
 
313
-		$has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) );
313
+		$has_setter_or_getter = is_callable(array($this, 'set_' . $key)) || is_callable(array($this, 'get_' . $key));
314 314
 
315
-		if ( ! $has_setter_or_getter ) {
315
+		if (!$has_setter_or_getter) {
316 316
 			return false;
317 317
 		}
318 318
 
319 319
 		/* translators: %s: $key Key to check */
320
-		getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
320
+		getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid'), $key), '1.0.19');
321 321
 
322 322
 		return true;
323 323
 	}
@@ -331,13 +331,13 @@  discard block
 block discarded – undo
331 331
 	 * @param  string $context What the value is for. Valid values are view and edit.
332 332
 	 * @return mixed
333 333
 	 */
334
-	public function get_meta( $key = '', $single = true, $context = 'view' ) {
334
+	public function get_meta($key = '', $single = true, $context = 'view') {
335 335
 
336 336
 		// Check if this is an internal meta key.
337
-		if ( $this->is_internal_meta_key( $key ) ) {
337
+		if ($this->is_internal_meta_key($key)) {
338 338
 			$function = 'get_' . $key;
339 339
 
340
-			if ( is_callable( array( $this, $function ) ) ) {
340
+			if (is_callable(array($this, $function))) {
341 341
 				return $this->{$function}();
342 342
 			}
343 343
 		}
@@ -345,20 +345,20 @@  discard block
 block discarded – undo
345 345
 		// Read the meta data if not yet read.
346 346
 		$this->maybe_read_meta_data();
347 347
 		$meta_data  = $this->get_meta_data();
348
-		$array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true );
348
+		$array_keys = array_keys(wp_list_pluck($meta_data, 'key'), $key, true);
349 349
 		$value      = $single ? '' : array();
350 350
 
351
-		if ( ! empty( $array_keys ) ) {
351
+		if (!empty($array_keys)) {
352 352
 			// We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()).
353
-			if ( $single ) {
354
-				$value = $meta_data[ current( $array_keys ) ]->value;
353
+			if ($single) {
354
+				$value = $meta_data[current($array_keys)]->value;
355 355
 			} else {
356
-				$value = array_intersect_key( $meta_data, array_flip( $array_keys ) );
356
+				$value = array_intersect_key($meta_data, array_flip($array_keys));
357 357
 			}
358 358
 		}
359 359
 
360
-		if ( 'view' === $context ) {
361
-			$value = apply_filters( $this->get_hook_prefix() . $key, $value, $this );
360
+		if ('view' === $context) {
361
+			$value = apply_filters($this->get_hook_prefix() . $key, $value, $this);
362 362
 		}
363 363
 
364 364
 		return $value;
@@ -371,10 +371,10 @@  discard block
 block discarded – undo
371 371
 	 * @param  string $key Meta Key.
372 372
 	 * @return boolean
373 373
 	 */
374
-	public function meta_exists( $key = '' ) {
374
+	public function meta_exists($key = '') {
375 375
 		$this->maybe_read_meta_data();
376
-		$array_keys = wp_list_pluck( $this->get_meta_data(), 'key' );
377
-		return in_array( $key, $array_keys, true );
376
+		$array_keys = wp_list_pluck($this->get_meta_data(), 'key');
377
+		return in_array($key, $array_keys, true);
378 378
 	}
379 379
 
380 380
 	/**
@@ -383,12 +383,12 @@  discard block
 block discarded – undo
383 383
 	 * @since 1.0.19
384 384
 	 * @param array $data Key/Value pairs.
385 385
 	 */
386
-	public function set_meta_data( $data ) {
387
-		if ( ! empty( $data ) && is_array( $data ) ) {
386
+	public function set_meta_data($data) {
387
+		if (!empty($data) && is_array($data)) {
388 388
 			$this->maybe_read_meta_data();
389
-			foreach ( $data as $meta ) {
389
+			foreach ($data as $meta) {
390 390
 				$meta = (array) $meta;
391
-				if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) {
391
+				if (isset($meta['key'], $meta['value'], $meta['id'])) {
392 392
 					$this->meta_data[] = new GetPaid_Meta_Data(
393 393
 						array(
394 394
 							'id'    => $meta['id'],
@@ -410,18 +410,18 @@  discard block
 block discarded – undo
410 410
 	 * @param string|array $value Meta value.
411 411
 	 * @param bool         $unique Should this be a unique key?.
412 412
 	 */
413
-	public function add_meta_data( $key, $value, $unique = false ) {
414
-		if ( $this->is_internal_meta_key( $key ) ) {
413
+	public function add_meta_data($key, $value, $unique = false) {
414
+		if ($this->is_internal_meta_key($key)) {
415 415
 			$function = 'set_' . $key;
416 416
 
417
-			if ( is_callable( array( $this, $function ) ) ) {
418
-				return $this->{$function}( $value );
417
+			if (is_callable(array($this, $function))) {
418
+				return $this->{$function}($value);
419 419
 			}
420 420
 		}
421 421
 
422 422
 		$this->maybe_read_meta_data();
423
-		if ( $unique ) {
424
-			$this->delete_meta_data( $key );
423
+		if ($unique) {
424
+			$this->delete_meta_data($key);
425 425
 		}
426 426
 		$this->meta_data[] = new GetPaid_Meta_Data(
427 427
 			array(
@@ -440,12 +440,12 @@  discard block
 block discarded – undo
440 440
 	 * @param  string|array $value Meta value.
441 441
 	 * @param  int          $meta_id Meta ID.
442 442
 	 */
443
-	public function update_meta_data( $key, $value, $meta_id = 0 ) {
444
-		if ( $this->is_internal_meta_key( $key ) ) {
443
+	public function update_meta_data($key, $value, $meta_id = 0) {
444
+		if ($this->is_internal_meta_key($key)) {
445 445
 			$function = 'set_' . $key;
446 446
 
447
-			if ( is_callable( array( $this, $function ) ) ) {
448
-				return $this->{$function}( $value );
447
+			if (is_callable(array($this, $function))) {
448
+				return $this->{$function}($value);
449 449
 			}
450 450
 		}
451 451
 
@@ -453,33 +453,33 @@  discard block
 block discarded – undo
453 453
 
454 454
 		$array_key = false;
455 455
 
456
-		if ( $meta_id ) {
457
-			$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true );
458
-			$array_key  = $array_keys ? current( $array_keys ) : false;
456
+		if ($meta_id) {
457
+			$array_keys = array_keys(wp_list_pluck($this->meta_data, 'id'), $meta_id, true);
458
+			$array_key  = $array_keys ? current($array_keys) : false;
459 459
 		} else {
460 460
 			// Find matches by key.
461 461
 			$matches = array();
462
-			foreach ( $this->meta_data as $meta_data_array_key => $meta ) {
463
-				if ( $meta->key === $key ) {
462
+			foreach ($this->meta_data as $meta_data_array_key => $meta) {
463
+				if ($meta->key === $key) {
464 464
 					$matches[] = $meta_data_array_key;
465 465
 				}
466 466
 			}
467 467
 
468
-			if ( ! empty( $matches ) ) {
468
+			if (!empty($matches)) {
469 469
 				// Set matches to null so only one key gets the new value.
470
-				foreach ( $matches as $meta_data_array_key ) {
471
-					$this->meta_data[ $meta_data_array_key ]->value = null;
470
+				foreach ($matches as $meta_data_array_key) {
471
+					$this->meta_data[$meta_data_array_key]->value = null;
472 472
 				}
473
-				$array_key = current( $matches );
473
+				$array_key = current($matches);
474 474
 			}
475 475
 		}
476 476
 
477
-		if ( false !== $array_key ) {
478
-			$meta        = $this->meta_data[ $array_key ];
477
+		if (false !== $array_key) {
478
+			$meta        = $this->meta_data[$array_key];
479 479
 			$meta->key   = $key;
480 480
 			$meta->value = $value;
481 481
 		} else {
482
-			$this->add_meta_data( $key, $value, true );
482
+			$this->add_meta_data($key, $value, true);
483 483
 		}
484 484
 	}
485 485
 
@@ -489,13 +489,13 @@  discard block
 block discarded – undo
489 489
 	 * @since 1.0.19
490 490
 	 * @param string $key Meta key.
491 491
 	 */
492
-	public function delete_meta_data( $key ) {
492
+	public function delete_meta_data($key) {
493 493
 		$this->maybe_read_meta_data();
494
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true );
494
+		$array_keys = array_keys(wp_list_pluck($this->meta_data, 'key'), $key, true);
495 495
 
496
-		if ( $array_keys ) {
497
-			foreach ( $array_keys as $array_key ) {
498
-				$this->meta_data[ $array_key ]->value = null;
496
+		if ($array_keys) {
497
+			foreach ($array_keys as $array_key) {
498
+				$this->meta_data[$array_key]->value = null;
499 499
 			}
500 500
 		}
501 501
 	}
@@ -506,13 +506,13 @@  discard block
 block discarded – undo
506 506
 	 * @since 1.0.19
507 507
 	 * @param int $mid Meta ID.
508 508
 	 */
509
-	public function delete_meta_data_by_mid( $mid ) {
509
+	public function delete_meta_data_by_mid($mid) {
510 510
 		$this->maybe_read_meta_data();
511
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true );
511
+		$array_keys = array_keys(wp_list_pluck($this->meta_data, 'id'), (int) $mid, true);
512 512
 
513
-		if ( $array_keys ) {
514
-			foreach ( $array_keys as $array_key ) {
515
-				$this->meta_data[ $array_key ]->value = null;
513
+		if ($array_keys) {
514
+			foreach ($array_keys as $array_key) {
515
+				$this->meta_data[$array_key]->value = null;
516 516
 			}
517 517
 		}
518 518
 	}
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
 	 * @since 1.0.19
524 524
 	 */
525 525
 	protected function maybe_read_meta_data() {
526
-		if ( is_null( $this->meta_data ) ) {
526
+		if (is_null($this->meta_data)) {
527 527
 			$this->read_meta_data();
528 528
 		}
529 529
 	}
@@ -535,43 +535,43 @@  discard block
 block discarded – undo
535 535
 	 * @since 1.0.19
536 536
 	 * @param bool $force_read True to force a new DB read (and update cache).
537 537
 	 */
538
-	public function read_meta_data( $force_read = false ) {
538
+	public function read_meta_data($force_read = false) {
539 539
 		$this->meta_data = array();
540 540
 		$cache_loaded    = false;
541 541
 
542
-		if ( ! $this->get_id() ) {
542
+		if (!$this->get_id()) {
543 543
 			return;
544 544
 		}
545 545
 
546
-		if ( ! $this->data_store ) {
546
+		if (!$this->data_store) {
547 547
 			return;
548 548
 		}
549 549
 
550
-		if ( ! empty( $this->cache_group ) ) {
551
-			$cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
550
+		if (!empty($this->cache_group)) {
551
+			$cache_key = GetPaid_Cache_Helper::get_cache_prefix($this->cache_group) . GetPaid_Cache_Helper::get_cache_prefix('object_' . $this->get_id()) . 'object_meta_' . $this->get_id();
552 552
 		}
553 553
 
554
-		if ( ! $force_read ) {
555
-			if ( ! empty( $this->cache_group ) ) {
556
-				$cached_meta  = wp_cache_get( $cache_key, $this->cache_group );
557
-				$cache_loaded = ! empty( $cached_meta );
554
+		if (!$force_read) {
555
+			if (!empty($this->cache_group)) {
556
+				$cached_meta  = wp_cache_get($cache_key, $this->cache_group);
557
+				$cache_loaded = !empty($cached_meta);
558 558
 			}
559 559
 		}
560 560
 
561
-		$raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta( $this );
562
-		if ( $raw_meta_data ) {
563
-			foreach ( $raw_meta_data as $meta ) {
561
+		$raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta($this);
562
+		if ($raw_meta_data) {
563
+			foreach ($raw_meta_data as $meta) {
564 564
 				$this->meta_data[] = new GetPaid_Meta_Data(
565 565
 					array(
566 566
 						'id'    => (int) $meta->meta_id,
567 567
 						'key'   => $meta->meta_key,
568
-						'value' => maybe_unserialize( $meta->meta_value ),
568
+						'value' => maybe_unserialize($meta->meta_value),
569 569
 					)
570 570
 				);
571 571
 			}
572 572
 
573
-			if ( ! $cache_loaded && ! empty( $this->cache_group ) ) {
574
-				wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group );
573
+			if (!$cache_loaded && !empty($this->cache_group)) {
574
+				wp_cache_set($cache_key, $raw_meta_data, $this->cache_group);
575 575
 			}
576 576
 		}
577 577
 	}
@@ -582,28 +582,28 @@  discard block
 block discarded – undo
582 582
 	 * @since 1.0.19
583 583
 	 */
584 584
 	public function save_meta_data() {
585
-		if ( ! $this->data_store || is_null( $this->meta_data ) ) {
585
+		if (!$this->data_store || is_null($this->meta_data)) {
586 586
 			return;
587 587
 		}
588
-		foreach ( $this->meta_data as $array_key => $meta ) {
589
-			if ( is_null( $meta->value ) ) {
590
-				if ( ! empty( $meta->id ) ) {
591
-					$this->data_store->delete_meta( $this, $meta );
592
-					unset( $this->meta_data[ $array_key ] );
588
+		foreach ($this->meta_data as $array_key => $meta) {
589
+			if (is_null($meta->value)) {
590
+				if (!empty($meta->id)) {
591
+					$this->data_store->delete_meta($this, $meta);
592
+					unset($this->meta_data[$array_key]);
593 593
 				}
594
-			} elseif ( empty( $meta->id ) ) {
595
-				$meta->id = $this->data_store->add_meta( $this, $meta );
594
+			} elseif (empty($meta->id)) {
595
+				$meta->id = $this->data_store->add_meta($this, $meta);
596 596
 				$meta->apply_changes();
597 597
 			} else {
598
-				if ( $meta->get_changes() ) {
599
-					$this->data_store->update_meta( $this, $meta );
598
+				if ($meta->get_changes()) {
599
+					$this->data_store->update_meta($this, $meta);
600 600
 					$meta->apply_changes();
601 601
 				}
602 602
 			}
603 603
 		}
604
-		if ( ! empty( $this->cache_group ) ) {
605
-			$cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
606
-			wp_cache_delete( $cache_key, $this->cache_group );
604
+		if (!empty($this->cache_group)) {
605
+			$cache_key = GetPaid_Cache_Helper::get_cache_prefix($this->cache_group) . GetPaid_Cache_Helper::get_cache_prefix('object_' . $this->get_id()) . 'object_meta_' . $this->get_id();
606
+			wp_cache_delete($cache_key, $this->cache_group);
607 607
 		}
608 608
 	}
609 609
 
@@ -613,8 +613,8 @@  discard block
 block discarded – undo
613 613
 	 * @since 1.0.19
614 614
 	 * @param int $id ID.
615 615
 	 */
616
-	public function set_id( $id ) {
617
-		$this->id = absint( $id );
616
+	public function set_id($id) {
617
+		$this->id = absint($id);
618 618
 	}
619 619
 
620 620
 	/**
@@ -625,7 +625,7 @@  discard block
 block discarded – undo
625 625
 	public function set_defaults() {
626 626
 		$this->data    = $this->default_data;
627 627
 		$this->changes = array();
628
-		$this->set_object_read( false );
628
+		$this->set_object_read(false);
629 629
 	}
630 630
 
631 631
 	/**
@@ -634,7 +634,7 @@  discard block
 block discarded – undo
634 634
 	 * @since 1.0.19
635 635
 	 * @param boolean $read Should read?.
636 636
 	 */
637
-	public function set_object_read( $read = true ) {
637
+	public function set_object_read($read = true) {
638 638
 		$this->object_read = (bool) $read;
639 639
 	}
640 640
 
@@ -659,32 +659,32 @@  discard block
 block discarded – undo
659 659
 	 *
660 660
 	 * @return bool|WP_Error
661 661
 	 */
662
-	public function set_props( $props, $context = 'set' ) {
662
+	public function set_props($props, $context = 'set') {
663 663
 		$errors = false;
664 664
 
665
-		foreach ( $props as $prop => $value ) {
665
+		foreach ($props as $prop => $value) {
666 666
 			try {
667 667
 				/**
668 668
 				 * Checks if the prop being set is allowed, and the value is not null.
669 669
 				 */
670
-				if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) {
670
+				if (is_null($value) || in_array($prop, array('prop', 'date_prop', 'meta_data'), true)) {
671 671
 					continue;
672 672
 				}
673 673
 				$setter = "set_$prop";
674 674
 
675
-				if ( is_callable( array( $this, $setter ) ) ) {
676
-					$this->{$setter}( $value );
675
+				if (is_callable(array($this, $setter))) {
676
+					$this->{$setter}($value);
677 677
 				}
678
-			} catch ( Exception $e ) {
679
-				if ( ! $errors ) {
678
+			} catch (Exception $e) {
679
+				if (!$errors) {
680 680
 					$errors = new WP_Error();
681 681
 				}
682
-				$errors->add( $e->getCode(), $e->getMessage() );
682
+				$errors->add($e->getCode(), $e->getMessage());
683 683
 				$this->last_error = $e->getMessage();
684 684
 			}
685 685
 		}
686 686
 
687
-		return $errors && count( $errors->get_error_codes() ) ? $errors : true;
687
+		return $errors && count($errors->get_error_codes()) ? $errors : true;
688 688
 	}
689 689
 
690 690
 	/**
@@ -697,14 +697,14 @@  discard block
 block discarded – undo
697 697
 	 * @param string $prop Name of prop to set.
698 698
 	 * @param mixed  $value Value of the prop.
699 699
 	 */
700
-	protected function set_prop( $prop, $value ) {
701
-		if ( array_key_exists( $prop, $this->data ) ) {
702
-			if ( true === $this->object_read ) {
703
-				if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) {
704
-					$this->changes[ $prop ] = $value;
700
+	protected function set_prop($prop, $value) {
701
+		if (array_key_exists($prop, $this->data)) {
702
+			if (true === $this->object_read) {
703
+				if ($value !== $this->data[$prop] || array_key_exists($prop, $this->changes)) {
704
+					$this->changes[$prop] = $value;
705 705
 				}
706 706
 			} else {
707
-				$this->data[ $prop ] = $value;
707
+				$this->data[$prop] = $value;
708 708
 			}
709 709
 		}
710 710
 	}
@@ -725,7 +725,7 @@  discard block
 block discarded – undo
725 725
 	 * @since 1.0.19
726 726
 	 */
727 727
 	public function apply_changes() {
728
-		$this->data    = array_replace_recursive( $this->data, $this->changes );
728
+		$this->data    = array_replace_recursive($this->data, $this->changes);
729 729
 		$this->changes = array();
730 730
 	}
731 731
 
@@ -750,14 +750,14 @@  discard block
 block discarded – undo
750 750
 	 * @param  string $context What the value is for. Valid values are view and edit.
751 751
 	 * @return mixed
752 752
 	 */
753
-	protected function get_prop( $prop, $context = 'view' ) {
753
+	protected function get_prop($prop, $context = 'view') {
754 754
 		$value = null;
755 755
 
756
-		if ( array_key_exists( $prop, $this->data ) ) {
757
-			$value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ];
756
+		if (array_key_exists($prop, $this->data)) {
757
+			$value = array_key_exists($prop, $this->changes) ? $this->changes[$prop] : $this->data[$prop];
758 758
 
759
-			if ( 'view' === $context ) {
760
-				$value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );
759
+			if ('view' === $context) {
760
+				$value = apply_filters($this->get_hook_prefix() . $prop, $value, $this);
761 761
 			}
762 762
 		}
763 763
 
@@ -771,13 +771,13 @@  discard block
 block discarded – undo
771 771
 	 * @param string         $prop Name of prop to set.
772 772
 	 * @param string|integer $value Value of the prop.
773 773
 	 */
774
-	protected function set_date_prop( $prop, $value ) {
774
+	protected function set_date_prop($prop, $value) {
775 775
 
776
-		if ( empty( $value ) ) {
777
-			$this->set_prop( $prop, null );
776
+		if (empty($value)) {
777
+			$this->set_prop($prop, null);
778 778
 			return;
779 779
 		}
780
-		$this->set_prop( $prop, $value );
780
+		$this->set_prop($prop, $value);
781 781
 
782 782
 	}
783 783
 
@@ -789,7 +789,7 @@  discard block
 block discarded – undo
789 789
 	 * @param string $code             Error code.
790 790
 	 * @param string $message          Error message.
791 791
 	 */
792
-	protected function error( $code, $message ) {
793
-		throw new Exception( $message, $code );
792
+	protected function error($code, $message) {
793
+		throw new Exception($message, $code);
794 794
 	}
795 795
 }
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-getpaid-meta-box-item-details.php 2 patches
Indentation   +27 added lines, -27 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.
@@ -285,11 +285,11 @@  discard block
 block discarded – undo
285 285
     }
286 286
 
287 287
     /**
288
-	 * Save meta box data.
289
-	 *
290
-	 * @param int $post_id
291
-	 */
292
-	public static function save( $post_id ) {
288
+     * Save meta box data.
289
+     *
290
+     * @param int $post_id
291
+     */
292
+    public static function save( $post_id ) {
293 293
 
294 294
         // verify nonce
295 295
         if ( ! isset( $_POST['wpinv_vat_meta_box_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_vat_meta_box_nonce'], 'wpinv_item_meta_box_save' ) ) {
@@ -301,24 +301,24 @@  discard block
 block discarded – undo
301 301
 
302 302
         // Load new data.
303 303
         $item->set_props(
304
-			array(
305
-				'price'                => isset( $_POST['wpinv_item_price'] ) ? (float) $_POST['wpinv_item_price'] : null,
306
-				'vat_rule'             => isset( $_POST['wpinv_vat_rules'] ) ? wpinv_clean( $_POST['wpinv_vat_rules'] ) : null,
307
-				'vat_class'            => isset( $_POST['wpinv_vat_class'] ) ? wpinv_clean( $_POST['wpinv_vat_class'] ) : null,
308
-				'type'                 => isset( $_POST['wpinv_item_type'] ) ? wpinv_clean( $_POST['wpinv_item_type'] ) : null,
309
-				'is_dynamic_pricing'   => isset( $_POST['wpinv_name_your_price'] ),
304
+            array(
305
+                'price'                => isset( $_POST['wpinv_item_price'] ) ? (float) $_POST['wpinv_item_price'] : null,
306
+                'vat_rule'             => isset( $_POST['wpinv_vat_rules'] ) ? wpinv_clean( $_POST['wpinv_vat_rules'] ) : null,
307
+                'vat_class'            => isset( $_POST['wpinv_vat_class'] ) ? wpinv_clean( $_POST['wpinv_vat_class'] ) : null,
308
+                'type'                 => isset( $_POST['wpinv_item_type'] ) ? wpinv_clean( $_POST['wpinv_item_type'] ) : null,
309
+                'is_dynamic_pricing'   => isset( $_POST['wpinv_name_your_price'] ),
310 310
                 'minimum_price'        => isset( $_POST['wpinv_minimum_price'] ) ? (float) $_POST['wpinv_minimum_price'] : null,
311
-				'is_recurring'         => isset( $_POST['wpinv_is_recurring'] ),
312
-				'recurring_period'     => isset( $_POST['wpinv_recurring_period'] ) ? wpinv_clean( $_POST['wpinv_recurring_period'] ) : null,
313
-				'recurring_interval'   => isset( $_POST['wpinv_recurring_interval'] ) ? (int) $_POST['wpinv_recurring_interval'] : null,
314
-				'recurring_limit'      => isset( $_POST['wpinv_recurring_limit'] ) ? (int) $_POST['wpinv_recurring_limit'] : null,
315
-				'is_free_trial'        => isset( $_POST['wpinv_trial_interval'] ) ? ( 0 != (int) $_POST['wpinv_trial_interval'] ) : null,
316
-				'trial_period'         => isset( $_POST['wpinv_trial_period'] ) ? wpinv_clean( $_POST['wpinv_trial_period'] ) : null,
317
-				'trial_interval'       => isset( $_POST['wpinv_trial_interval'] ) ? (int) $_POST['wpinv_trial_interval'] : null,
318
-			)
311
+                'is_recurring'         => isset( $_POST['wpinv_is_recurring'] ),
312
+                'recurring_period'     => isset( $_POST['wpinv_recurring_period'] ) ? wpinv_clean( $_POST['wpinv_recurring_period'] ) : null,
313
+                'recurring_interval'   => isset( $_POST['wpinv_recurring_interval'] ) ? (int) $_POST['wpinv_recurring_interval'] : null,
314
+                'recurring_limit'      => isset( $_POST['wpinv_recurring_limit'] ) ? (int) $_POST['wpinv_recurring_limit'] : null,
315
+                'is_free_trial'        => isset( $_POST['wpinv_trial_interval'] ) ? ( 0 != (int) $_POST['wpinv_trial_interval'] ) : null,
316
+                'trial_period'         => isset( $_POST['wpinv_trial_period'] ) ? wpinv_clean( $_POST['wpinv_trial_period'] ) : null,
317
+                'trial_interval'       => isset( $_POST['wpinv_trial_interval'] ) ? (int) $_POST['wpinv_trial_interval'] : null,
318
+            )
319 319
         );
320 320
 
321
-		$item->save();
322
-		do_action( 'getpaid_item_metabox_save', $post_id, $item );
323
-	}
321
+        $item->save();
322
+        do_action( 'getpaid_item_metabox_save', $post_id, $item );
323
+    }
324 324
 }
Please login to merge, or discard this patch.
Spacing   +88 added lines, -88 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( 'wpinv_item_meta_box_save', 'wpinv_vat_meta_box_nonce' );
30
+        wp_nonce_field('wpinv_item_meta_box_save', 'wpinv_vat_meta_box_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
         <input type="hidden" id="_wpi_is_editable" value="<?php echo (int) $item->is_editable(); ?>" />
46 46
         <style>
47 47
             #poststuff .input-group-text,
@@ -51,21 +51,21 @@  discard block
 block discarded – undo
51 51
         </style>
52 52
         <div class='bsui' style='max-width: 600px;padding-top: 10px;'>
53 53
 
54
-            <?php do_action( 'wpinv_item_details_metabox_before_price', $item ); ?>
54
+            <?php do_action('wpinv_item_details_metabox_before_price', $item); ?>
55 55
             <div class="form-group row">
56
-                <label class="col-sm-3 col-form-label" for="wpinv_item_price"><span><?php _e( 'Item Price', 'invoicing' )?></span></label>
56
+                <label class="col-sm-3 col-form-label" for="wpinv_item_price"><span><?php _e('Item Price', 'invoicing')?></span></label>
57 57
                 <div class="col-sm-8">
58 58
                     <div class="row">
59 59
                         <div class="col-sm-4 getpaid-price-input">
60 60
                             <div class="input-group input-group-sm">
61
-                                <?php if( 'left' == $position ) : ?>
61
+                                <?php if ('left' == $position) : ?>
62 62
                                 <div class="input-group-prepend">
63 63
                                     <span class="input-group-text" id="wpinv_item_price_symbol"><?php echo wpinv_currency_symbol(); ?></span>
64 64
                                 </div>
65 65
                                 <?php endif; ?>
66
-                                <input type="text" name="wpinv_item_price" id="wpinv_item_price" value="<?php echo esc_attr( $item->get_price( 'edit' ) ); ?>" placeholder="<?php echo esc_attr( wpinv_sanitize_amount( 0 ) ); ?>" class="form-control">
66
+                                <input type="text" name="wpinv_item_price" id="wpinv_item_price" value="<?php echo esc_attr($item->get_price('edit')); ?>" placeholder="<?php echo esc_attr(wpinv_sanitize_amount(0)); ?>" class="form-control">
67 67
 
68
-                                <?php if( 'left' != $position ) : ?>
68
+                                <?php if ('left' != $position) : ?>
69 69
                                 <div class="input-group-append">
70 70
                                     <span class="input-group-text" id="wpinv_item_price_symbol"><?php echo wpinv_currency_symbol(); ?></span>
71 71
                                 </div>
@@ -79,25 +79,25 @@  discard block
 block discarded – undo
79 79
                                     array(
80 80
                                         'id'               => 'wpinv_recurring_interval',
81 81
                                         'name'             => 'wpinv_recurring_interval',
82
-                                        'label'            => __( 'Interval', 'invoicing' ),
83
-                                        'placeholder'      => __( 'Select Interval', 'invoicing' ),
84
-                                        'value'            => $item->get_recurring_interval( 'edit' ),
82
+                                        'label'            => __('Interval', 'invoicing'),
83
+                                        'placeholder'      => __('Select Interval', 'invoicing'),
84
+                                        'value'            => $item->get_recurring_interval('edit'),
85 85
                                         'select2'          => true,
86 86
                                         'data-allow-clear' => 'false',
87 87
                                         'options'          => array(
88
-                                            '1'  => __( 'every', 'invoicing' ),
89
-                                            '2'  => __( 'every 2nd', 'invoicing' ),
90
-                                            '3'  => __( 'every 3rd', 'invoicing' ),
91
-                                            '4'  => __( 'every 4th', 'invoicing' ),
92
-                                            '5'  => __( 'every 5th', 'invoicing' ),
93
-                                            '6'  => __( 'every 6th', 'invoicing' ),
94
-                                            '8'  => __( 'every 8th', 'invoicing' ),
95
-                                            '9'  => __( 'every 9th', 'invoicing' ),
96
-                                            '10' => __( 'every 10th', 'invoicing' ),
97
-                                            '11' => __( 'every 11th', 'invoicing' ),
98
-                                            '12' => __( 'every 12th', 'invoicing' ),
99
-                                            '13' => __( 'every 13th', 'invoicing' ),
100
-                                            '14' => __( 'every 14th', 'invoicing' ),
88
+                                            '1'  => __('every', 'invoicing'),
89
+                                            '2'  => __('every 2nd', 'invoicing'),
90
+                                            '3'  => __('every 3rd', 'invoicing'),
91
+                                            '4'  => __('every 4th', 'invoicing'),
92
+                                            '5'  => __('every 5th', 'invoicing'),
93
+                                            '6'  => __('every 6th', 'invoicing'),
94
+                                            '8'  => __('every 8th', 'invoicing'),
95
+                                            '9'  => __('every 9th', 'invoicing'),
96
+                                            '10' => __('every 10th', 'invoicing'),
97
+                                            '11' => __('every 11th', 'invoicing'),
98
+                                            '12' => __('every 12th', 'invoicing'),
99
+                                            '13' => __('every 13th', 'invoicing'),
100
+                                            '14' => __('every 14th', 'invoicing'),
101 101
                                         )
102 102
                                     )
103 103
                                 );
@@ -109,16 +109,16 @@  discard block
 block discarded – undo
109 109
                                     array(
110 110
                                         'id'               => 'wpinv_recurring_period',
111 111
                                         'name'             => 'wpinv_recurring_period',
112
-                                        'label'            => __( 'Period', 'invoicing' ),
113
-                                        'placeholder'      => __( 'Select Period', 'invoicing' ),
114
-                                        'value'            => $item->get_recurring_period( 'edit' ),
112
+                                        'label'            => __('Period', 'invoicing'),
113
+                                        'placeholder'      => __('Select Period', 'invoicing'),
114
+                                        'value'            => $item->get_recurring_period('edit'),
115 115
                                         'select2'          => true,
116 116
                                         'data-allow-clear' => 'false',
117 117
                                         'options'     => array(
118
-                                            'D'  => __( 'day', 'invoicing' ),
119
-                                            'W'  => __( 'week', 'invoicing' ),
120
-                                            'M'  => __( 'month', 'invoicing' ),
121
-                                            'Y'  => __( 'year', 'invoicing' ),
118
+                                            'D'  => __('day', 'invoicing'),
119
+                                            'W'  => __('week', 'invoicing'),
120
+                                            'M'  => __('month', 'invoicing'),
121
+                                            'Y'  => __('year', 'invoicing'),
122 122
                                         )
123 123
                                     )
124 124
                                 );
@@ -130,9 +130,9 @@  discard block
 block discarded – undo
130 130
                             <?php
131 131
 
132 132
                                 // Dynamic pricing.
133
-                                if( $item->supports_dynamic_pricing() ) {
133
+                                if ($item->supports_dynamic_pricing()) {
134 134
 
135
-                                    do_action( 'wpinv_item_details_metabox_before_dynamic_pricing_checkbox', $item );
135
+                                    do_action('wpinv_item_details_metabox_before_dynamic_pricing_checkbox', $item);
136 136
 
137 137
                                     // NYP toggle.
138 138
                                     echo aui()->input(
@@ -140,60 +140,60 @@  discard block
 block discarded – undo
140 140
                                             'id'          => 'wpinv_name_your_price',
141 141
                                             'name'        => 'wpinv_name_your_price',
142 142
                                             'type'        => 'checkbox',
143
-                                            'label'       => apply_filters( 'wpinv_name_your_price_toggle_text', __( 'Let customers name their price', 'invoicing' ) ),
143
+                                            'label'       => apply_filters('wpinv_name_your_price_toggle_text', __('Let customers name their price', 'invoicing')),
144 144
                                             'value'       => '1',
145 145
                                             'checked'     => $item->user_can_set_their_price(),
146 146
                                             'no_wrap'     => true,
147 147
                                         )
148 148
                                     );
149 149
 
150
-                                    do_action( 'wpinv_item_details_metabox_dynamic_pricing_checkbox', $item );
150
+                                    do_action('wpinv_item_details_metabox_dynamic_pricing_checkbox', $item);
151 151
 
152 152
                                 }
153 153
 
154 154
                                 // Subscriptions.
155
-                                do_action( 'wpinv_item_details_metabox_before_subscription_checkbox', $item );
155
+                                do_action('wpinv_item_details_metabox_before_subscription_checkbox', $item);
156 156
                                 echo aui()->input(
157 157
                                     array(
158 158
                                         'id'          => 'wpinv_is_recurring',
159 159
                                         'name'        => 'wpinv_is_recurring',
160 160
                                         'type'        => 'checkbox',
161
-                                        'label'       => apply_filters( 'wpinv_is_recurring_toggle_text', __( 'Charge customers a recurring amount for this item', 'invoicing' ) ),
161
+                                        'label'       => apply_filters('wpinv_is_recurring_toggle_text', __('Charge customers a recurring amount for this item', 'invoicing')),
162 162
                                         'value'       => '1',
163 163
                                         'checked'     => $item->is_recurring(),
164 164
                                         'no_wrap'     => true,
165 165
                                     )
166 166
                                 );
167
-                                do_action( 'wpinv_item_details_metabox_subscription_checkbox', $item );
167
+                                do_action('wpinv_item_details_metabox_subscription_checkbox', $item);
168 168
                             ?>
169 169
                         </div>
170 170
                     </div>
171 171
                 </div>
172 172
                 <div class="col-sm-1 pt-2 pl-0">
173
-                    <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>
173
+                    <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>
174 174
                 </div>
175 175
             </div>
176
-            <?php do_action( 'wpinv_item_details_metabox_after_price', $item ); ?>
176
+            <?php do_action('wpinv_item_details_metabox_after_price', $item); ?>
177 177
 
178
-            <?php if( $item->supports_dynamic_pricing() ) : ?>
179
-                <?php do_action( 'wpinv_item_details_metabox_before_minimum_price', $item ); ?>
178
+            <?php if ($item->supports_dynamic_pricing()) : ?>
179
+                <?php do_action('wpinv_item_details_metabox_before_minimum_price', $item); ?>
180 180
                 <div class="wpinv_show_if_dynamic wpinv_minimum_price">
181 181
 
182 182
                     <div class="form-group row">
183 183
                         <label for="wpinv_minimum_price" class="col-sm-3 col-form-label">
184
-                            <?php _e( 'Minimum Price', 'invoicing' );?>
184
+                            <?php _e('Minimum Price', 'invoicing'); ?>
185 185
                         </label>
186 186
                         <div class="col-sm-8">
187 187
                             <div class="input-group input-group-sm">
188
-                                <?php if( 'left' == $position ) : ?>
188
+                                <?php if ('left' == $position) : ?>
189 189
                                     <div class="input-group-prepend">
190 190
                                         <span class="input-group-text" id="wpinv_item_minimum_price_symbol"><?php echo wpinv_currency_symbol(); ?></span>
191 191
                                     </div>
192 192
                                 <?php endif; ?>
193 193
 
194
-                                <input type="text" name="wpinv_minimum_price" id="wpinv_minimum_price" value="<?php echo esc_attr( $item->get_minimum_price( 'edit' ) ); ?>" placeholder="<?php echo esc_attr( wpinv_sanitize_amount( 0 ) ); ?>" class="form-control">
194
+                                <input type="text" name="wpinv_minimum_price" id="wpinv_minimum_price" value="<?php echo esc_attr($item->get_minimum_price('edit')); ?>" placeholder="<?php echo esc_attr(wpinv_sanitize_amount(0)); ?>" class="form-control">
195 195
 
196
-                                <?php if( 'left' != $position ) : ?>
196
+                                <?php if ('left' != $position) : ?>
197 197
                                     <div class="input-group-append">
198 198
                                         <span class="input-group-text" id="wpinv_item_minimum_price_symbol"><?php echo wpinv_currency_symbol(); ?></span>
199 199
                                     </div>
@@ -202,45 +202,45 @@  discard block
 block discarded – undo
202 202
                         </div>
203 203
 
204 204
                         <div class="col-sm-1 pt-2 pl-0">
205
-                            <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>
205
+                            <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>
206 206
                         </div>
207 207
                     </div>
208 208
 
209 209
                 </div>
210
-                <?php do_action( 'wpinv_item_details_metabox_minimum_price', $item ); ?>
210
+                <?php do_action('wpinv_item_details_metabox_minimum_price', $item); ?>
211 211
             <?php endif; ?>
212 212
 
213
-            <?php do_action( 'wpinv_item_details_metabox_before_maximum_renewals', $item ); ?>
213
+            <?php do_action('wpinv_item_details_metabox_before_maximum_renewals', $item); ?>
214 214
             <div class="wpinv_show_if_recurring wpinv_maximum_renewals">
215 215
 
216 216
                 <div class="form-group row">
217 217
                     <label for="wpinv_recurring_limit" class="col-sm-3 col-form-label">
218
-                        <?php _e( 'Maximum Renewals', 'invoicing' );?>
218
+                        <?php _e('Maximum Renewals', 'invoicing'); ?>
219 219
                     </label>
220 220
                     <div class="col-sm-8">
221
-                        <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%;" />
221
+                        <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%;" />
222 222
                     </div>
223 223
                     <div class="col-sm-1 pt-2 pl-0">
224
-                        <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>
224
+                        <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>
225 225
                     </div>
226 226
                 </div>
227 227
 
228 228
             </div>
229
-            <?php do_action( 'wpinv_item_details_metabox_maximum_renewals', $item ); ?>
229
+            <?php do_action('wpinv_item_details_metabox_maximum_renewals', $item); ?>
230 230
 
231
-            <?php do_action( 'wpinv_item_details_metabox_before_free_trial', $item ); ?>
231
+            <?php do_action('wpinv_item_details_metabox_before_free_trial', $item); ?>
232 232
             <div class="wpinv_show_if_recurring wpinv_free_trial">
233 233
 
234 234
                 <div class="form-group row">
235
-                    <label class="col-sm-3 col-form-label" for="wpinv_trial_interval"><?php _e( 'Free Trial', 'invoicing' )?></label>
235
+                    <label class="col-sm-3 col-form-label" for="wpinv_trial_interval"><?php _e('Free Trial', 'invoicing')?></label>
236 236
 
237 237
                     <div class="col-sm-8">
238 238
                         <div class="row">
239 239
                             <div class="col-sm-6">
240
-                                <?php $value = $item->has_free_trial() ? $item->get_trial_interval( 'edit' ) : 0;?>
240
+                                <?php $value = $item->has_free_trial() ? $item->get_trial_interval('edit') : 0; ?>
241 241
 
242 242
                                 <div>
243
-                                    <input type="number" name="wpinv_trial_interval" style="width: 100%;" placeholder="0" id="wpinv_trial_interval" value="<?php echo esc_attr( $value ); ?>" >
243
+                                    <input type="number" name="wpinv_trial_interval" style="width: 100%;" placeholder="0" id="wpinv_trial_interval" value="<?php echo esc_attr($value); ?>" >
244 244
                                 </div>
245 245
                             </div>
246 246
                             <div class="col-sm-6">
@@ -249,17 +249,17 @@  discard block
 block discarded – undo
249 249
                                         array(
250 250
                                             'id'               => 'wpinv_trial_period',
251 251
                                             'name'             => 'wpinv_trial_period',
252
-                                            'label'            => __( 'Trial Period', 'invoicing' ),
253
-                                            'placeholder'      => __( 'Trial Period', 'invoicing' ),
254
-                                            'value'            => $item->get_recurring_period( 'edit' ),
252
+                                            'label'            => __('Trial Period', 'invoicing'),
253
+                                            'placeholder'      => __('Trial Period', 'invoicing'),
254
+                                            'value'            => $item->get_recurring_period('edit'),
255 255
                                             'select2'          => true,
256 256
                                             'data-allow-clear' => 'false',
257 257
                                             'no_wrap'          => true,
258 258
                                             'options'          => array(
259
-                                                'D'  => __( 'day(s)', 'invoicing' ),
260
-                                                'W'  => __( 'week(s)', 'invoicing' ),
261
-                                                'M'  => __( 'month(s)', 'invoicing' ),
262
-                                                'Y'  => __( 'year(s)', 'invoicing' ),
259
+                                                'D'  => __('day(s)', 'invoicing'),
260
+                                                'W'  => __('week(s)', 'invoicing'),
261
+                                                'M'  => __('month(s)', 'invoicing'),
262
+                                                'Y'  => __('year(s)', 'invoicing'),
263 263
                                             )
264 264
                                         )
265 265
                                     );
@@ -270,15 +270,15 @@  discard block
 block discarded – undo
270 270
                     </div>
271 271
 
272 272
                     <div class="col-sm-1 pt-2 pl-0">
273
-                        <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>
273
+                        <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>
274 274
                     </div>
275 275
 
276 276
                 </div>
277 277
 
278 278
             </div>
279
-            <?php do_action( 'wpinv_item_details_metabox__free_trial', $item ); ?>
279
+            <?php do_action('wpinv_item_details_metabox__free_trial', $item); ?>
280 280
 
281
-            <?php do_action( 'wpinv_item_details_metabox_item_details', $item ); ?>
281
+            <?php do_action('wpinv_item_details_metabox_item_details', $item); ?>
282 282
         </div>
283 283
         <?php
284 284
 
@@ -289,36 +289,36 @@  discard block
 block discarded – undo
289 289
 	 *
290 290
 	 * @param int $post_id
291 291
 	 */
292
-	public static function save( $post_id ) {
292
+	public static function save($post_id) {
293 293
 
294 294
         // verify nonce
295
-        if ( ! isset( $_POST['wpinv_vat_meta_box_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_vat_meta_box_nonce'], 'wpinv_item_meta_box_save' ) ) {
295
+        if (!isset($_POST['wpinv_vat_meta_box_nonce']) || !wp_verify_nonce($_POST['wpinv_vat_meta_box_nonce'], 'wpinv_item_meta_box_save')) {
296 296
             return;
297 297
         }
298 298
 
299 299
         // Prepare the item.
300
-        $item = new WPInv_Item( $post_id );
300
+        $item = new WPInv_Item($post_id);
301 301
 
302 302
         // Load new data.
303 303
         $item->set_props(
304 304
 			array(
305
-				'price'                => isset( $_POST['wpinv_item_price'] ) ? (float) $_POST['wpinv_item_price'] : null,
306
-				'vat_rule'             => isset( $_POST['wpinv_vat_rules'] ) ? wpinv_clean( $_POST['wpinv_vat_rules'] ) : null,
307
-				'vat_class'            => isset( $_POST['wpinv_vat_class'] ) ? wpinv_clean( $_POST['wpinv_vat_class'] ) : null,
308
-				'type'                 => isset( $_POST['wpinv_item_type'] ) ? wpinv_clean( $_POST['wpinv_item_type'] ) : null,
309
-				'is_dynamic_pricing'   => isset( $_POST['wpinv_name_your_price'] ),
310
-                'minimum_price'        => isset( $_POST['wpinv_minimum_price'] ) ? (float) $_POST['wpinv_minimum_price'] : null,
311
-				'is_recurring'         => isset( $_POST['wpinv_is_recurring'] ),
312
-				'recurring_period'     => isset( $_POST['wpinv_recurring_period'] ) ? wpinv_clean( $_POST['wpinv_recurring_period'] ) : null,
313
-				'recurring_interval'   => isset( $_POST['wpinv_recurring_interval'] ) ? (int) $_POST['wpinv_recurring_interval'] : null,
314
-				'recurring_limit'      => isset( $_POST['wpinv_recurring_limit'] ) ? (int) $_POST['wpinv_recurring_limit'] : null,
315
-				'is_free_trial'        => isset( $_POST['wpinv_trial_interval'] ) ? ( 0 != (int) $_POST['wpinv_trial_interval'] ) : null,
316
-				'trial_period'         => isset( $_POST['wpinv_trial_period'] ) ? wpinv_clean( $_POST['wpinv_trial_period'] ) : null,
317
-				'trial_interval'       => isset( $_POST['wpinv_trial_interval'] ) ? (int) $_POST['wpinv_trial_interval'] : null,
305
+				'price'                => isset($_POST['wpinv_item_price']) ? (float) $_POST['wpinv_item_price'] : null,
306
+				'vat_rule'             => isset($_POST['wpinv_vat_rules']) ? wpinv_clean($_POST['wpinv_vat_rules']) : null,
307
+				'vat_class'            => isset($_POST['wpinv_vat_class']) ? wpinv_clean($_POST['wpinv_vat_class']) : null,
308
+				'type'                 => isset($_POST['wpinv_item_type']) ? wpinv_clean($_POST['wpinv_item_type']) : null,
309
+				'is_dynamic_pricing'   => isset($_POST['wpinv_name_your_price']),
310
+                'minimum_price'        => isset($_POST['wpinv_minimum_price']) ? (float) $_POST['wpinv_minimum_price'] : null,
311
+				'is_recurring'         => isset($_POST['wpinv_is_recurring']),
312
+				'recurring_period'     => isset($_POST['wpinv_recurring_period']) ? wpinv_clean($_POST['wpinv_recurring_period']) : null,
313
+				'recurring_interval'   => isset($_POST['wpinv_recurring_interval']) ? (int) $_POST['wpinv_recurring_interval'] : null,
314
+				'recurring_limit'      => isset($_POST['wpinv_recurring_limit']) ? (int) $_POST['wpinv_recurring_limit'] : null,
315
+				'is_free_trial'        => isset($_POST['wpinv_trial_interval']) ? (0 != (int) $_POST['wpinv_trial_interval']) : null,
316
+				'trial_period'         => isset($_POST['wpinv_trial_period']) ? wpinv_clean($_POST['wpinv_trial_period']) : null,
317
+				'trial_interval'       => isset($_POST['wpinv_trial_interval']) ? (int) $_POST['wpinv_trial_interval'] : null,
318 318
 			)
319 319
         );
320 320
 
321 321
 		$item->save();
322
-		do_action( 'getpaid_item_metabox_save', $post_id, $item );
322
+		do_action('getpaid_item_metabox_save', $post_id, $item);
323 323
 	}
324 324
 }
Please login to merge, or discard this patch.
includes/class-wpinv-legacy-invoice.php 1 patch
Spacing   +626 added lines, -626 removed lines patch added patch discarded remove patch
@@ -7,8 +7,8 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 final class WPInv_Legacy_Invoice {
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
     /**
17 17
      * Invoice id.
18 18
      */
19
-    public $ID  = 0;
19
+    public $ID = 0;
20 20
 
21 21
     /**
22 22
      * The title of the invoice. Usually the invoice number.
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
     /**
133 133
      * The invoice status.
134 134
      */
135
-    public $status      = 'wpi-pending';
135
+    public $status = 'wpi-pending';
136 136
 
137 137
     /**
138 138
      * Same as self::$status.
@@ -259,17 +259,17 @@  discard block
 block discarded – undo
259 259
      */
260 260
     public $parent_invoice = 0;
261 261
     
262
-    public function __construct( $invoice_id = false ) {
263
-        if( empty( $invoice_id ) ) {
262
+    public function __construct($invoice_id = false) {
263
+        if (empty($invoice_id)) {
264 264
             return false;
265 265
         }
266 266
 
267
-        $this->setup_invoice( $invoice_id );
267
+        $this->setup_invoice($invoice_id);
268 268
     }
269 269
 
270
-    public function get( $key ) {
271
-        if ( method_exists( $this, 'get_' . $key ) ) {
272
-            $value = call_user_func( array( $this, 'get_' . $key ) );
270
+    public function get($key) {
271
+        if (method_exists($this, 'get_' . $key)) {
272
+            $value = call_user_func(array($this, 'get_' . $key));
273 273
         } else {
274 274
             $value = $this->$key;
275 275
         }
@@ -277,51 +277,51 @@  discard block
 block discarded – undo
277 277
         return $value;
278 278
     }
279 279
 
280
-    public function set( $key, $value ) {
281
-        $ignore = array( 'items', 'cart_details', 'fees', '_ID' );
280
+    public function set($key, $value) {
281
+        $ignore = array('items', 'cart_details', 'fees', '_ID');
282 282
 
283
-        if ( $key === 'status' ) {
283
+        if ($key === 'status') {
284 284
             $this->old_status = $this->status;
285 285
         }
286 286
 
287
-        if ( ! in_array( $key, $ignore ) ) {
288
-            $this->pending[ $key ] = $value;
287
+        if (!in_array($key, $ignore)) {
288
+            $this->pending[$key] = $value;
289 289
         }
290 290
 
291
-        if( '_ID' !== $key ) {
291
+        if ('_ID' !== $key) {
292 292
             $this->$key = $value;
293 293
         }
294 294
     }
295 295
 
296
-    public function _isset( $name ) {
297
-        if ( property_exists( $this, $name) ) {
298
-            return false === empty( $this->$name );
296
+    public function _isset($name) {
297
+        if (property_exists($this, $name)) {
298
+            return false === empty($this->$name);
299 299
         } else {
300 300
             return null;
301 301
         }
302 302
     }
303 303
 
304
-    private function setup_invoice( $invoice_id ) {
304
+    private function setup_invoice($invoice_id) {
305 305
         $this->pending = array();
306 306
 
307
-        if ( empty( $invoice_id ) ) {
307
+        if (empty($invoice_id)) {
308 308
             return false;
309 309
         }
310 310
 
311
-        $invoice = get_post( $invoice_id );
311
+        $invoice = get_post($invoice_id);
312 312
 
313
-        if( !$invoice || is_wp_error( $invoice ) ) {
313
+        if (!$invoice || is_wp_error($invoice)) {
314 314
             return false;
315 315
         }
316 316
 
317
-        if( !('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type) ) {
317
+        if (!('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type)) {
318 318
             return false;
319 319
         }
320 320
 
321
-        do_action( 'wpinv_pre_setup_invoice', $this, $invoice_id );
321
+        do_action('wpinv_pre_setup_invoice', $this, $invoice_id);
322 322
 
323 323
         // Primary Identifier
324
-        $this->ID              = absint( $invoice_id );
324
+        $this->ID              = absint($invoice_id);
325 325
         $this->post_type       = $invoice->post_type;
326 326
 
327 327
         // We have a payment, get the generic payment_meta item to reduce calls to it
@@ -331,14 +331,14 @@  discard block
 block discarded – undo
331 331
         $this->completed_date  = $this->setup_completed_date();
332 332
         $this->status          = $invoice->post_status;
333 333
 
334
-        if ( 'future' == $this->status ) {
334
+        if ('future' == $this->status) {
335 335
             $this->status = 'publish';
336 336
         }
337 337
 
338 338
         $this->post_status     = $this->status;
339 339
         $this->mode            = $this->setup_mode();
340 340
         $this->parent_invoice  = $invoice->post_parent;
341
-        $this->post_name       = $this->setup_post_name( $invoice );
341
+        $this->post_name       = $this->setup_post_name($invoice);
342 342
         $this->status_nicename = $this->setup_status_nicename($invoice->post_status);
343 343
 
344 344
         // Items
@@ -361,8 +361,8 @@  discard block
 block discarded – undo
361 361
         
362 362
         // User based
363 363
         $this->ip              = $this->setup_ip();
364
-        $this->user_id         = !empty( $invoice->post_author ) ? $invoice->post_author : get_current_user_id();///$this->setup_user_id();
365
-        $this->email           = get_the_author_meta( 'email', $this->user_id );
364
+        $this->user_id         = !empty($invoice->post_author) ? $invoice->post_author : get_current_user_id(); ///$this->setup_user_id();
365
+        $this->email           = get_the_author_meta('email', $this->user_id);
366 366
 
367 367
         $this->user_info       = $this->setup_user_info();
368 368
 
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
         $this->company         = $this->user_info['company'];
372 372
         $this->vat_number      = $this->user_info['vat_number'];
373 373
         $this->vat_rate        = $this->user_info['vat_rate'];
374
-        $this->adddress_confirmed  = $this->user_info['adddress_confirmed'];
374
+        $this->adddress_confirmed = $this->user_info['adddress_confirmed'];
375 375
         $this->address         = $this->user_info['address'];
376 376
         $this->city            = $this->user_info['city'];
377 377
         $this->country         = $this->user_info['country'];
@@ -386,39 +386,39 @@  discard block
 block discarded – undo
386 386
         // Other Identifiers
387 387
         $this->key             = $this->setup_invoice_key();
388 388
         $this->number          = $this->setup_invoice_number();
389
-        $this->title           = !empty( $invoice->post_title ) ? $invoice->post_title : $this->number;
389
+        $this->title           = !empty($invoice->post_title) ? $invoice->post_title : $this->number;
390 390
         
391
-        $this->full_name       = trim( $this->first_name . ' '. $this->last_name );
391
+        $this->full_name       = trim($this->first_name . ' ' . $this->last_name);
392 392
         
393 393
         // Allow extensions to add items to this object via hook
394
-        do_action( 'wpinv_setup_invoice', $this, $invoice_id );
394
+        do_action('wpinv_setup_invoice', $this, $invoice_id);
395 395
 
396 396
         return true;
397 397
     }
398 398
 
399
-    private function setup_status_nicename( $status ) {
400
-        $all_invoice_statuses  = wpinv_get_invoice_statuses( true, true, $this );
399
+    private function setup_status_nicename($status) {
400
+        $all_invoice_statuses = wpinv_get_invoice_statuses(true, true, $this);
401 401
 
402
-        if ( $this->is_quote() && class_exists( 'Wpinv_Quotes_Shared' ) ) {
403
-            $all_invoice_statuses  = Wpinv_Quotes_Shared::wpinv_get_quote_statuses();
402
+        if ($this->is_quote() && class_exists('Wpinv_Quotes_Shared')) {
403
+            $all_invoice_statuses = Wpinv_Quotes_Shared::wpinv_get_quote_statuses();
404 404
         }
405
-        $status   = isset( $all_invoice_statuses[$status] ) ? $all_invoice_statuses[$status] : __( $status, 'invoicing' );
405
+        $status = isset($all_invoice_statuses[$status]) ? $all_invoice_statuses[$status] : __($status, 'invoicing');
406 406
 
407
-        return apply_filters( 'setup_status_nicename', $status );
407
+        return apply_filters('setup_status_nicename', $status);
408 408
     }
409 409
 
410
-    private function setup_post_name( $post = NULL ) {
410
+    private function setup_post_name($post = NULL) {
411 411
         global $wpdb;
412 412
         
413 413
         $post_name = '';
414 414
         
415
-        if ( !empty( $post ) ) {
416
-            if( !empty( $post->post_name ) ) {
415
+        if (!empty($post)) {
416
+            if (!empty($post->post_name)) {
417 417
                 $post_name = $post->post_name;
418
-            } else if ( !empty( $post->ID ) ) {
419
-                $post_name = wpinv_generate_post_name( $post->ID );
418
+            } else if (!empty($post->ID)) {
419
+                $post_name = wpinv_generate_post_name($post->ID);
420 420
 
421
-                $wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) );
421
+                $wpdb->update($wpdb->posts, array('post_name' => $post_name), array('ID' => $post->ID));
422 422
             }
423 423
         }
424 424
 
@@ -426,12 +426,12 @@  discard block
 block discarded – undo
426 426
     }
427 427
     
428 428
     private function setup_due_date() {
429
-        $due_date = $this->get_meta( '_wpinv_due_date' );
429
+        $due_date = $this->get_meta('_wpinv_due_date');
430 430
         
431
-        if ( empty( $due_date ) ) {
432
-            $overdue_time = strtotime( $this->date ) + ( DAY_IN_SECONDS * absint( wpinv_get_option( 'overdue_days' ) ) );
433
-            $due_date = date_i18n( 'Y-m-d', $overdue_time );
434
-        } else if ( $due_date == 'none' ) {
431
+        if (empty($due_date)) {
432
+            $overdue_time = strtotime($this->date) + (DAY_IN_SECONDS * absint(wpinv_get_option('overdue_days')));
433
+            $due_date = date_i18n('Y-m-d', $overdue_time);
434
+        } else if ($due_date == 'none') {
435 435
             $due_date = '';
436 436
         }
437 437
         
@@ -439,67 +439,67 @@  discard block
 block discarded – undo
439 439
     }
440 440
     
441 441
     private function setup_completed_date() {
442
-        $invoice = get_post( $this->ID );
442
+        $invoice = get_post($this->ID);
443 443
 
444
-        if ( 'wpi-pending' == $invoice->post_status || 'preapproved' == $invoice->post_status ) {
444
+        if ('wpi-pending' == $invoice->post_status || 'preapproved' == $invoice->post_status) {
445 445
             return false; // This invoice was never paid
446 446
         }
447 447
 
448
-        $date = ( $date = $this->get_meta( '_wpinv_completed_date', true ) ) ? $date : $invoice->modified_date;
448
+        $date = ($date = $this->get_meta('_wpinv_completed_date', true)) ? $date : $invoice->modified_date;
449 449
 
450 450
         return $date;
451 451
     }
452 452
     
453 453
     private function setup_cart_details() {
454
-        $cart_details = isset( $this->payment_meta['cart_details'] ) ? maybe_unserialize( $this->payment_meta['cart_details'] ) : array();
454
+        $cart_details = isset($this->payment_meta['cart_details']) ? maybe_unserialize($this->payment_meta['cart_details']) : array();
455 455
         return $cart_details;
456 456
     }
457 457
     
458 458
     public function array_convert() {
459
-        return get_object_vars( $this );
459
+        return get_object_vars($this);
460 460
     }
461 461
     
462 462
     private function setup_items() {
463
-        $items = isset( $this->payment_meta['items'] ) ? maybe_unserialize( $this->payment_meta['items'] ) : array();
463
+        $items = isset($this->payment_meta['items']) ? maybe_unserialize($this->payment_meta['items']) : array();
464 464
         return $items;
465 465
     }
466 466
     
467 467
     private function setup_fees() {
468
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
468
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
469 469
         return $payment_fees;
470 470
     }
471 471
         
472 472
     private function setup_currency() {
473
-        $currency = isset( $this->payment_meta['currency'] ) ? $this->payment_meta['currency'] : apply_filters( 'wpinv_currency_default', wpinv_get_currency(), $this );
473
+        $currency = isset($this->payment_meta['currency']) ? $this->payment_meta['currency'] : apply_filters('wpinv_currency_default', wpinv_get_currency(), $this);
474 474
         return $currency;
475 475
     }
476 476
     
477 477
     private function setup_discount() {
478 478
         //$discount = $this->get_meta( '_wpinv_discount', true );
479
-        $discount = (float)$this->subtotal - ( (float)$this->total - (float)$this->tax - (float)$this->fees_total );
480
-        if ( $discount < 0 ) {
479
+        $discount = (float) $this->subtotal - ((float) $this->total - (float) $this->tax - (float) $this->fees_total);
480
+        if ($discount < 0) {
481 481
             $discount = 0;
482 482
         }
483
-        $discount = wpinv_round_amount( $discount );
483
+        $discount = wpinv_round_amount($discount);
484 484
         
485 485
         return $discount;
486 486
     }
487 487
     
488 488
     private function setup_discount_code() {
489
-        $discount_code = !empty( $this->discounts ) ? $this->discounts : $this->get_meta( '_wpinv_discount_code', true );
489
+        $discount_code = !empty($this->discounts) ? $this->discounts : $this->get_meta('_wpinv_discount_code', true);
490 490
         return $discount_code;
491 491
     }
492 492
     
493 493
     private function setup_tax() {
494 494
 
495
-        $tax = $this->get_meta( '_wpinv_tax', true );
495
+        $tax = $this->get_meta('_wpinv_tax', true);
496 496
 
497 497
         // We don't have tax as it's own meta and no meta was passed
498
-        if ( '' === $tax ) {            
499
-            $tax = isset( $this->payment_meta['tax'] ) ? $this->payment_meta['tax'] : 0;
498
+        if ('' === $tax) {            
499
+            $tax = isset($this->payment_meta['tax']) ? $this->payment_meta['tax'] : 0;
500 500
         }
501 501
         
502
-        if ( $tax < 0 || ! $this->is_taxable() ) {
502
+        if ($tax < 0 || !$this->is_taxable()) {
503 503
             $tax = 0;
504 504
         }
505 505
 
@@ -510,16 +510,16 @@  discard block
 block discarded – undo
510 510
      * If taxes are enabled, allow users to enable/disable taxes per invoice.
511 511
      */
512 512
     private function setup_is_taxable() {
513
-        return (int) $this->get_meta( '_wpinv_disable_taxes', true );
513
+        return (int) $this->get_meta('_wpinv_disable_taxes', true);
514 514
     }
515 515
 
516 516
     private function setup_subtotal() {
517 517
         $subtotal     = 0;
518 518
         $cart_details = $this->cart_details;
519 519
 
520
-        if ( is_array( $cart_details ) ) {
521
-            foreach ( $cart_details as $item ) {
522
-                if ( isset( $item['subtotal'] ) ) {
520
+        if (is_array($cart_details)) {
521
+            foreach ($cart_details as $item) {
522
+                if (isset($item['subtotal'])) {
523 523
                     $subtotal += $item['subtotal'];
524 524
                 }
525 525
             }
@@ -533,23 +533,23 @@  discard block
 block discarded – undo
533 533
     }
534 534
 
535 535
     private function setup_discounts() {
536
-        $discounts = ! empty( $this->payment_meta['user_info']['discount'] ) ? $this->payment_meta['user_info']['discount'] : array();
536
+        $discounts = !empty($this->payment_meta['user_info']['discount']) ? $this->payment_meta['user_info']['discount'] : array();
537 537
         return $discounts;
538 538
     }
539 539
     
540 540
     private function setup_total() {
541
-        $amount = $this->get_meta( '_wpinv_total', true );
541
+        $amount = $this->get_meta('_wpinv_total', true);
542 542
 
543
-        if ( empty( $amount ) && '0.00' != $amount ) {
544
-            $meta   = $this->get_meta( '_wpinv_payment_meta', true );
545
-            $meta   = maybe_unserialize( $meta );
543
+        if (empty($amount) && '0.00' != $amount) {
544
+            $meta   = $this->get_meta('_wpinv_payment_meta', true);
545
+            $meta   = maybe_unserialize($meta);
546 546
 
547
-            if ( isset( $meta['amount'] ) ) {
547
+            if (isset($meta['amount'])) {
548 548
                 $amount = $meta['amount'];
549 549
             }
550 550
         }
551 551
 
552
-        if($amount < 0){
552
+        if ($amount < 0) {
553 553
             $amount = 0;
554 554
         }
555 555
 
@@ -557,13 +557,13 @@  discard block
 block discarded – undo
557 557
     }
558 558
     
559 559
     private function setup_mode() {
560
-        return $this->get_meta( '_wpinv_mode' );
560
+        return $this->get_meta('_wpinv_mode');
561 561
     }
562 562
 
563 563
     private function setup_gateway() {
564
-        $gateway = $this->get_meta( '_wpinv_gateway' );
564
+        $gateway = $this->get_meta('_wpinv_gateway');
565 565
         
566
-        if ( empty( $gateway ) && 'publish' === $this->status ) {
566
+        if (empty($gateway) && 'publish' === $this->status) {
567 567
             $gateway = 'manual';
568 568
         }
569 569
         
@@ -571,23 +571,23 @@  discard block
 block discarded – undo
571 571
     }
572 572
 
573 573
     private function setup_gateway_title() {
574
-        $gateway_title = wpinv_get_gateway_checkout_label( $this->gateway );
574
+        $gateway_title = wpinv_get_gateway_checkout_label($this->gateway);
575 575
         return $gateway_title;
576 576
     }
577 577
 
578 578
     private function setup_transaction_id() {
579
-        $transaction_id = $this->get_meta( '_wpinv_transaction_id' );
579
+        $transaction_id = $this->get_meta('_wpinv_transaction_id');
580 580
 
581
-        if ( empty( $transaction_id ) || (int) $transaction_id === (int) $this->ID ) {
581
+        if (empty($transaction_id) || (int) $transaction_id === (int) $this->ID) {
582 582
             $gateway        = $this->gateway;
583
-            $transaction_id = apply_filters( 'wpinv_get_invoice_transaction_id-' . $gateway, $this->ID );
583
+            $transaction_id = apply_filters('wpinv_get_invoice_transaction_id-' . $gateway, $this->ID);
584 584
         }
585 585
 
586 586
         return $transaction_id;
587 587
     }
588 588
 
589 589
     private function setup_ip() {
590
-        $ip = $this->get_meta( '_wpinv_user_ip' );
590
+        $ip = $this->get_meta('_wpinv_user_ip');
591 591
         return $ip;
592 592
     }
593 593
 
@@ -597,62 +597,62 @@  discard block
 block discarded – undo
597 597
     ///}
598 598
         
599 599
     private function setup_first_name() {
600
-        $first_name = $this->get_meta( '_wpinv_first_name' );
600
+        $first_name = $this->get_meta('_wpinv_first_name');
601 601
         return $first_name;
602 602
     }
603 603
     
604 604
     private function setup_last_name() {
605
-        $last_name = $this->get_meta( '_wpinv_last_name' );
605
+        $last_name = $this->get_meta('_wpinv_last_name');
606 606
         return $last_name;
607 607
     }
608 608
     
609 609
     private function setup_company() {
610
-        $company = $this->get_meta( '_wpinv_company' );
610
+        $company = $this->get_meta('_wpinv_company');
611 611
         return $company;
612 612
     }
613 613
     
614 614
     private function setup_vat_number() {
615
-        $vat_number = $this->get_meta( '_wpinv_vat_number' );
615
+        $vat_number = $this->get_meta('_wpinv_vat_number');
616 616
         return $vat_number;
617 617
     }
618 618
     
619 619
     private function setup_vat_rate() {
620
-        $vat_rate = $this->get_meta( '_wpinv_vat_rate' );
620
+        $vat_rate = $this->get_meta('_wpinv_vat_rate');
621 621
         return $vat_rate;
622 622
     }
623 623
     
624 624
     private function setup_adddress_confirmed() {
625
-        $adddress_confirmed = $this->get_meta( '_wpinv_adddress_confirmed' );
625
+        $adddress_confirmed = $this->get_meta('_wpinv_adddress_confirmed');
626 626
         return $adddress_confirmed;
627 627
     }
628 628
     
629 629
     private function setup_phone() {
630
-        $phone = $this->get_meta( '_wpinv_phone' );
630
+        $phone = $this->get_meta('_wpinv_phone');
631 631
         return $phone;
632 632
     }
633 633
     
634 634
     private function setup_address() {
635
-        $address = $this->get_meta( '_wpinv_address', true );
635
+        $address = $this->get_meta('_wpinv_address', true);
636 636
         return $address;
637 637
     }
638 638
     
639 639
     private function setup_city() {
640
-        $city = $this->get_meta( '_wpinv_city', true );
640
+        $city = $this->get_meta('_wpinv_city', true);
641 641
         return $city;
642 642
     }
643 643
     
644 644
     private function setup_country() {
645
-        $country = $this->get_meta( '_wpinv_country', true );
645
+        $country = $this->get_meta('_wpinv_country', true);
646 646
         return $country;
647 647
     }
648 648
     
649 649
     private function setup_state() {
650
-        $state = $this->get_meta( '_wpinv_state', true );
650
+        $state = $this->get_meta('_wpinv_state', true);
651 651
         return $state;
652 652
     }
653 653
     
654 654
     private function setup_zip() {
655
-        $zip = $this->get_meta( '_wpinv_zip', true );
655
+        $zip = $this->get_meta('_wpinv_zip', true);
656 656
         return $zip;
657 657
     }
658 658
 
@@ -661,7 +661,7 @@  discard block
 block discarded – undo
661 661
             'user_id'        => $this->user_id,
662 662
             'first_name'     => $this->first_name,
663 663
             'last_name'      => $this->last_name,
664
-            'email'          => get_the_author_meta( 'email', $this->user_id ),
664
+            'email'          => get_the_author_meta('email', $this->user_id),
665 665
             'phone'          => $this->phone,
666 666
             'address'        => $this->address,
667 667
             'city'           => $this->city,
@@ -676,12 +676,12 @@  discard block
 block discarded – undo
676 676
         );
677 677
         
678 678
         $user_info = array();
679
-        if ( isset( $this->payment_meta['user_info'] ) ) {
680
-            $user_info = maybe_unserialize( $this->payment_meta['user_info'] );
679
+        if (isset($this->payment_meta['user_info'])) {
680
+            $user_info = maybe_unserialize($this->payment_meta['user_info']);
681 681
             
682
-            if ( !empty( $user_info ) && isset( $user_info['user_id'] ) && $post = get_post( $this->ID ) ) {
682
+            if (!empty($user_info) && isset($user_info['user_id']) && $post = get_post($this->ID)) {
683 683
                 $this->user_id = $post->post_author;
684
-                $this->email = get_the_author_meta( 'email', $this->user_id );
684
+                $this->email = get_the_author_meta('email', $this->user_id);
685 685
                 
686 686
                 $user_info['user_id'] = $this->user_id;
687 687
                 $user_info['email'] = $this->email;
@@ -690,13 +690,13 @@  discard block
 block discarded – undo
690 690
             }
691 691
         }
692 692
         
693
-        $user_info    = wp_parse_args( $user_info, $defaults );
693
+        $user_info = wp_parse_args($user_info, $defaults);
694 694
         
695 695
         // Get the user, but only if it's been created
696
-        $user = get_userdata( $this->user_id );
696
+        $user = get_userdata($this->user_id);
697 697
         
698
-        if ( !empty( $user ) && $user->ID > 0 ) {
699
-            if ( empty( $user_info ) ) {
698
+        if (!empty($user) && $user->ID > 0) {
699
+            if (empty($user_info)) {
700 700
                 $user_info = array(
701 701
                     'user_id'    => $user->ID,
702 702
                     'first_name' => $user->first_name,
@@ -705,23 +705,23 @@  discard block
 block discarded – undo
705 705
                     'discount'   => '',
706 706
                 );
707 707
             } else {
708
-                foreach ( $user_info as $key => $value ) {
709
-                    if ( ! empty( $value ) ) {
708
+                foreach ($user_info as $key => $value) {
709
+                    if (!empty($value)) {
710 710
                         continue;
711 711
                     }
712 712
 
713
-                    switch( $key ) {
713
+                    switch ($key) {
714 714
                         case 'user_id':
715
-                            $user_info[ $key ] = $user->ID;
715
+                            $user_info[$key] = $user->ID;
716 716
                             break;
717 717
                         case 'first_name':
718
-                            $user_info[ $key ] = $user->first_name;
718
+                            $user_info[$key] = $user->first_name;
719 719
                             break;
720 720
                         case 'last_name':
721
-                            $user_info[ $key ] = $user->last_name;
721
+                            $user_info[$key] = $user->last_name;
722 722
                             break;
723 723
                         case 'email':
724
-                            $user_info[ $key ] = $user->user_email;
724
+                            $user_info[$key] = $user->user_email;
725 725
                             break;
726 726
                     }
727 727
                 }
@@ -732,25 +732,25 @@  discard block
 block discarded – undo
732 732
     }
733 733
 
734 734
     private function setup_invoice_key() {
735
-        $key = $this->get_meta( '_wpinv_key', true );
735
+        $key = $this->get_meta('_wpinv_key', true);
736 736
         
737 737
         return $key;
738 738
     }
739 739
 
740 740
     private function setup_invoice_number() {
741
-        $number = $this->get_meta( '_wpinv_number', true );
741
+        $number = $this->get_meta('_wpinv_number', true);
742 742
 
743
-        if ( !$number ) {
743
+        if (!$number) {
744 744
             $number = $this->ID;
745 745
 
746
-            if ( $this->status == 'auto-draft' ) {
747
-                if ( wpinv_sequential_number_active( $this->post_type ) ) {
748
-                    $next_number = wpinv_get_next_invoice_number( $this->post_type );
746
+            if ($this->status == 'auto-draft') {
747
+                if (wpinv_sequential_number_active($this->post_type)) {
748
+                    $next_number = wpinv_get_next_invoice_number($this->post_type);
749 749
                     $number      = $next_number;
750 750
                 }
751 751
             }
752 752
             
753
-            $number = wpinv_format_invoice_number( $number, $this->post_type );
753
+            $number = wpinv_format_invoice_number($number, $this->post_type);
754 754
         }
755 755
 
756 756
         return $number;
@@ -759,10 +759,10 @@  discard block
 block discarded – undo
759 759
     private function insert_invoice() {
760 760
         global $wpdb;
761 761
 
762
-        if ( empty( $this->post_type ) ) {
763
-            if ( !empty( $this->ID ) && $post_type = get_post_type( $this->ID ) ) {
762
+        if (empty($this->post_type)) {
763
+            if (!empty($this->ID) && $post_type = get_post_type($this->ID)) {
764 764
                 $this->post_type = $post_type;
765
-            } else if ( !empty( $this->parent_invoice ) && $post_type = get_post_type( $this->parent_invoice ) ) {
765
+            } else if (!empty($this->parent_invoice) && $post_type = get_post_type($this->parent_invoice)) {
766 766
                 $this->post_type = $post_type;
767 767
             } else {
768 768
                 $this->post_type = 'wpi_invoice';
@@ -770,16 +770,16 @@  discard block
 block discarded – undo
770 770
         }
771 771
 
772 772
         $invoice_number = $this->ID;
773
-        if ( $number = $this->get_meta( '_wpinv_number', true ) ) {
773
+        if ($number = $this->get_meta('_wpinv_number', true)) {
774 774
             $invoice_number = $number;
775 775
         }
776 776
 
777
-        if ( empty( $this->key ) ) {
777
+        if (empty($this->key)) {
778 778
             $this->key = self::generate_key();
779 779
             $this->pending['key'] = $this->key;
780 780
         }
781 781
 
782
-        if ( empty( $this->ip ) ) {
782
+        if (empty($this->ip)) {
783 783
             $this->ip = wpinv_get_ip();
784 784
             $this->pending['ip'] = $this->ip;
785 785
         }
@@ -816,61 +816,61 @@  discard block
 block discarded – undo
816 816
                         'post_status'   => $this->status,
817 817
                         'post_author'   => $this->user_id,
818 818
                         'post_type'     => $this->post_type,
819
-                        'post_date'     => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time( 'mysql' ),
820
-                        'post_date_gmt' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date( $this->date ) : current_time( 'mysql', 1 ),
819
+                        'post_date'     => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time('mysql'),
820
+                        'post_date_gmt' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date($this->date) : current_time('mysql', 1),
821 821
                         'post_parent'   => $this->parent_invoice,
822 822
                     );
823
-        $args = apply_filters( 'wpinv_insert_invoice_args', $post_data, $this );
823
+        $args = apply_filters('wpinv_insert_invoice_args', $post_data, $this);
824 824
 
825 825
         // Create a blank invoice
826
-        if ( !empty( $this->ID ) ) {
827
-            $args['ID']         = $this->ID;
826
+        if (!empty($this->ID)) {
827
+            $args['ID'] = $this->ID;
828 828
 
829
-            $invoice_id = wp_update_post( $args, true );
829
+            $invoice_id = wp_update_post($args, true);
830 830
         } else {
831
-            $invoice_id = wp_insert_post( $args, true );
831
+            $invoice_id = wp_insert_post($args, true);
832 832
         }
833 833
 
834
-        if ( is_wp_error( $invoice_id ) ) {
834
+        if (is_wp_error($invoice_id)) {
835 835
             return false;
836 836
         }
837 837
 
838
-        if ( !empty( $invoice_id ) ) {
838
+        if (!empty($invoice_id)) {
839 839
             $this->ID  = $invoice_id;
840 840
             $this->_ID = $invoice_id;
841 841
 
842
-            $this->payment_meta = apply_filters( 'wpinv_payment_meta', $this->payment_meta, $payment_data );
843
-            if ( ! empty( $this->payment_meta['fees'] ) ) {
844
-                $this->fees = array_merge( $this->fees, $this->payment_meta['fees'] );
845
-                foreach( $this->fees as $fee ) {
846
-                    $this->increase_fees( $fee['amount'] );
842
+            $this->payment_meta = apply_filters('wpinv_payment_meta', $this->payment_meta, $payment_data);
843
+            if (!empty($this->payment_meta['fees'])) {
844
+                $this->fees = array_merge($this->fees, $this->payment_meta['fees']);
845
+                foreach ($this->fees as $fee) {
846
+                    $this->increase_fees($fee['amount']);
847 847
                 }
848 848
             }
849 849
 
850
-            $this->update_meta( '_wpinv_payment_meta', $this->payment_meta );    
850
+            $this->update_meta('_wpinv_payment_meta', $this->payment_meta);    
851 851
             $this->new = true;
852 852
         }
853 853
 
854 854
         return $this->ID;
855 855
     }
856 856
 
857
-    public function save( $setup = false ) {
857
+    public function save($setup = false) {
858 858
         global $wpi_session;
859 859
         
860 860
         $saved = false;
861
-        if ( empty( $this->items ) ) {
861
+        if (empty($this->items)) {
862 862
             return $saved; // Don't save empty invoice.
863 863
         }
864 864
         
865
-        if ( empty( $this->key ) ) {
865
+        if (empty($this->key)) {
866 866
             $this->key = self::generate_key();
867 867
             $this->pending['key'] = $this->key;
868 868
         }
869 869
         
870
-        if ( empty( $this->ID ) ) {
870
+        if (empty($this->ID)) {
871 871
             $invoice_id = $this->insert_invoice();
872 872
 
873
-            if ( false === $invoice_id ) {
873
+            if (false === $invoice_id) {
874 874
                 $saved = false;
875 875
             } else {
876 876
                 $this->ID = $invoice_id;
@@ -878,27 +878,27 @@  discard block
 block discarded – undo
878 878
         }
879 879
 
880 880
         // If we have something pending, let's save it
881
-        if ( !empty( $this->pending ) ) {
881
+        if (!empty($this->pending)) {
882 882
             $total_increase = 0;
883 883
             $total_decrease = 0;
884 884
 
885
-            foreach ( $this->pending as $key => $value ) {
886
-                switch( $key ) {
885
+            foreach ($this->pending as $key => $value) {
886
+                switch ($key) {
887 887
                     case 'items':
888 888
                         // Update totals for pending items
889
-                        foreach ( $this->pending[ $key ] as $item ) {
890
-                            switch( $item['action'] ) {
889
+                        foreach ($this->pending[$key] as $item) {
890
+                            switch ($item['action']) {
891 891
                                 case 'add':
892 892
                                     $price = $item['price'];
893 893
                                     $taxes = $item['tax'];
894 894
 
895
-                                    if ( 'publish' === $this->status ) {
895
+                                    if ('publish' === $this->status) {
896 896
                                         $total_increase += $price;
897 897
                                     }
898 898
                                     break;
899 899
 
900 900
                                 case 'remove':
901
-                                    if ( 'publish' === $this->status ) {
901
+                                    if ('publish' === $this->status) {
902 902
                                         $total_decrease += $item['price'];
903 903
                                     }
904 904
                                     break;
@@ -906,16 +906,16 @@  discard block
 block discarded – undo
906 906
                         }
907 907
                         break;
908 908
                     case 'fees':
909
-                        if ( 'publish' !== $this->status ) {
909
+                        if ('publish' !== $this->status) {
910 910
                             break;
911 911
                         }
912 912
 
913
-                        if ( empty( $this->pending[ $key ] ) ) {
913
+                        if (empty($this->pending[$key])) {
914 914
                             break;
915 915
                         }
916 916
 
917
-                        foreach ( $this->pending[ $key ] as $fee ) {
918
-                            switch( $fee['action'] ) {
917
+                        foreach ($this->pending[$key] as $fee) {
918
+                            switch ($fee['action']) {
919 919
                                 case 'add':
920 920
                                     $total_increase += $fee['amount'];
921 921
                                     break;
@@ -927,86 +927,86 @@  discard block
 block discarded – undo
927 927
                         }
928 928
                         break;
929 929
                     case 'status':
930
-                        $this->update_status( $this->status );
930
+                        $this->update_status($this->status);
931 931
                         break;
932 932
                     case 'gateway':
933
-                        $this->update_meta( '_wpinv_gateway', $this->gateway );
933
+                        $this->update_meta('_wpinv_gateway', $this->gateway);
934 934
                         break;
935 935
                     case 'mode':
936
-                        $this->update_meta( '_wpinv_mode', $this->mode );
936
+                        $this->update_meta('_wpinv_mode', $this->mode);
937 937
                         break;
938 938
                     case 'transaction_id':
939
-                        $this->update_meta( '_wpinv_transaction_id', $this->transaction_id );
939
+                        $this->update_meta('_wpinv_transaction_id', $this->transaction_id);
940 940
                         break;
941 941
                     case 'ip':
942
-                        $this->update_meta( '_wpinv_user_ip', $this->ip );
942
+                        $this->update_meta('_wpinv_user_ip', $this->ip);
943 943
                         break;
944 944
                     ///case 'user_id':
945 945
                         ///$this->update_meta( '_wpinv_user_id', $this->user_id );
946 946
                         ///$this->user_info['user_id'] = $this->user_id;
947 947
                         ///break;
948 948
                     case 'first_name':
949
-                        $this->update_meta( '_wpinv_first_name', $this->first_name );
949
+                        $this->update_meta('_wpinv_first_name', $this->first_name);
950 950
                         $this->user_info['first_name'] = $this->first_name;
951 951
                         break;
952 952
                     case 'last_name':
953
-                        $this->update_meta( '_wpinv_last_name', $this->last_name );
953
+                        $this->update_meta('_wpinv_last_name', $this->last_name);
954 954
                         $this->user_info['last_name'] = $this->last_name;
955 955
                         break;
956 956
                     case 'phone':
957
-                        $this->update_meta( '_wpinv_phone', $this->phone );
957
+                        $this->update_meta('_wpinv_phone', $this->phone);
958 958
                         $this->user_info['phone'] = $this->phone;
959 959
                         break;
960 960
                     case 'address':
961
-                        $this->update_meta( '_wpinv_address', $this->address );
961
+                        $this->update_meta('_wpinv_address', $this->address);
962 962
                         $this->user_info['address'] = $this->address;
963 963
                         break;
964 964
                     case 'city':
965
-                        $this->update_meta( '_wpinv_city', $this->city );
965
+                        $this->update_meta('_wpinv_city', $this->city);
966 966
                         $this->user_info['city'] = $this->city;
967 967
                         break;
968 968
                     case 'country':
969
-                        $this->update_meta( '_wpinv_country', $this->country );
969
+                        $this->update_meta('_wpinv_country', $this->country);
970 970
                         $this->user_info['country'] = $this->country;
971 971
                         break;
972 972
                     case 'state':
973
-                        $this->update_meta( '_wpinv_state', $this->state );
973
+                        $this->update_meta('_wpinv_state', $this->state);
974 974
                         $this->user_info['state'] = $this->state;
975 975
                         break;
976 976
                     case 'zip':
977
-                        $this->update_meta( '_wpinv_zip', $this->zip );
977
+                        $this->update_meta('_wpinv_zip', $this->zip);
978 978
                         $this->user_info['zip'] = $this->zip;
979 979
                         break;
980 980
                     case 'company':
981
-                        $this->update_meta( '_wpinv_company', $this->company );
981
+                        $this->update_meta('_wpinv_company', $this->company);
982 982
                         $this->user_info['company'] = $this->company;
983 983
                         break;
984 984
                     case 'vat_number':
985
-                        $this->update_meta( '_wpinv_vat_number', $this->vat_number );
985
+                        $this->update_meta('_wpinv_vat_number', $this->vat_number);
986 986
                         $this->user_info['vat_number'] = $this->vat_number;
987 987
                         
988
-                        $vat_info = $wpi_session->get( 'user_vat_data' );
989
-                        if ( $this->vat_number && !empty( $vat_info ) && isset( $vat_info['number'] ) && isset( $vat_info['valid'] ) && $vat_info['number'] == $this->vat_number ) {
990
-                            $adddress_confirmed = isset( $vat_info['adddress_confirmed'] ) ? $vat_info['adddress_confirmed'] : false;
991
-                            $this->update_meta( '_wpinv_adddress_confirmed', (bool)$adddress_confirmed );
992
-                            $this->user_info['adddress_confirmed'] = (bool)$adddress_confirmed;
988
+                        $vat_info = $wpi_session->get('user_vat_data');
989
+                        if ($this->vat_number && !empty($vat_info) && isset($vat_info['number']) && isset($vat_info['valid']) && $vat_info['number'] == $this->vat_number) {
990
+                            $adddress_confirmed = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
991
+                            $this->update_meta('_wpinv_adddress_confirmed', (bool) $adddress_confirmed);
992
+                            $this->user_info['adddress_confirmed'] = (bool) $adddress_confirmed;
993 993
                         }
994 994
     
995 995
                         break;
996 996
                     case 'vat_rate':
997
-                        $this->update_meta( '_wpinv_vat_rate', $this->vat_rate );
997
+                        $this->update_meta('_wpinv_vat_rate', $this->vat_rate);
998 998
                         $this->user_info['vat_rate'] = $this->vat_rate;
999 999
                         break;
1000 1000
                     case 'adddress_confirmed':
1001
-                        $this->update_meta( '_wpinv_adddress_confirmed', $this->adddress_confirmed );
1001
+                        $this->update_meta('_wpinv_adddress_confirmed', $this->adddress_confirmed);
1002 1002
                         $this->user_info['adddress_confirmed'] = $this->adddress_confirmed;
1003 1003
                         break;
1004 1004
                     
1005 1005
                     case 'key':
1006
-                        $this->update_meta( '_wpinv_key', $this->key );
1006
+                        $this->update_meta('_wpinv_key', $this->key);
1007 1007
                         break;
1008 1008
                     case 'disable_taxes':
1009
-                        $this->update_meta( '_wpinv_disable_taxes', $this->disable_taxes );
1009
+                        $this->update_meta('_wpinv_disable_taxes', $this->disable_taxes);
1010 1010
                         break;
1011 1011
                     case 'date':
1012 1012
                         $args = array(
@@ -1015,49 +1015,49 @@  discard block
 block discarded – undo
1015 1015
                             'edit_date' => true,
1016 1016
                         );
1017 1017
 
1018
-                        wp_update_post( $args );
1018
+                        wp_update_post($args);
1019 1019
                         break;
1020 1020
                     case 'due_date':
1021
-                        if ( empty( $this->due_date ) ) {
1021
+                        if (empty($this->due_date)) {
1022 1022
                             $this->due_date = 'none';
1023 1023
                         }
1024 1024
                         
1025
-                        $this->update_meta( '_wpinv_due_date', $this->due_date );
1025
+                        $this->update_meta('_wpinv_due_date', $this->due_date);
1026 1026
                         break;
1027 1027
                     case 'completed_date':
1028
-                        $this->update_meta( '_wpinv_completed_date', $this->completed_date );
1028
+                        $this->update_meta('_wpinv_completed_date', $this->completed_date);
1029 1029
                         break;
1030 1030
                     case 'discounts':
1031
-                        if ( ! is_array( $this->discounts ) ) {
1032
-                            $this->discounts = explode( ',', $this->discounts );
1031
+                        if (!is_array($this->discounts)) {
1032
+                            $this->discounts = explode(',', $this->discounts);
1033 1033
                         }
1034 1034
 
1035
-                        $this->user_info['discount'] = implode( ',', $this->discounts );
1035
+                        $this->user_info['discount'] = implode(',', $this->discounts);
1036 1036
                         break;
1037 1037
                     case 'discount':
1038
-                        $this->update_meta( '_wpinv_discount', wpinv_round_amount( $this->discount ) );
1038
+                        $this->update_meta('_wpinv_discount', wpinv_round_amount($this->discount));
1039 1039
                         break;
1040 1040
                     case 'discount_code':
1041
-                        $this->update_meta( '_wpinv_discount_code', $this->discount_code );
1041
+                        $this->update_meta('_wpinv_discount_code', $this->discount_code);
1042 1042
                         break;
1043 1043
                     case 'parent_invoice':
1044 1044
                         $args = array(
1045 1045
                             'ID'          => $this->ID,
1046 1046
                             'post_parent' => $this->parent_invoice,
1047 1047
                         );
1048
-                        wp_update_post( $args );
1048
+                        wp_update_post($args);
1049 1049
                         break;
1050 1050
                     default:
1051
-                        do_action( 'wpinv_save', $this, $key );
1051
+                        do_action('wpinv_save', $this, $key);
1052 1052
                         break;
1053 1053
                 }
1054 1054
             }
1055 1055
 
1056
-            $this->update_meta( '_wpinv_subtotal', wpinv_round_amount( $this->subtotal ) );
1057
-            $this->update_meta( '_wpinv_total', wpinv_round_amount( $this->total ) );
1058
-            $this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) );
1056
+            $this->update_meta('_wpinv_subtotal', wpinv_round_amount($this->subtotal));
1057
+            $this->update_meta('_wpinv_total', wpinv_round_amount($this->total));
1058
+            $this->update_meta('_wpinv_tax', wpinv_round_amount($this->tax));
1059 1059
             
1060
-            $this->items    = array_values( $this->items );
1060
+            $this->items = array_values($this->items);
1061 1061
             
1062 1062
             $new_meta = array(
1063 1063
                 'items'         => $this->items,
@@ -1068,12 +1068,12 @@  discard block
 block discarded – undo
1068 1068
             );
1069 1069
             
1070 1070
             $meta        = $this->get_meta();
1071
-            $merged_meta = array_merge( $meta, $new_meta );
1071
+            $merged_meta = array_merge($meta, $new_meta);
1072 1072
 
1073 1073
             // Only save the payment meta if it's changed
1074
-            if ( md5( serialize( $meta ) ) !== md5( serialize( $merged_meta) ) ) {
1075
-                $updated     = $this->update_meta( '_wpinv_payment_meta', $merged_meta );
1076
-                if ( false !== $updated ) {
1074
+            if (md5(serialize($meta)) !== md5(serialize($merged_meta))) {
1075
+                $updated = $this->update_meta('_wpinv_payment_meta', $merged_meta);
1076
+                if (false !== $updated) {
1077 1077
                     $saved = true;
1078 1078
                 }
1079 1079
             }
@@ -1081,15 +1081,15 @@  discard block
 block discarded – undo
1081 1081
             $this->pending = array();
1082 1082
             $saved         = true;
1083 1083
         } else {
1084
-            $this->update_meta( '_wpinv_subtotal', wpinv_round_amount( $this->subtotal ) );
1085
-            $this->update_meta( '_wpinv_total', wpinv_round_amount( $this->total ) );
1086
-            $this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) );
1084
+            $this->update_meta('_wpinv_subtotal', wpinv_round_amount($this->subtotal));
1085
+            $this->update_meta('_wpinv_total', wpinv_round_amount($this->total));
1086
+            $this->update_meta('_wpinv_tax', wpinv_round_amount($this->tax));
1087 1087
         }
1088 1088
         
1089
-        do_action( 'wpinv_invoice_save', $this, $saved );
1089
+        do_action('wpinv_invoice_save', $this, $saved);
1090 1090
 
1091
-        if ( true === $saved || $setup ) {
1092
-            $this->setup_invoice( $this->ID );
1091
+        if (true === $saved || $setup) {
1092
+            $this->setup_invoice($this->ID);
1093 1093
         }
1094 1094
         
1095 1095
         $this->refresh_item_ids();
@@ -1097,7 +1097,7 @@  discard block
 block discarded – undo
1097 1097
         return $saved;
1098 1098
     }
1099 1099
     
1100
-    public function add_fee( $args, $global = true ) {
1100
+    public function add_fee($args, $global = true) {
1101 1101
         $default_args = array(
1102 1102
             'label'       => '',
1103 1103
             'amount'      => 0,
@@ -1107,75 +1107,75 @@  discard block
 block discarded – undo
1107 1107
             'item_id'     => 0,
1108 1108
         );
1109 1109
 
1110
-        $fee = wp_parse_args( $args, $default_args );
1110
+        $fee = wp_parse_args($args, $default_args);
1111 1111
         
1112
-        if ( empty( $fee['label'] ) ) {
1112
+        if (empty($fee['label'])) {
1113 1113
             return false;
1114 1114
         }
1115 1115
         
1116
-        $fee['id']  = sanitize_title( $fee['label'] );
1116
+        $fee['id'] = sanitize_title($fee['label']);
1117 1117
         
1118
-        $this->fees[]               = $fee;
1118
+        $this->fees[] = $fee;
1119 1119
         
1120 1120
         $added_fee               = $fee;
1121 1121
         $added_fee['action']     = 'add';
1122 1122
         $this->pending['fees'][] = $added_fee;
1123
-        reset( $this->fees );
1123
+        reset($this->fees);
1124 1124
 
1125
-        $this->increase_fees( $fee['amount'] );
1125
+        $this->increase_fees($fee['amount']);
1126 1126
         return true;
1127 1127
     }
1128 1128
 
1129
-    public function remove_fee( $key ) {
1129
+    public function remove_fee($key) {
1130 1130
         $removed = false;
1131 1131
 
1132
-        if ( is_numeric( $key ) ) {
1133
-            $removed = $this->remove_fee_by( 'index', $key );
1132
+        if (is_numeric($key)) {
1133
+            $removed = $this->remove_fee_by('index', $key);
1134 1134
         }
1135 1135
 
1136 1136
         return $removed;
1137 1137
     }
1138 1138
 
1139
-    public function remove_fee_by( $key, $value, $global = false ) {
1140
-        $allowed_fee_keys = apply_filters( 'wpinv_fee_keys', array(
1139
+    public function remove_fee_by($key, $value, $global = false) {
1140
+        $allowed_fee_keys = apply_filters('wpinv_fee_keys', array(
1141 1141
             'index', 'label', 'amount', 'type',
1142
-        ) );
1142
+        ));
1143 1143
 
1144
-        if ( ! in_array( $key, $allowed_fee_keys ) ) {
1144
+        if (!in_array($key, $allowed_fee_keys)) {
1145 1145
             return false;
1146 1146
         }
1147 1147
 
1148 1148
         $removed = false;
1149
-        if ( 'index' === $key && array_key_exists( $value, $this->fees ) ) {
1150
-            $removed_fee             = $this->fees[ $value ];
1149
+        if ('index' === $key && array_key_exists($value, $this->fees)) {
1150
+            $removed_fee             = $this->fees[$value];
1151 1151
             $removed_fee['action']   = 'remove';
1152 1152
             $this->pending['fees'][] = $removed_fee;
1153 1153
 
1154
-            $this->decrease_fees( $removed_fee['amount'] );
1154
+            $this->decrease_fees($removed_fee['amount']);
1155 1155
 
1156
-            unset( $this->fees[ $value ] );
1156
+            unset($this->fees[$value]);
1157 1157
             $removed = true;
1158
-        } else if ( 'index' !== $key ) {
1159
-            foreach ( $this->fees as $index => $fee ) {
1160
-                if ( isset( $fee[ $key ] ) && $fee[ $key ] == $value ) {
1158
+        } else if ('index' !== $key) {
1159
+            foreach ($this->fees as $index => $fee) {
1160
+                if (isset($fee[$key]) && $fee[$key] == $value) {
1161 1161
                     $removed_fee             = $fee;
1162 1162
                     $removed_fee['action']   = 'remove';
1163 1163
                     $this->pending['fees'][] = $removed_fee;
1164 1164
 
1165
-                    $this->decrease_fees( $removed_fee['amount'] );
1165
+                    $this->decrease_fees($removed_fee['amount']);
1166 1166
 
1167
-                    unset( $this->fees[ $index ] );
1167
+                    unset($this->fees[$index]);
1168 1168
                     $removed = true;
1169 1169
 
1170
-                    if ( false === $global ) {
1170
+                    if (false === $global) {
1171 1171
                         break;
1172 1172
                     }
1173 1173
                 }
1174 1174
             }
1175 1175
         }
1176 1176
 
1177
-        if ( true === $removed ) {
1178
-            $this->fees = array_values( $this->fees );
1177
+        if (true === $removed) {
1178
+            $this->fees = array_values($this->fees);
1179 1179
         }
1180 1180
 
1181 1181
         return $removed;
@@ -1183,35 +1183,35 @@  discard block
 block discarded – undo
1183 1183
 
1184 1184
     
1185 1185
 
1186
-    public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) {
1186
+    public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) {
1187 1187
         // Bail if no note specified
1188
-        if( !$note ) {
1188
+        if (!$note) {
1189 1189
             return false;
1190 1190
         }
1191 1191
 
1192
-        if ( empty( $this->ID ) )
1192
+        if (empty($this->ID))
1193 1193
             return false;
1194 1194
         
1195
-        if ( ( ( is_user_logged_in() && wpinv_current_user_can_manage_invoicing() ) || $added_by_user ) && !$system ) {
1196
-            $user                 = get_user_by( 'id', get_current_user_id() );
1195
+        if (((is_user_logged_in() && wpinv_current_user_can_manage_invoicing()) || $added_by_user) && !$system) {
1196
+            $user                 = get_user_by('id', get_current_user_id());
1197 1197
             $comment_author       = $user->display_name;
1198 1198
             $comment_author_email = $user->user_email;
1199 1199
         } else {
1200 1200
             $comment_author       = 'System';
1201 1201
             $comment_author_email = 'system@';
1202
-            $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ) : 'noreply.com';
1203
-            $comment_author_email = sanitize_email( $comment_author_email );
1202
+            $comment_author_email .= isset($_SERVER['HTTP_HOST']) ? str_replace('www.', '', $_SERVER['HTTP_HOST']) : 'noreply.com';
1203
+            $comment_author_email = sanitize_email($comment_author_email);
1204 1204
         }
1205 1205
 
1206
-        do_action( 'wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type );
1206
+        do_action('wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type);
1207 1207
 
1208
-        $note_id = wp_insert_comment( wp_filter_comment( array(
1208
+        $note_id = wp_insert_comment(wp_filter_comment(array(
1209 1209
             'comment_post_ID'      => $this->ID,
1210 1210
             'comment_content'      => $note,
1211 1211
             'comment_agent'        => 'WPInvoicing',
1212 1212
             'user_id'              => is_admin() ? get_current_user_id() : 0,
1213
-            'comment_date'         => current_time( 'mysql' ),
1214
-            'comment_date_gmt'     => current_time( 'mysql', 1 ),
1213
+            'comment_date'         => current_time('mysql'),
1214
+            'comment_date_gmt'     => current_time('mysql', 1),
1215 1215
             'comment_approved'     => 1,
1216 1216
             'comment_parent'       => 0,
1217 1217
             'comment_author'       => $comment_author,
@@ -1219,53 +1219,53 @@  discard block
 block discarded – undo
1219 1219
             'comment_author_url'   => '',
1220 1220
             'comment_author_email' => $comment_author_email,
1221 1221
             'comment_type'         => 'wpinv_note'
1222
-        ) ) );
1222
+        )));
1223 1223
 
1224
-        do_action( 'wpinv_insert_payment_note', $note_id, $this->ID, $note );
1224
+        do_action('wpinv_insert_payment_note', $note_id, $this->ID, $note);
1225 1225
         
1226
-        if ( $customer_type ) {
1227
-            add_comment_meta( $note_id, '_wpi_customer_note', 1 );
1226
+        if ($customer_type) {
1227
+            add_comment_meta($note_id, '_wpi_customer_note', 1);
1228 1228
 
1229
-            do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $this->ID, 'user_note' => $note ) );
1229
+            do_action('wpinv_new_customer_note', array('invoice_id' => $this->ID, 'user_note' => $note));
1230 1230
         }
1231 1231
 
1232 1232
         return $note_id;
1233 1233
     }
1234 1234
 
1235
-    private function increase_subtotal( $amount = 0.00 ) {
1235
+    private function increase_subtotal($amount = 0.00) {
1236 1236
         $amount          = (float) $amount;
1237 1237
         $this->subtotal += $amount;
1238
-        $this->subtotal  = wpinv_round_amount( $this->subtotal );
1238
+        $this->subtotal  = wpinv_round_amount($this->subtotal);
1239 1239
 
1240 1240
         $this->recalculate_total();
1241 1241
     }
1242 1242
 
1243
-    private function decrease_subtotal( $amount = 0.00 ) {
1243
+    private function decrease_subtotal($amount = 0.00) {
1244 1244
         $amount          = (float) $amount;
1245 1245
         $this->subtotal -= $amount;
1246
-        $this->subtotal  = wpinv_round_amount( $this->subtotal );
1246
+        $this->subtotal  = wpinv_round_amount($this->subtotal);
1247 1247
 
1248
-        if ( $this->subtotal < 0 ) {
1248
+        if ($this->subtotal < 0) {
1249 1249
             $this->subtotal = 0;
1250 1250
         }
1251 1251
 
1252 1252
         $this->recalculate_total();
1253 1253
     }
1254 1254
 
1255
-    private function increase_fees( $amount = 0.00 ) {
1256
-        $amount            = (float)$amount;
1255
+    private function increase_fees($amount = 0.00) {
1256
+        $amount            = (float) $amount;
1257 1257
         $this->fees_total += $amount;
1258
-        $this->fees_total  = wpinv_round_amount( $this->fees_total );
1258
+        $this->fees_total  = wpinv_round_amount($this->fees_total);
1259 1259
 
1260 1260
         $this->recalculate_total();
1261 1261
     }
1262 1262
 
1263
-    private function decrease_fees( $amount = 0.00 ) {
1263
+    private function decrease_fees($amount = 0.00) {
1264 1264
         $amount            = (float) $amount;
1265 1265
         $this->fees_total -= $amount;
1266
-        $this->fees_total  = wpinv_round_amount( $this->fees_total );
1266
+        $this->fees_total  = wpinv_round_amount($this->fees_total);
1267 1267
 
1268
-        if ( $this->fees_total < 0 ) {
1268
+        if ($this->fees_total < 0) {
1269 1269
             $this->fees_total = 0;
1270 1270
         }
1271 1271
 
@@ -1276,54 +1276,54 @@  discard block
 block discarded – undo
1276 1276
         global $wpi_nosave;
1277 1277
         
1278 1278
         $this->total = $this->subtotal + $this->tax + $this->fees_total;
1279
-        $this->total = wpinv_round_amount( $this->total );
1279
+        $this->total = wpinv_round_amount($this->total);
1280 1280
         
1281
-        do_action( 'wpinv_invoice_recalculate_total', $this, $wpi_nosave );
1281
+        do_action('wpinv_invoice_recalculate_total', $this, $wpi_nosave);
1282 1282
     }
1283 1283
     
1284
-    public function increase_tax( $amount = 0.00 ) {
1284
+    public function increase_tax($amount = 0.00) {
1285 1285
         $amount       = (float) $amount;
1286 1286
         $this->tax   += $amount;
1287 1287
 
1288 1288
         $this->recalculate_total();
1289 1289
     }
1290 1290
 
1291
-    public function decrease_tax( $amount = 0.00 ) {
1291
+    public function decrease_tax($amount = 0.00) {
1292 1292
         $amount     = (float) $amount;
1293 1293
         $this->tax -= $amount;
1294 1294
 
1295
-        if ( $this->tax < 0 ) {
1295
+        if ($this->tax < 0) {
1296 1296
             $this->tax = 0;
1297 1297
         }
1298 1298
 
1299 1299
         $this->recalculate_total();
1300 1300
     }
1301 1301
 
1302
-    public function update_status( $new_status = false, $note = '', $manual = false ) {
1303
-        $old_status = ! empty( $this->old_status ) ? $this->old_status : get_post_status( $this->ID );
1302
+    public function update_status($new_status = false, $note = '', $manual = false) {
1303
+        $old_status = !empty($this->old_status) ? $this->old_status : get_post_status($this->ID);
1304 1304
 
1305
-        if ( $old_status === $new_status && in_array( $new_status, array_keys( wpinv_get_invoice_statuses( true ) ) ) ) {
1305
+        if ($old_status === $new_status && in_array($new_status, array_keys(wpinv_get_invoice_statuses(true)))) {
1306 1306
             return false; // Don't permit status changes that aren't changes
1307 1307
         }
1308 1308
 
1309
-        $do_change = apply_filters( 'wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status );
1309
+        $do_change = apply_filters('wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status);
1310 1310
         $updated = false;
1311 1311
 
1312
-        if ( $do_change ) {
1313
-            do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status );
1312
+        if ($do_change) {
1313
+            do_action('wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status);
1314 1314
 
1315 1315
             $update_post_data                   = array();
1316 1316
             $update_post_data['ID']             = $this->ID;
1317 1317
             $update_post_data['post_status']    = $new_status;
1318
-            $update_post_data['edit_date']      = current_time( 'mysql', 0 );
1319
-            $update_post_data['edit_date_gmt']  = current_time( 'mysql', 1 );
1318
+            $update_post_data['edit_date']      = current_time('mysql', 0);
1319
+            $update_post_data['edit_date_gmt']  = current_time('mysql', 1);
1320 1320
             
1321
-            $update_post_data = apply_filters( 'wpinv_update_invoice_status_fields', $update_post_data, $this->ID );
1321
+            $update_post_data = apply_filters('wpinv_update_invoice_status_fields', $update_post_data, $this->ID);
1322 1322
 
1323
-            $updated = wp_update_post( $update_post_data );     
1323
+            $updated = wp_update_post($update_post_data);     
1324 1324
            
1325 1325
             // Process any specific status functions
1326
-            switch( $new_status ) {
1326
+            switch ($new_status) {
1327 1327
                 case 'wpi-refunded':
1328 1328
                     $this->process_refund();
1329 1329
                     break;
@@ -1336,9 +1336,9 @@  discard block
 block discarded – undo
1336 1336
             }
1337 1337
             
1338 1338
             // Status was changed.
1339
-            do_action( 'wpinv_status_' . $new_status, $this->ID, $old_status );
1340
-            do_action( 'wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status );
1341
-            do_action( 'wpinv_update_status', $this->ID, $new_status, $old_status );
1339
+            do_action('wpinv_status_' . $new_status, $this->ID, $old_status);
1340
+            do_action('wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status);
1341
+            do_action('wpinv_update_status', $this->ID, $new_status, $old_status);
1342 1342
         }
1343 1343
 
1344 1344
         return $updated;
@@ -1352,20 +1352,20 @@  discard block
 block discarded – undo
1352 1352
         $this->save();
1353 1353
     }
1354 1354
 
1355
-    public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) {
1356
-        if ( empty( $meta_key ) ) {
1355
+    public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') {
1356
+        if (empty($meta_key)) {
1357 1357
             return false;
1358 1358
         }
1359 1359
 
1360
-        if ( $meta_key == 'key' || $meta_key == 'date' ) {
1360
+        if ($meta_key == 'key' || $meta_key == 'date') {
1361 1361
             $current_meta = $this->get_meta();
1362
-            $current_meta[ $meta_key ] = $meta_value;
1362
+            $current_meta[$meta_key] = $meta_value;
1363 1363
 
1364 1364
             $meta_key     = '_wpinv_payment_meta';
1365 1365
             $meta_value   = $current_meta;
1366 1366
         }
1367 1367
 
1368
-        $meta_value = apply_filters( 'wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID );
1368
+        $meta_value = apply_filters('wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID);
1369 1369
         
1370 1370
         // Do not update created date on invoice marked as paid.
1371 1371
         /*if ( $meta_key == '_wpinv_completed_date' && !empty( $meta_value ) ) {
@@ -1380,45 +1380,45 @@  discard block
 block discarded – undo
1380 1380
             wp_update_post( $args );
1381 1381
         }*/
1382 1382
         
1383
-        return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value );
1383
+        return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value);
1384 1384
     }
1385 1385
 
1386 1386
     private function process_refund() {
1387 1387
         $process_refund = true;
1388 1388
 
1389 1389
         // If the payment was not in publish, don't decrement stats as they were never incremented
1390
-        if ( 'publish' != $this->old_status || 'wpi-refunded' != $this->status ) {
1390
+        if ('publish' != $this->old_status || 'wpi-refunded' != $this->status) {
1391 1391
             $process_refund = false;
1392 1392
         }
1393 1393
 
1394 1394
         // Allow extensions to filter for their own payment types, Example: Recurring Payments
1395
-        $process_refund = apply_filters( 'wpinv_should_process_refund', $process_refund, $this );
1395
+        $process_refund = apply_filters('wpinv_should_process_refund', $process_refund, $this);
1396 1396
 
1397
-        if ( false === $process_refund ) {
1397
+        if (false === $process_refund) {
1398 1398
             return;
1399 1399
         }
1400 1400
 
1401
-        do_action( 'wpinv_pre_refund_invoice', $this );
1401
+        do_action('wpinv_pre_refund_invoice', $this);
1402 1402
         
1403
-        $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_refund', true, $this );
1404
-        $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_refund', true, $this );
1405
-        $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_refund', true, $this );
1403
+        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_refund', true, $this);
1404
+        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_refund', true, $this);
1405
+        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_refund', true, $this);
1406 1406
         
1407
-        do_action( 'wpinv_post_refund_invoice', $this );
1407
+        do_action('wpinv_post_refund_invoice', $this);
1408 1408
     }
1409 1409
 
1410 1410
     private function process_failure() {
1411 1411
         $discounts = $this->discounts;
1412
-        if ( empty( $discounts ) ) {
1412
+        if (empty($discounts)) {
1413 1413
             return;
1414 1414
         }
1415 1415
 
1416
-        if ( ! is_array( $discounts ) ) {
1417
-            $discounts = array_map( 'trim', explode( ',', $discounts ) );
1416
+        if (!is_array($discounts)) {
1417
+            $discounts = array_map('trim', explode(',', $discounts));
1418 1418
         }
1419 1419
 
1420
-        foreach ( $discounts as $discount ) {
1421
-            wpinv_decrease_discount_usage( $discount );
1420
+        foreach ($discounts as $discount) {
1421
+            wpinv_decrease_discount_usage($discount);
1422 1422
         }
1423 1423
     }
1424 1424
     
@@ -1426,92 +1426,92 @@  discard block
 block discarded – undo
1426 1426
         $process_pending = true;
1427 1427
 
1428 1428
         // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented
1429
-        if ( ( 'publish' != $this->old_status && 'revoked' != $this->old_status ) || 'wpi-pending' != $this->status ) {
1429
+        if (('publish' != $this->old_status && 'revoked' != $this->old_status) || 'wpi-pending' != $this->status) {
1430 1430
             $process_pending = false;
1431 1431
         }
1432 1432
 
1433 1433
         // Allow extensions to filter for their own payment types, Example: Recurring Payments
1434
-        $process_pending = apply_filters( 'wpinv_should_process_pending', $process_pending, $this );
1434
+        $process_pending = apply_filters('wpinv_should_process_pending', $process_pending, $this);
1435 1435
 
1436
-        if ( false === $process_pending ) {
1436
+        if (false === $process_pending) {
1437 1437
             return;
1438 1438
         }
1439 1439
 
1440
-        $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_pending', true, $this );
1441
-        $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_pending', true, $this );
1442
-        $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_pending', true, $this );
1440
+        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_pending', true, $this);
1441
+        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_pending', true, $this);
1442
+        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_pending', true, $this);
1443 1443
 
1444 1444
         $this->completed_date = '';
1445
-        $this->update_meta( '_wpinv_completed_date', '' );
1445
+        $this->update_meta('_wpinv_completed_date', '');
1446 1446
     }
1447 1447
     
1448 1448
     // get data
1449
-    public function get_meta( $meta_key = '_wpinv_payment_meta', $single = true ) {
1450
-        $meta = get_post_meta( $this->ID, $meta_key, $single );
1449
+    public function get_meta($meta_key = '_wpinv_payment_meta', $single = true) {
1450
+        $meta = get_post_meta($this->ID, $meta_key, $single);
1451 1451
 
1452
-        if ( $meta_key === '_wpinv_payment_meta' ) {
1452
+        if ($meta_key === '_wpinv_payment_meta') {
1453 1453
 
1454
-            if(!is_array($meta)){$meta = array();} // we need this to be an array so make sure it is.
1454
+            if (!is_array($meta)) {$meta = array(); } // we need this to be an array so make sure it is.
1455 1455
 
1456
-            if ( empty( $meta['key'] ) ) {
1456
+            if (empty($meta['key'])) {
1457 1457
                 $meta['key'] = $this->setup_invoice_key();
1458 1458
             }
1459 1459
 
1460
-            if ( empty( $meta['date'] ) ) {
1461
-                $meta['date'] = get_post_field( 'post_date', $this->ID );
1460
+            if (empty($meta['date'])) {
1461
+                $meta['date'] = get_post_field('post_date', $this->ID);
1462 1462
             }
1463 1463
         }
1464 1464
 
1465
-        $meta = apply_filters( 'wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID );
1465
+        $meta = apply_filters('wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID);
1466 1466
 
1467
-        return apply_filters( 'wpinv_get_invoice_meta', $meta, $this->ID, $meta_key );
1467
+        return apply_filters('wpinv_get_invoice_meta', $meta, $this->ID, $meta_key);
1468 1468
     }
1469 1469
     
1470 1470
     public function get_description() {
1471
-        $post = get_post( $this->ID );
1471
+        $post = get_post($this->ID);
1472 1472
         
1473
-        $description = !empty( $post ) ? $post->post_content : '';
1474
-        return apply_filters( 'wpinv_get_description', $description, $this->ID, $this );
1473
+        $description = !empty($post) ? $post->post_content : '';
1474
+        return apply_filters('wpinv_get_description', $description, $this->ID, $this);
1475 1475
     }
1476 1476
     
1477
-    public function get_status( $nicename = false ) {
1478
-        if ( !$nicename ) {
1477
+    public function get_status($nicename = false) {
1478
+        if (!$nicename) {
1479 1479
             $status = $this->status;
1480 1480
         } else {
1481 1481
             $status = $this->status_nicename;
1482 1482
         }
1483 1483
         
1484
-        return apply_filters( 'wpinv_get_status', $status, $nicename, $this->ID, $this );
1484
+        return apply_filters('wpinv_get_status', $status, $nicename, $this->ID, $this);
1485 1485
     }
1486 1486
     
1487 1487
     public function get_cart_details() {
1488
-        return apply_filters( 'wpinv_cart_details', $this->cart_details, $this->ID, $this );
1488
+        return apply_filters('wpinv_cart_details', $this->cart_details, $this->ID, $this);
1489 1489
     }
1490 1490
     
1491
-    public function get_subtotal( $currency = false ) {
1492
-        $subtotal = wpinv_round_amount( $this->subtotal );
1491
+    public function get_subtotal($currency = false) {
1492
+        $subtotal = wpinv_round_amount($this->subtotal);
1493 1493
         
1494
-        if ( $currency ) {
1495
-            $subtotal = wpinv_price( wpinv_format_amount( $subtotal, NULL, !$currency ), $this->get_currency() );
1494
+        if ($currency) {
1495
+            $subtotal = wpinv_price(wpinv_format_amount($subtotal, NULL, !$currency), $this->get_currency());
1496 1496
         }
1497 1497
         
1498
-        return apply_filters( 'wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency );
1498
+        return apply_filters('wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency);
1499 1499
     }
1500 1500
     
1501
-    public function get_total( $currency = false ) {        
1502
-        if ( $this->is_free_trial() ) {
1503
-            $total = wpinv_round_amount( 0 );
1501
+    public function get_total($currency = false) {        
1502
+        if ($this->is_free_trial()) {
1503
+            $total = wpinv_round_amount(0);
1504 1504
         } else {
1505
-            $total = wpinv_round_amount( $this->total );
1505
+            $total = wpinv_round_amount($this->total);
1506 1506
         }
1507
-        if ( $currency ) {
1508
-            $total = wpinv_price( wpinv_format_amount( $total, NULL, !$currency ), $this->get_currency() );
1507
+        if ($currency) {
1508
+            $total = wpinv_price(wpinv_format_amount($total, NULL, !$currency), $this->get_currency());
1509 1509
         }
1510 1510
         
1511
-        return apply_filters( 'wpinv_get_invoice_total', $total, $this->ID, $this, $currency );
1511
+        return apply_filters('wpinv_get_invoice_total', $total, $this->ID, $this, $currency);
1512 1512
     }
1513 1513
     
1514
-    public function get_recurring_details( $field = '', $currency = false ) {        
1514
+    public function get_recurring_details($field = '', $currency = false) {        
1515 1515
         $data                 = array();
1516 1516
         $data['cart_details'] = $this->cart_details;
1517 1517
         $data['subtotal']     = $this->get_subtotal();
@@ -1519,119 +1519,119 @@  discard block
 block discarded – undo
1519 1519
         $data['tax']          = $this->get_tax();
1520 1520
         $data['total']        = $this->get_total();
1521 1521
     
1522
-        if ( !empty( $this->cart_details ) && ( $this->is_parent() || $this->is_renewal() ) ) {
1522
+        if (!empty($this->cart_details) && ($this->is_parent() || $this->is_renewal())) {
1523 1523
             $is_free_trial = $this->is_free_trial();
1524
-            $discounts = $this->get_discounts( true );
1524
+            $discounts = $this->get_discounts(true);
1525 1525
             
1526
-            if ( $is_free_trial || !empty( $discounts ) ) {
1526
+            if ($is_free_trial || !empty($discounts)) {
1527 1527
                 $first_use_only = false;
1528 1528
                 
1529
-                if ( !empty( $discounts ) ) {
1530
-                    foreach ( $discounts as $key => $code ) {
1531
-                        if ( wpinv_discount_is_recurring( $code, true ) && !$this->is_renewal() ) {
1529
+                if (!empty($discounts)) {
1530
+                    foreach ($discounts as $key => $code) {
1531
+                        if (wpinv_discount_is_recurring($code, true) && !$this->is_renewal()) {
1532 1532
                             $first_use_only = true;
1533 1533
                             break;
1534 1534
                         }
1535 1535
                     }
1536 1536
                 }
1537 1537
                     
1538
-                if ( !$first_use_only ) {
1539
-                    $data['subtotal'] = wpinv_round_amount( $this->subtotal );
1540
-                    $data['discount'] = wpinv_round_amount( $this->discount );
1541
-                    $data['tax']      = wpinv_round_amount( $this->tax );
1542
-                    $data['total']    = wpinv_round_amount( $this->total );
1538
+                if (!$first_use_only) {
1539
+                    $data['subtotal'] = wpinv_round_amount($this->subtotal);
1540
+                    $data['discount'] = wpinv_round_amount($this->discount);
1541
+                    $data['tax']      = wpinv_round_amount($this->tax);
1542
+                    $data['total']    = wpinv_round_amount($this->total);
1543 1543
                 } else {
1544 1544
                     $cart_subtotal   = 0;
1545 1545
                     $cart_discount   = $this->discount;
1546 1546
                     $cart_tax        = 0;
1547 1547
 
1548
-                    foreach ( $this->cart_details as $key => $item ) {
1549
-                        $item_quantity  = $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
1550
-                        $item_subtotal  = !empty( $item['subtotal'] ) ? $item['subtotal'] : $item['item_price'] * $item_quantity;
1548
+                    foreach ($this->cart_details as $key => $item) {
1549
+                        $item_quantity  = $item['quantity'] > 0 ? absint($item['quantity']) : 1;
1550
+                        $item_subtotal  = !empty($item['subtotal']) ? $item['subtotal'] : $item['item_price'] * $item_quantity;
1551 1551
                         $item_discount  = 0;
1552
-                        $item_tax       = $item_subtotal > 0 && !empty( $item['vat_rate'] ) ? ( $item_subtotal * 0.01 * (float)$item['vat_rate'] ) : 0;
1552
+                        $item_tax       = $item_subtotal > 0 && !empty($item['vat_rate']) ? ($item_subtotal * 0.01 * (float) $item['vat_rate']) : 0;
1553 1553
                         
1554
-                        if ( wpinv_prices_include_tax() ) {
1555
-                            $item_subtotal -= wpinv_round_amount( $item_tax );
1554
+                        if (wpinv_prices_include_tax()) {
1555
+                            $item_subtotal -= wpinv_round_amount($item_tax);
1556 1556
                         }
1557 1557
                         
1558 1558
                         $item_total     = $item_subtotal - $item_discount + $item_tax;
1559 1559
                         // Do not allow totals to go negative
1560
-                        if ( $item_total < 0 ) {
1560
+                        if ($item_total < 0) {
1561 1561
                             $item_total = 0;
1562 1562
                         }
1563 1563
                         
1564
-                        $cart_subtotal  += (float)($item_subtotal);
1565
-                        $cart_discount  += (float)($item_discount);
1566
-                        $cart_tax       += (float)($item_tax);
1564
+                        $cart_subtotal  += (float) ($item_subtotal);
1565
+                        $cart_discount  += (float) ($item_discount);
1566
+                        $cart_tax       += (float) ($item_tax);
1567 1567
                         
1568
-                        $data['cart_details'][$key]['discount']   = wpinv_round_amount( $item_discount );
1569
-                        $data['cart_details'][$key]['tax']        = wpinv_round_amount( $item_tax );
1570
-                        $data['cart_details'][$key]['price']      = wpinv_round_amount( $item_total );
1568
+                        $data['cart_details'][$key]['discount']   = wpinv_round_amount($item_discount);
1569
+                        $data['cart_details'][$key]['tax']        = wpinv_round_amount($item_tax);
1570
+                        $data['cart_details'][$key]['price']      = wpinv_round_amount($item_total);
1571 1571
                     }
1572 1572
 
1573 1573
 	                $total = $data['subtotal'] - $data['discount'] + $data['tax'];
1574
-	                if ( $total < 0 ) {
1574
+	                if ($total < 0) {
1575 1575
 		                $total = 0;
1576 1576
 	                }
1577 1577
 
1578
-                    $data['subtotal'] = wpinv_round_amount( $cart_subtotal );
1579
-                    $data['discount'] = wpinv_round_amount( $cart_discount );
1580
-                    $data['tax']      = wpinv_round_amount( $cart_tax );
1581
-                    $data['total']    = wpinv_round_amount( $total );
1578
+                    $data['subtotal'] = wpinv_round_amount($cart_subtotal);
1579
+                    $data['discount'] = wpinv_round_amount($cart_discount);
1580
+                    $data['tax']      = wpinv_round_amount($cart_tax);
1581
+                    $data['total']    = wpinv_round_amount($total);
1582 1582
                 }
1583 1583
             }
1584 1584
         }
1585 1585
         
1586
-        $data = apply_filters( 'wpinv_get_invoice_recurring_details', $data, $this, $field, $currency );
1586
+        $data = apply_filters('wpinv_get_invoice_recurring_details', $data, $this, $field, $currency);
1587 1587
 
1588
-        if ( isset( $data[$field] ) ) {
1589
-            return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] );
1588
+        if (isset($data[$field])) {
1589
+            return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]);
1590 1590
         }
1591 1591
         
1592 1592
         return $data;
1593 1593
     }
1594 1594
     
1595
-    public function get_final_tax( $currency = false ) {        
1596
-        $final_total = wpinv_round_amount( $this->tax );
1597
-        if ( $currency ) {
1598
-            $final_total = wpinv_price( wpinv_format_amount( $final_total, NULL, !$currency ), $this->get_currency() );
1595
+    public function get_final_tax($currency = false) {        
1596
+        $final_total = wpinv_round_amount($this->tax);
1597
+        if ($currency) {
1598
+            $final_total = wpinv_price(wpinv_format_amount($final_total, NULL, !$currency), $this->get_currency());
1599 1599
         }
1600 1600
         
1601
-        return apply_filters( 'wpinv_get_invoice_final_total', $final_total, $this, $currency );
1601
+        return apply_filters('wpinv_get_invoice_final_total', $final_total, $this, $currency);
1602 1602
     }
1603 1603
     
1604
-    public function get_discounts( $array = false ) {
1604
+    public function get_discounts($array = false) {
1605 1605
         $discounts = $this->discounts;
1606
-        if ( $array && $discounts ) {
1607
-            $discounts = explode( ',', $discounts );
1606
+        if ($array && $discounts) {
1607
+            $discounts = explode(',', $discounts);
1608 1608
         }
1609
-        return apply_filters( 'wpinv_payment_discounts', $discounts, $this->ID, $this, $array );
1609
+        return apply_filters('wpinv_payment_discounts', $discounts, $this->ID, $this, $array);
1610 1610
     }
1611 1611
     
1612
-    public function get_discount( $currency = false, $dash = false ) {
1613
-        if ( !empty( $this->discounts ) ) {
1612
+    public function get_discount($currency = false, $dash = false) {
1613
+        if (!empty($this->discounts)) {
1614 1614
             global $ajax_cart_details;
1615 1615
             $ajax_cart_details = $this->get_cart_details();
1616 1616
             
1617
-            if ( !empty( $ajax_cart_details ) && count( $ajax_cart_details ) == count( $this->items ) ) {
1617
+            if (!empty($ajax_cart_details) && count($ajax_cart_details) == count($this->items)) {
1618 1618
                 $cart_items = $ajax_cart_details;
1619 1619
             } else {
1620 1620
                 $cart_items = $this->items;
1621 1621
             }
1622 1622
 
1623
-            $this->discount = wpinv_get_cart_items_discount_amount( $cart_items , $this->discounts );
1623
+            $this->discount = wpinv_get_cart_items_discount_amount($cart_items, $this->discounts);
1624 1624
         }
1625
-        $discount   = wpinv_round_amount( $this->discount );
1625
+        $discount   = wpinv_round_amount($this->discount);
1626 1626
         $dash       = $dash && $discount > 0 ? '&ndash;' : '';
1627 1627
         
1628
-        if ( $currency ) {
1629
-            $discount = wpinv_price( wpinv_format_amount( $discount, NULL, !$currency ), $this->get_currency() );
1628
+        if ($currency) {
1629
+            $discount = wpinv_price(wpinv_format_amount($discount, NULL, !$currency), $this->get_currency());
1630 1630
         }
1631 1631
         
1632
-        $discount   = $dash . $discount;
1632
+        $discount = $dash . $discount;
1633 1633
         
1634
-        return apply_filters( 'wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash );
1634
+        return apply_filters('wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash);
1635 1635
     }
1636 1636
     
1637 1637
     public function get_discount_code() {
@@ -1643,49 +1643,49 @@  discard block
 block discarded – undo
1643 1643
         return (int) $this->disable_taxes === 0;
1644 1644
     }
1645 1645
 
1646
-    public function get_tax( $currency = false ) {
1647
-        $tax = wpinv_round_amount( $this->tax );
1646
+    public function get_tax($currency = false) {
1647
+        $tax = wpinv_round_amount($this->tax);
1648 1648
 
1649
-        if ( $currency ) {
1650
-            $tax = wpinv_price( wpinv_format_amount( $tax, NULL, !$currency ), $this->get_currency() );
1649
+        if ($currency) {
1650
+            $tax = wpinv_price(wpinv_format_amount($tax, NULL, !$currency), $this->get_currency());
1651 1651
         }
1652 1652
 
1653
-        if ( ! $this->is_taxable() ) {
1654
-            $tax = wpinv_round_amount( 0.00 );
1653
+        if (!$this->is_taxable()) {
1654
+            $tax = wpinv_round_amount(0.00);
1655 1655
         }
1656 1656
 
1657
-        return apply_filters( 'wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency );
1657
+        return apply_filters('wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency);
1658 1658
     }
1659 1659
     
1660
-    public function get_fees( $type = 'all' ) {
1661
-        $fees    = array();
1660
+    public function get_fees($type = 'all') {
1661
+        $fees = array();
1662 1662
 
1663
-        if ( ! empty( $this->fees ) && is_array( $this->fees ) ) {
1664
-            foreach ( $this->fees as $fee ) {
1665
-                if( 'all' != $type && ! empty( $fee['type'] ) && $type != $fee['type'] ) {
1663
+        if (!empty($this->fees) && is_array($this->fees)) {
1664
+            foreach ($this->fees as $fee) {
1665
+                if ('all' != $type && !empty($fee['type']) && $type != $fee['type']) {
1666 1666
                     continue;
1667 1667
                 }
1668 1668
 
1669
-                $fee['label'] = stripslashes( $fee['label'] );
1670
-                $fee['amount_display'] = wpinv_price( $fee['amount'], $this->get_currency() );
1671
-                $fees[]    = $fee;
1669
+                $fee['label'] = stripslashes($fee['label']);
1670
+                $fee['amount_display'] = wpinv_price($fee['amount'], $this->get_currency());
1671
+                $fees[] = $fee;
1672 1672
             }
1673 1673
         }
1674 1674
 
1675
-        return apply_filters( 'wpinv_get_invoice_fees', $fees, $this->ID, $this );
1675
+        return apply_filters('wpinv_get_invoice_fees', $fees, $this->ID, $this);
1676 1676
     }
1677 1677
     
1678
-    public function get_fees_total( $type = 'all' ) {
1678
+    public function get_fees_total($type = 'all') {
1679 1679
         $fees_total = (float) 0.00;
1680 1680
 
1681
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
1682
-        if ( ! empty( $payment_fees ) ) {
1683
-            foreach ( $payment_fees as $fee ) {
1681
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
1682
+        if (!empty($payment_fees)) {
1683
+            foreach ($payment_fees as $fee) {
1684 1684
                 $fees_total += (float) $fee['amount'];
1685 1685
             }
1686 1686
         }
1687 1687
 
1688
-        return apply_filters( 'wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this );
1688
+        return apply_filters('wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this);
1689 1689
         /*
1690 1690
         $fees = $this->get_fees( $type );
1691 1691
 
@@ -1705,116 +1705,116 @@  discard block
 block discarded – undo
1705 1705
     }
1706 1706
 
1707 1707
     public function get_user_id() {
1708
-        return apply_filters( 'wpinv_user_id', $this->user_id, $this->ID, $this );
1708
+        return apply_filters('wpinv_user_id', $this->user_id, $this->ID, $this);
1709 1709
     }
1710 1710
     
1711 1711
     public function get_first_name() {
1712
-        return apply_filters( 'wpinv_first_name', $this->first_name, $this->ID, $this );
1712
+        return apply_filters('wpinv_first_name', $this->first_name, $this->ID, $this);
1713 1713
     }
1714 1714
     
1715 1715
     public function get_last_name() {
1716
-        return apply_filters( 'wpinv_last_name', $this->last_name, $this->ID, $this );
1716
+        return apply_filters('wpinv_last_name', $this->last_name, $this->ID, $this);
1717 1717
     }
1718 1718
     
1719 1719
     public function get_user_full_name() {
1720
-        return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this );
1720
+        return apply_filters('wpinv_user_full_name', $this->full_name, $this->ID, $this);
1721 1721
     }
1722 1722
     
1723 1723
     public function get_user_info() {
1724
-        return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this );
1724
+        return apply_filters('wpinv_user_info', $this->user_info, $this->ID, $this);
1725 1725
     }
1726 1726
     
1727 1727
     public function get_email() {
1728
-        return apply_filters( 'wpinv_user_email', $this->email, $this->ID, $this );
1728
+        return apply_filters('wpinv_user_email', $this->email, $this->ID, $this);
1729 1729
     }
1730 1730
     
1731 1731
     public function get_address() {
1732
-        return apply_filters( 'wpinv_address', $this->address, $this->ID, $this );
1732
+        return apply_filters('wpinv_address', $this->address, $this->ID, $this);
1733 1733
     }
1734 1734
     
1735 1735
     public function get_phone() {
1736
-        return apply_filters( 'wpinv_phone', $this->phone, $this->ID, $this );
1736
+        return apply_filters('wpinv_phone', $this->phone, $this->ID, $this);
1737 1737
     }
1738 1738
     
1739 1739
     public function get_number() {
1740
-        return apply_filters( 'wpinv_number', $this->number, $this->ID, $this );
1740
+        return apply_filters('wpinv_number', $this->number, $this->ID, $this);
1741 1741
     }
1742 1742
     
1743 1743
     public function get_items() {
1744
-        return apply_filters( 'wpinv_payment_meta_items', $this->items, $this->ID, $this );
1744
+        return apply_filters('wpinv_payment_meta_items', $this->items, $this->ID, $this);
1745 1745
     }
1746 1746
     
1747 1747
     public function get_key() {
1748
-        return apply_filters( 'wpinv_key', $this->key, $this->ID, $this );
1748
+        return apply_filters('wpinv_key', $this->key, $this->ID, $this);
1749 1749
     }
1750 1750
     
1751 1751
     public function get_transaction_id() {
1752
-        return apply_filters( 'wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this );
1752
+        return apply_filters('wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this);
1753 1753
     }
1754 1754
     
1755 1755
     public function get_gateway() {
1756
-        return apply_filters( 'wpinv_gateway', $this->gateway, $this->ID, $this );
1756
+        return apply_filters('wpinv_gateway', $this->gateway, $this->ID, $this);
1757 1757
     }
1758 1758
     
1759 1759
     public function get_gateway_title() {
1760
-        $this->gateway_title = !empty( $this->gateway_title ) ? $this->gateway_title : wpinv_get_gateway_checkout_label( $this->gateway );
1760
+        $this->gateway_title = !empty($this->gateway_title) ? $this->gateway_title : wpinv_get_gateway_checkout_label($this->gateway);
1761 1761
         
1762
-        return apply_filters( 'wpinv_gateway_title', $this->gateway_title, $this->ID, $this );
1762
+        return apply_filters('wpinv_gateway_title', $this->gateway_title, $this->ID, $this);
1763 1763
     }
1764 1764
     
1765 1765
     public function get_currency() {
1766
-        return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this );
1766
+        return apply_filters('wpinv_currency_code', $this->currency, $this->ID, $this);
1767 1767
     }
1768 1768
     
1769 1769
     public function get_created_date() {
1770
-        return apply_filters( 'wpinv_created_date', $this->date, $this->ID, $this );
1770
+        return apply_filters('wpinv_created_date', $this->date, $this->ID, $this);
1771 1771
     }
1772 1772
     
1773
-    public function get_due_date( $display = false ) {
1774
-        $due_date = apply_filters( 'wpinv_due_date', $this->due_date, $this->ID, $this );
1773
+    public function get_due_date($display = false) {
1774
+        $due_date = apply_filters('wpinv_due_date', $this->due_date, $this->ID, $this);
1775 1775
         
1776
-        if ( !$display || empty( $due_date ) ) {
1776
+        if (!$display || empty($due_date)) {
1777 1777
             return $due_date;
1778 1778
         }
1779 1779
         
1780
-        return date_i18n( get_option( 'date_format' ), strtotime( $due_date ) );
1780
+        return date_i18n(get_option('date_format'), strtotime($due_date));
1781 1781
     }
1782 1782
     
1783 1783
     public function get_completed_date() {
1784
-        return apply_filters( 'wpinv_completed_date', $this->completed_date, $this->ID, $this );
1784
+        return apply_filters('wpinv_completed_date', $this->completed_date, $this->ID, $this);
1785 1785
     }
1786 1786
     
1787
-    public function get_invoice_date( $formatted = true ) {
1787
+    public function get_invoice_date($formatted = true) {
1788 1788
         $date_completed = $this->completed_date;
1789 1789
         $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? $date_completed : '';
1790 1790
         
1791
-        if ( $invoice_date == '' ) {
1791
+        if ($invoice_date == '') {
1792 1792
             $date_created   = $this->date;
1793 1793
             $invoice_date   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? $date_created : '';
1794 1794
         }
1795 1795
         
1796
-        if ( $formatted && $invoice_date ) {
1797
-            $invoice_date   = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date ) );
1796
+        if ($formatted && $invoice_date) {
1797
+            $invoice_date = date_i18n(get_option('date_format'), strtotime($invoice_date));
1798 1798
         }
1799 1799
 
1800
-        return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this );
1800
+        return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this);
1801 1801
     }
1802 1802
     
1803 1803
     public function get_ip() {
1804
-        return apply_filters( 'wpinv_user_ip', $this->ip, $this->ID, $this );
1804
+        return apply_filters('wpinv_user_ip', $this->ip, $this->ID, $this);
1805 1805
     }
1806 1806
         
1807
-    public function has_status( $status ) {
1808
-        return apply_filters( 'wpinv_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status ) ) || $this->get_status() === $status ? true : false, $this, $status );
1807
+    public function has_status($status) {
1808
+        return apply_filters('wpinv_has_status', (is_array($status) && in_array($this->get_status(), $status)) || $this->get_status() === $status ? true : false, $this, $status);
1809 1809
     }
1810 1810
     
1811
-    public function add_item( $item_id = 0, $args = array() ) {
1811
+    public function add_item($item_id = 0, $args = array()) {
1812 1812
         global $wpi_current_id, $wpi_item_id;
1813 1813
         
1814
-        $item = new WPInv_Item( $item_id );
1814
+        $item = new WPInv_Item($item_id);
1815 1815
 
1816 1816
         // Bail if this post isn't a item
1817
-        if( !$item || $item->post_type !== 'wpi_item' ) {
1817
+        if (!$item || $item->post_type !== 'wpi_item') {
1818 1818
             return false;
1819 1819
         }
1820 1820
         
@@ -1833,8 +1833,8 @@  discard block
 block discarded – undo
1833 1833
             'fees'          => array()
1834 1834
         );
1835 1835
 
1836
-        $args = wp_parse_args( apply_filters( 'wpinv_add_item_args', $args, $item->ID ), $defaults );
1837
-        $args['quantity']   = $has_quantities && $args['quantity'] > 0 ? absint( $args['quantity'] ) : 1;
1836
+        $args = wp_parse_args(apply_filters('wpinv_add_item_args', $args, $item->ID), $defaults);
1837
+        $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint($args['quantity']) : 1;
1838 1838
 
1839 1839
         $wpi_current_id         = $this->ID;
1840 1840
         $wpi_item_id            = $item->ID;
@@ -1846,19 +1846,19 @@  discard block
 block discarded – undo
1846 1846
         $found_cart_key         = false;
1847 1847
         
1848 1848
         if ($has_quantities) {
1849
-            $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1849
+            $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1850 1850
             
1851
-            foreach ( $this->items as $key => $cart_item ) {
1852
-                if ( (int)$item_id !== (int)$cart_item['id'] ) {
1851
+            foreach ($this->items as $key => $cart_item) {
1852
+                if ((int) $item_id !== (int) $cart_item['id']) {
1853 1853
                     continue;
1854 1854
                 }
1855 1855
 
1856
-                $this->items[ $key ]['quantity'] += $args['quantity'];
1856
+                $this->items[$key]['quantity'] += $args['quantity'];
1857 1857
                 break;
1858 1858
             }
1859 1859
             
1860
-            foreach ( $this->cart_details as $cart_key => $cart_item ) {
1861
-                if ( $item_id != $cart_item['id'] ) {
1860
+            foreach ($this->cart_details as $cart_key => $cart_item) {
1861
+                if ($item_id != $cart_item['id']) {
1862 1862
                     continue;
1863 1863
                 }
1864 1864
 
@@ -1870,29 +1870,29 @@  discard block
 block discarded – undo
1870 1870
         if ($has_quantities && $found_cart_key !== false) {
1871 1871
             $cart_item          = $this->cart_details[$found_cart_key];
1872 1872
             $item_price         = $cart_item['item_price'];
1873
-            $quantity           = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
1874
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
1873
+            $quantity           = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
1874
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
1875 1875
             
1876 1876
             $new_quantity       = $quantity + $args['quantity'];
1877 1877
             $subtotal           = $item_price * $new_quantity;
1878 1878
             
1879 1879
             $args['quantity']   = $new_quantity;
1880
-            $discount           = !empty( $args['discount'] ) ? $args['discount'] : 0;
1881
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1880
+            $discount           = !empty($args['discount']) ? $args['discount'] : 0;
1881
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0;
1882 1882
             
1883
-            $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float)$cart_item['discount'] ? $discount - (float)$cart_item['discount'] : 0;
1884
-            $tax_increased      = $tax > 0 && $subtotal > 0 && $tax > (float)$cart_item['tax'] ? $tax - (float)$cart_item['tax'] : 0;
1883
+            $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float) $cart_item['discount'] ? $discount - (float) $cart_item['discount'] : 0;
1884
+            $tax_increased      = $tax > 0 && $subtotal > 0 && $tax > (float) $cart_item['tax'] ? $tax - (float) $cart_item['tax'] : 0;
1885 1885
             // The total increase equals the number removed * the item_price
1886
-            $total_increased    = wpinv_round_amount( $item_price );
1886
+            $total_increased    = wpinv_round_amount($item_price);
1887 1887
             
1888
-            if ( wpinv_prices_include_tax() ) {
1889
-                $subtotal -= wpinv_round_amount( $tax );
1888
+            if (wpinv_prices_include_tax()) {
1889
+                $subtotal -= wpinv_round_amount($tax);
1890 1890
             }
1891 1891
 
1892
-            $total              = $subtotal - $discount + $tax;
1892
+            $total = $subtotal - $discount + $tax;
1893 1893
 
1894 1894
             // Do not allow totals to go negative
1895
-            if( $total < 0 ) {
1895
+            if ($total < 0) {
1896 1896
                 $total = 0;
1897 1897
             }
1898 1898
             
@@ -1908,25 +1908,25 @@  discard block
 block discarded – undo
1908 1908
             $this->cart_details[$found_cart_key] = $cart_item;
1909 1909
         } else {
1910 1910
             // Set custom price.
1911
-            if ( $args['custom_price'] !== '' ) {
1911
+            if ($args['custom_price'] !== '') {
1912 1912
                 $item_price = $args['custom_price'];
1913 1913
             } else {
1914 1914
                 // Allow overriding the price
1915
-                if ( false !== $args['item_price'] ) {
1915
+                if (false !== $args['item_price']) {
1916 1916
                     $item_price = $args['item_price'];
1917 1917
                 } else {
1918
-                    $item_price = wpinv_get_item_price( $item->ID );
1918
+                    $item_price = wpinv_get_item_price($item->ID);
1919 1919
                 }
1920 1920
             }
1921 1921
 
1922 1922
             // Sanitizing the price here so we don't have a dozen calls later
1923
-            $item_price = wpinv_sanitize_amount( $item_price );
1924
-            $subtotal   = wpinv_round_amount( $item_price * $args['quantity'] );
1923
+            $item_price = wpinv_sanitize_amount($item_price);
1924
+            $subtotal   = wpinv_round_amount($item_price * $args['quantity']);
1925 1925
         
1926
-            $discount   = !empty( $args['discount'] ) ? $args['discount'] : 0;
1927
-            $tax_class  = !empty( $args['vat_class'] ) ? $args['vat_class'] : '';
1928
-            $tax_rate   = !empty( $args['vat_rate'] ) ? $args['vat_rate'] : 0;
1929
-            $tax        = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1926
+            $discount   = !empty($args['discount']) ? $args['discount'] : 0;
1927
+            $tax_class  = !empty($args['vat_class']) ? $args['vat_class'] : '';
1928
+            $tax_rate   = !empty($args['vat_rate']) ? $args['vat_rate'] : 0;
1929
+            $tax        = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0;
1930 1930
 
1931 1931
             // Setup the items meta item
1932 1932
             $new_item = array(
@@ -1934,29 +1934,29 @@  discard block
 block discarded – undo
1934 1934
                 'quantity' => $args['quantity'],
1935 1935
             );
1936 1936
 
1937
-            $this->items[]  = $new_item;
1937
+            $this->items[] = $new_item;
1938 1938
 
1939
-            if ( wpinv_prices_include_tax() ) {
1940
-                $subtotal -= wpinv_round_amount( $tax );
1939
+            if (wpinv_prices_include_tax()) {
1940
+                $subtotal -= wpinv_round_amount($tax);
1941 1941
             }
1942 1942
 
1943
-            $total      = $subtotal - $discount + $tax;
1943
+            $total = $subtotal - $discount + $tax;
1944 1944
 
1945 1945
             // Do not allow totals to go negative
1946
-            if( $total < 0 ) {
1946
+            if ($total < 0) {
1947 1947
                 $total = 0;
1948 1948
             }
1949 1949
         
1950 1950
             $this->cart_details[] = array(
1951 1951
                 'name'          => !empty($args['name']) ? $args['name'] : $item->get_name(),
1952 1952
                 'id'            => $item->ID,
1953
-                'item_price'    => wpinv_round_amount( $item_price ),
1954
-                'custom_price'  => ( $args['custom_price'] !== '' ? wpinv_round_amount( $args['custom_price'] ) : '' ),
1953
+                'item_price'    => wpinv_round_amount($item_price),
1954
+                'custom_price'  => ($args['custom_price'] !== '' ? wpinv_round_amount($args['custom_price']) : ''),
1955 1955
                 'quantity'      => $args['quantity'],
1956 1956
                 'discount'      => $discount,
1957
-                'subtotal'      => wpinv_round_amount( $subtotal ),
1958
-                'tax'           => wpinv_round_amount( $tax ),
1959
-                'price'         => wpinv_round_amount( $total ),
1957
+                'subtotal'      => wpinv_round_amount($subtotal),
1958
+                'tax'           => wpinv_round_amount($tax),
1959
+                'price'         => wpinv_round_amount($total),
1960 1960
                 'vat_rate'      => $tax_rate,
1961 1961
                 'vat_class'     => $tax_class,
1962 1962
                 'meta'          => $args['meta'],
@@ -1966,18 +1966,18 @@  discard block
 block discarded – undo
1966 1966
             $subtotal = $subtotal - $discount;
1967 1967
         }
1968 1968
         
1969
-        $added_item = end( $this->cart_details );
1970
-        $added_item['action']  = 'add';
1969
+        $added_item = end($this->cart_details);
1970
+        $added_item['action'] = 'add';
1971 1971
         
1972 1972
         $this->pending['items'][] = $added_item;
1973 1973
         
1974
-        $this->increase_subtotal( $subtotal );
1975
-        $this->increase_tax( $tax );
1974
+        $this->increase_subtotal($subtotal);
1975
+        $this->increase_tax($tax);
1976 1976
 
1977 1977
         return true;
1978 1978
     }
1979 1979
     
1980
-    public function remove_item( $item_id, $args = array() ) {
1980
+    public function remove_item($item_id, $args = array()) {
1981 1981
         // Set some defaults
1982 1982
         $defaults = array(
1983 1983
             'quantity'      => 1,
@@ -1985,51 +1985,51 @@  discard block
 block discarded – undo
1985 1985
             'custom_price'  => '',
1986 1986
             'cart_index'    => false,
1987 1987
         );
1988
-        $args = wp_parse_args( $args, $defaults );
1988
+        $args = wp_parse_args($args, $defaults);
1989 1989
 
1990 1990
         // Bail if this post isn't a item
1991
-        if ( get_post_type( $item_id ) !== 'wpi_item' ) {
1991
+        if (get_post_type($item_id) !== 'wpi_item') {
1992 1992
             return false;
1993 1993
         }
1994 1994
         
1995
-        $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1995
+        $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1996 1996
 
1997
-        foreach ( $this->items as $key => $item ) {
1998
-            if ( !empty($item['id']) && (int)$item_id !== (int)$item['id'] ) {
1997
+        foreach ($this->items as $key => $item) {
1998
+            if (!empty($item['id']) && (int) $item_id !== (int) $item['id']) {
1999 1999
                 continue;
2000 2000
             }
2001 2001
 
2002
-            if ( false !== $args['cart_index'] ) {
2003
-                $cart_index = absint( $args['cart_index'] );
2004
-                $cart_item  = ! empty( $this->cart_details[ $cart_index ] ) ? $this->cart_details[ $cart_index ] : false;
2002
+            if (false !== $args['cart_index']) {
2003
+                $cart_index = absint($args['cart_index']);
2004
+                $cart_item  = !empty($this->cart_details[$cart_index]) ? $this->cart_details[$cart_index] : false;
2005 2005
 
2006
-                if ( ! empty( $cart_item ) ) {
2006
+                if (!empty($cart_item)) {
2007 2007
                     // If the cart index item isn't the same item ID, don't remove it
2008
-                    if ( !empty($cart_item['id']) && $cart_item['id'] != $item['id'] ) {
2008
+                    if (!empty($cart_item['id']) && $cart_item['id'] != $item['id']) {
2009 2009
                         continue;
2010 2010
                     }
2011 2011
                 }
2012 2012
             }
2013 2013
 
2014
-            $item_quantity = $this->items[ $key ]['quantity'];
2015
-            if ( $item_quantity > $args['quantity'] ) {
2016
-                $this->items[ $key ]['quantity'] -= $args['quantity'];
2014
+            $item_quantity = $this->items[$key]['quantity'];
2015
+            if ($item_quantity > $args['quantity']) {
2016
+                $this->items[$key]['quantity'] -= $args['quantity'];
2017 2017
                 break;
2018 2018
             } else {
2019
-                unset( $this->items[ $key ] );
2019
+                unset($this->items[$key]);
2020 2020
                 break;
2021 2021
             }
2022 2022
         }
2023 2023
 
2024 2024
         $found_cart_key = false;
2025
-        if ( false === $args['cart_index'] ) {
2026
-            foreach ( $this->cart_details as $cart_key => $item ) {
2027
-                if ( $item_id != $item['id'] ) {
2025
+        if (false === $args['cart_index']) {
2026
+            foreach ($this->cart_details as $cart_key => $item) {
2027
+                if ($item_id != $item['id']) {
2028 2028
                     continue;
2029 2029
                 }
2030 2030
 
2031
-                if ( false !== $args['item_price'] ) {
2032
-                    if ( isset( $item['item_price'] ) && (float) $args['item_price'] != (float) $item['item_price'] ) {
2031
+                if (false !== $args['item_price']) {
2032
+                    if (isset($item['item_price']) && (float) $args['item_price'] != (float) $item['item_price']) {
2033 2033
                         continue;
2034 2034
                     }
2035 2035
                 }
@@ -2038,13 +2038,13 @@  discard block
 block discarded – undo
2038 2038
                 break;
2039 2039
             }
2040 2040
         } else {
2041
-            $cart_index = absint( $args['cart_index'] );
2041
+            $cart_index = absint($args['cart_index']);
2042 2042
 
2043
-            if ( ! array_key_exists( $cart_index, $this->cart_details ) ) {
2043
+            if (!array_key_exists($cart_index, $this->cart_details)) {
2044 2044
                 return false; // Invalid cart index passed.
2045 2045
             }
2046 2046
 
2047
-            if ( (int) $this->cart_details[ $cart_index ]['id'] > 0 && (int) $this->cart_details[ $cart_index ]['id'] !== (int) $item_id ) {
2047
+            if ((int) $this->cart_details[$cart_index]['id'] > 0 && (int) $this->cart_details[$cart_index]['id'] !== (int) $item_id) {
2048 2048
                 return false; // We still need the proper Item ID to be sure.
2049 2049
             }
2050 2050
 
@@ -2052,41 +2052,41 @@  discard block
 block discarded – undo
2052 2052
         }
2053 2053
         
2054 2054
         $cart_item  = $this->cart_details[$found_cart_key];
2055
-        $quantity   = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
2055
+        $quantity   = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
2056 2056
         
2057
-        if ( count( $this->cart_details ) == 1 && ( $quantity - $args['quantity'] ) < 1 ) {
2057
+        if (count($this->cart_details) == 1 && ($quantity - $args['quantity']) < 1) {
2058 2058
             //return false; // Invoice must contain at least one item.
2059 2059
         }
2060 2060
         
2061
-        $discounts  = $this->get_discounts();
2061
+        $discounts = $this->get_discounts();
2062 2062
         
2063
-        if ( $quantity > $args['quantity'] ) {
2063
+        if ($quantity > $args['quantity']) {
2064 2064
             $item_price         = $cart_item['item_price'];
2065
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
2065
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
2066 2066
             
2067
-            $new_quantity       = max( $quantity - $args['quantity'], 1);
2067
+            $new_quantity       = max($quantity - $args['quantity'], 1);
2068 2068
             $subtotal           = $item_price * $new_quantity;
2069 2069
             
2070 2070
             $args['quantity']   = $new_quantity;
2071
-            $discount           = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
2072
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
2071
+            $discount           = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
2072
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0;
2073 2073
             
2074
-            $discount_decrease  = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['discount'] / $quantity ) ) : 0;
2075
-            $discount_decrease  = $discount > 0 && $subtotal > 0 && (float)$cart_item['discount'] > $discount ? (float)$cart_item['discount'] - $discount : $discount_decrease; 
2076
-            $tax_decrease       = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['tax'] / $quantity ) ) : 0;
2077
-            $tax_decrease       = $tax > 0 && $subtotal > 0 && (float)$cart_item['tax'] > $tax ? (float)$cart_item['tax'] - $tax : $tax_decrease;
2074
+            $discount_decrease  = (float) $cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount(((float) $cart_item['discount'] / $quantity)) : 0;
2075
+            $discount_decrease  = $discount > 0 && $subtotal > 0 && (float) $cart_item['discount'] > $discount ? (float) $cart_item['discount'] - $discount : $discount_decrease; 
2076
+            $tax_decrease       = (float) $cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount(((float) $cart_item['tax'] / $quantity)) : 0;
2077
+            $tax_decrease       = $tax > 0 && $subtotal > 0 && (float) $cart_item['tax'] > $tax ? (float) $cart_item['tax'] - $tax : $tax_decrease;
2078 2078
             
2079 2079
             // The total increase equals the number removed * the item_price
2080
-            $total_decrease     = wpinv_round_amount( $item_price );
2080
+            $total_decrease     = wpinv_round_amount($item_price);
2081 2081
             
2082
-            if ( wpinv_prices_include_tax() ) {
2083
-                $subtotal -= wpinv_round_amount( $tax );
2082
+            if (wpinv_prices_include_tax()) {
2083
+                $subtotal -= wpinv_round_amount($tax);
2084 2084
             }
2085 2085
 
2086
-            $total              = $subtotal - $discount + $tax;
2086
+            $total = $subtotal - $discount + $tax;
2087 2087
 
2088 2088
             // Do not allow totals to go negative
2089
-            if( $total < 0 ) {
2089
+            if ($total < 0) {
2090 2090
                 $total = 0;
2091 2091
             }
2092 2092
             
@@ -2105,16 +2105,16 @@  discard block
 block discarded – undo
2105 2105
             
2106 2106
             $this->cart_details[$found_cart_key] = $cart_item;
2107 2107
             
2108
-            $remove_item = end( $this->cart_details );
2108
+            $remove_item = end($this->cart_details);
2109 2109
         } else {
2110 2110
             $item_price     = $cart_item['item_price'];
2111
-            $discount       = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
2112
-            $tax            = !empty( $cart_item['tax'] ) ? $cart_item['tax'] : 0;
2111
+            $discount       = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
2112
+            $tax            = !empty($cart_item['tax']) ? $cart_item['tax'] : 0;
2113 2113
         
2114
-            $subtotal_decrease  = ( $item_price * $quantity ) - $discount;
2114
+            $subtotal_decrease  = ($item_price * $quantity) - $discount;
2115 2115
             $tax_decrease       = $tax;
2116 2116
 
2117
-            unset( $this->cart_details[$found_cart_key] );
2117
+            unset($this->cart_details[$found_cart_key]);
2118 2118
             
2119 2119
             $remove_item             = $args;
2120 2120
             $remove_item['id']       = $item_id;
@@ -2125,8 +2125,8 @@  discard block
 block discarded – undo
2125 2125
         $remove_item['action']      = 'remove';
2126 2126
         $this->pending['items'][]   = $remove_item;
2127 2127
                
2128
-        $this->decrease_subtotal( $subtotal_decrease );
2129
-        $this->decrease_tax( $tax_decrease );
2128
+        $this->decrease_subtotal($subtotal_decrease);
2129
+        $this->decrease_tax($tax_decrease);
2130 2130
         
2131 2131
         return true;
2132 2132
     }
@@ -2134,7 +2134,7 @@  discard block
 block discarded – undo
2134 2134
     public function update_items($temp = false) {
2135 2135
         global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpi_nosave;
2136 2136
         
2137
-        if ( !empty( $this->cart_details ) ) {
2137
+        if (!empty($this->cart_details)) {
2138 2138
             $wpi_nosave             = $temp;
2139 2139
             $cart_subtotal          = 0;
2140 2140
             $cart_discount          = 0;
@@ -2144,65 +2144,65 @@  discard block
 block discarded – undo
2144 2144
             $_POST['wpinv_country'] = $this->country;
2145 2145
             $_POST['wpinv_state']   = $this->state;
2146 2146
 
2147
-            foreach ( $this->cart_details as $key => $item ) {
2147
+            foreach ($this->cart_details as $key => $item) {
2148 2148
                 $item_price = $item['item_price'];
2149
-                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
2150
-                $amount     = wpinv_round_amount( $item_price * $quantity );
2149
+                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint($item['quantity']) : 1;
2150
+                $amount     = wpinv_round_amount($item_price * $quantity);
2151 2151
                 $subtotal   = $item_price * $quantity;
2152 2152
                 
2153 2153
                 $wpi_current_id         = $this->ID;
2154 2154
                 $wpi_item_id            = $item['id'];
2155 2155
                 
2156
-                $discount   = wpinv_get_cart_item_discount_amount( $item, $this->get_discounts() );
2156
+                $discount   = wpinv_get_cart_item_discount_amount($item, $this->get_discounts());
2157 2157
                 
2158
-                $tax_rate   = wpinv_get_tax_rate( $this->country, $this->state, $wpi_item_id );
2159
-                $tax_class  = $wpinv_euvat->get_item_class( $wpi_item_id );
2160
-                $tax        = $item_price > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
2158
+                $tax_rate   = wpinv_get_tax_rate($this->country, $this->state, $wpi_item_id);
2159
+                $tax_class  = $wpinv_euvat->get_item_class($wpi_item_id);
2160
+                $tax        = $item_price > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0;
2161 2161
 
2162
-                if ( ! $this->is_taxable() ) {
2162
+                if (!$this->is_taxable()) {
2163 2163
                     $tax = 0;
2164 2164
                 }
2165 2165
 
2166
-                if ( wpinv_prices_include_tax() ) {
2167
-                    $subtotal -= wpinv_round_amount( $tax );
2166
+                if (wpinv_prices_include_tax()) {
2167
+                    $subtotal -= wpinv_round_amount($tax);
2168 2168
                 }
2169 2169
 
2170
-                $total      = $subtotal - $discount + $tax;
2170
+                $total = $subtotal - $discount + $tax;
2171 2171
 
2172 2172
                 // Do not allow totals to go negative
2173
-                if( $total < 0 ) {
2173
+                if ($total < 0) {
2174 2174
                     $total = 0;
2175 2175
                 }
2176 2176
 
2177 2177
                 $cart_details[] = array(
2178 2178
                     'id'          => $item['id'],
2179 2179
                     'name'        => $item['name'],
2180
-                    'item_price'  => wpinv_round_amount( $item_price ),
2181
-                    'custom_price'=> ( isset( $item['custom_price'] ) ? $item['custom_price'] : '' ),
2180
+                    'item_price'  => wpinv_round_amount($item_price),
2181
+                    'custom_price'=> (isset($item['custom_price']) ? $item['custom_price'] : ''),
2182 2182
                     'quantity'    => $quantity,
2183 2183
                     'discount'    => $discount,
2184
-                    'subtotal'    => wpinv_round_amount( $subtotal ),
2185
-                    'tax'         => wpinv_round_amount( $tax ),
2186
-                    'price'       => wpinv_round_amount( $total ),
2184
+                    'subtotal'    => wpinv_round_amount($subtotal),
2185
+                    'tax'         => wpinv_round_amount($tax),
2186
+                    'price'       => wpinv_round_amount($total),
2187 2187
                     'vat_rate'    => $tax_rate,
2188 2188
                     'vat_class'   => $tax_class,
2189 2189
                     'meta'        => isset($item['meta']) ? $item['meta'] : array(),
2190 2190
                     'fees'        => isset($item['fees']) ? $item['fees'] : array(),
2191 2191
                 );
2192 2192
 
2193
-                $cart_subtotal  += (float)($subtotal - $discount); // TODO
2194
-                $cart_discount  += (float)($discount);
2195
-                $cart_tax       += (float)($tax);
2193
+                $cart_subtotal  += (float) ($subtotal - $discount); // TODO
2194
+                $cart_discount  += (float) ($discount);
2195
+                $cart_tax       += (float) ($tax);
2196 2196
             }
2197
-            if ( $cart_subtotal < 0 ) {
2197
+            if ($cart_subtotal < 0) {
2198 2198
                 $cart_subtotal = 0;
2199 2199
             }
2200
-            if ( $cart_tax < 0 ) {
2200
+            if ($cart_tax < 0) {
2201 2201
                 $cart_tax = 0;
2202 2202
             }
2203
-            $this->subtotal = wpinv_round_amount( $cart_subtotal );
2204
-            $this->tax      = wpinv_round_amount( $cart_tax );
2205
-            $this->discount = wpinv_round_amount( $cart_discount );
2203
+            $this->subtotal = wpinv_round_amount($cart_subtotal);
2204
+            $this->tax      = wpinv_round_amount($cart_tax);
2205
+            $this->discount = wpinv_round_amount($cart_discount);
2206 2206
             
2207 2207
             $this->recalculate_total();
2208 2208
             
@@ -2214,177 +2214,177 @@  discard block
 block discarded – undo
2214 2214
     
2215 2215
     public function recalculate_totals($temp = false) {        
2216 2216
         $this->update_items($temp);
2217
-        $this->save( true );
2217
+        $this->save(true);
2218 2218
         
2219 2219
         return $this;
2220 2220
     }
2221 2221
     
2222 2222
     public function needs_payment() {
2223
-        $valid_invoice_statuses = apply_filters( 'wpinv_valid_invoice_statuses_for_payment', array( 'wpi-pending' ), $this );
2223
+        $valid_invoice_statuses = apply_filters('wpinv_valid_invoice_statuses_for_payment', array('wpi-pending'), $this);
2224 2224
 
2225
-        if ( $this->has_status( $valid_invoice_statuses ) && ( $this->get_total() > 0 || $this->is_free_trial() || $this->is_free() || $this->is_initial_free() ) ) {
2225
+        if ($this->has_status($valid_invoice_statuses) && ($this->get_total() > 0 || $this->is_free_trial() || $this->is_free() || $this->is_initial_free())) {
2226 2226
             $needs_payment = true;
2227 2227
         } else {
2228 2228
             $needs_payment = false;
2229 2229
         }
2230 2230
 
2231
-        return apply_filters( 'wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses );
2231
+        return apply_filters('wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses);
2232 2232
     }
2233 2233
     
2234
-    public function get_checkout_payment_url( $with_key = false, $secret = false ) {
2234
+    public function get_checkout_payment_url($with_key = false, $secret = false) {
2235 2235
         $pay_url = wpinv_get_checkout_uri();
2236 2236
 
2237
-        if ( is_ssl() ) {
2238
-            $pay_url = str_replace( 'http:', 'https:', $pay_url );
2237
+        if (is_ssl()) {
2238
+            $pay_url = str_replace('http:', 'https:', $pay_url);
2239 2239
         }
2240 2240
         
2241 2241
         $key = $this->get_key();
2242 2242
 
2243
-        if ( $with_key ) {
2244
-            $pay_url = add_query_arg( 'invoice_key', $key, $pay_url );
2243
+        if ($with_key) {
2244
+            $pay_url = add_query_arg('invoice_key', $key, $pay_url);
2245 2245
         } else {
2246
-            $pay_url = add_query_arg( array( 'wpi_action' => 'pay_for_invoice', 'invoice_key' => $key ), $pay_url );
2246
+            $pay_url = add_query_arg(array('wpi_action' => 'pay_for_invoice', 'invoice_key' => $key), $pay_url);
2247 2247
         }
2248 2248
         
2249
-        if ( $secret ) {
2250
-            $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $key ) ), $pay_url );
2249
+        if ($secret) {
2250
+            $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $key)), $pay_url);
2251 2251
         }
2252 2252
 
2253
-        return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $with_key, $secret );
2253
+        return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this, $with_key, $secret);
2254 2254
     }
2255 2255
     
2256
-    public function get_view_url( $with_key = false ) {
2257
-        $invoice_url = get_permalink( $this->ID );
2256
+    public function get_view_url($with_key = false) {
2257
+        $invoice_url = get_permalink($this->ID);
2258 2258
 
2259
-        if ( $with_key ) {
2260
-            $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url );
2259
+        if ($with_key) {
2260
+            $invoice_url = add_query_arg('invoice_key', $this->get_key(), $invoice_url);
2261 2261
         }
2262 2262
 
2263
-        return apply_filters( 'wpinv_get_view_url', $invoice_url, $this, $with_key );
2263
+        return apply_filters('wpinv_get_view_url', $invoice_url, $this, $with_key);
2264 2264
     }
2265 2265
     
2266
-    public function generate_key( $string = '' ) {
2267
-        $auth_key  = defined( 'AUTH_KEY' ) ? AUTH_KEY : '';
2268
-        return strtolower( md5( $string . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) ) );  // Unique key
2266
+    public function generate_key($string = '') {
2267
+        $auth_key = defined('AUTH_KEY') ? AUTH_KEY : '';
2268
+        return strtolower(md5($string . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true))); // Unique key
2269 2269
     }
2270 2270
     
2271 2271
     public function is_recurring() {
2272
-        if ( empty( $this->cart_details ) ) {
2272
+        if (empty($this->cart_details)) {
2273 2273
             return false;
2274 2274
         }
2275 2275
         
2276 2276
         $has_subscription = false;
2277
-        foreach( $this->cart_details as $cart_item ) {
2278
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2277
+        foreach ($this->cart_details as $cart_item) {
2278
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2279 2279
                 $has_subscription = true;
2280 2280
                 break;
2281 2281
             }
2282 2282
         }
2283 2283
         
2284
-        if ( count( $this->cart_details ) > 1 ) {
2284
+        if (count($this->cart_details) > 1) {
2285 2285
             $has_subscription = false;
2286 2286
         }
2287 2287
 
2288
-        return apply_filters( 'wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details );
2288
+        return apply_filters('wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details);
2289 2289
     }
2290 2290
 
2291 2291
     public function is_free_trial() {
2292 2292
         $is_free_trial = false;
2293 2293
         
2294
-        if ( $this->is_parent() && $item = $this->get_recurring( true ) ) {
2295
-            if ( !empty( $item ) && $item->has_free_trial() ) {
2294
+        if ($this->is_parent() && $item = $this->get_recurring(true)) {
2295
+            if (!empty($item) && $item->has_free_trial()) {
2296 2296
                 $is_free_trial = true;
2297 2297
             }
2298 2298
         }
2299 2299
 
2300
-        return apply_filters( 'wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details, $this );
2300
+        return apply_filters('wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details, $this);
2301 2301
     }
2302 2302
 
2303 2303
     public function is_initial_free() {
2304 2304
         $is_initial_free = false;
2305 2305
         
2306
-        if ( ! ( (float)wpinv_round_amount( $this->get_total() ) > 0 ) && $this->is_parent() && $this->is_recurring() && ! $this->is_free_trial() && ! $this->is_free() ) {
2306
+        if (!((float) wpinv_round_amount($this->get_total()) > 0) && $this->is_parent() && $this->is_recurring() && !$this->is_free_trial() && !$this->is_free()) {
2307 2307
             $is_initial_free = true;
2308 2308
         }
2309 2309
 
2310
-        return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->cart_details );
2310
+        return apply_filters('wpinv_invoice_is_initial_free', $is_initial_free, $this->cart_details);
2311 2311
     }
2312 2312
     
2313
-    public function get_recurring( $object = false ) {
2313
+    public function get_recurring($object = false) {
2314 2314
         $item = NULL;
2315 2315
         
2316
-        if ( empty( $this->cart_details ) ) {
2316
+        if (empty($this->cart_details)) {
2317 2317
             return $item;
2318 2318
         }
2319 2319
         
2320
-        foreach( $this->cart_details as $cart_item ) {
2321
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2320
+        foreach ($this->cart_details as $cart_item) {
2321
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2322 2322
                 $item = $cart_item['id'];
2323 2323
                 break;
2324 2324
             }
2325 2325
         }
2326 2326
         
2327
-        if ( $object ) {
2328
-            $item = $item ? new WPInv_Item( $item ) : NULL;
2327
+        if ($object) {
2328
+            $item = $item ? new WPInv_Item($item) : NULL;
2329 2329
             
2330
-            apply_filters( 'wpinv_invoice_get_recurring_item', $item, $this );
2330
+            apply_filters('wpinv_invoice_get_recurring_item', $item, $this);
2331 2331
         }
2332 2332
 
2333
-        return apply_filters( 'wpinv_invoice_get_recurring_item_id', $item, $this );
2333
+        return apply_filters('wpinv_invoice_get_recurring_item_id', $item, $this);
2334 2334
     }
2335 2335
 
2336 2336
     public function get_subscription_name() {
2337
-        $item = $this->get_recurring( true );
2337
+        $item = $this->get_recurring(true);
2338 2338
 
2339
-        if ( empty( $item ) ) {
2339
+        if (empty($item)) {
2340 2340
             return NULL;
2341 2341
         }
2342 2342
 
2343
-        if ( !($name = $item->get_name()) ) {
2343
+        if (!($name = $item->get_name())) {
2344 2344
             $name = $item->post_name;
2345 2345
         }
2346 2346
 
2347
-        return apply_filters( 'wpinv_invoice_get_subscription_name', $name, $this );
2347
+        return apply_filters('wpinv_invoice_get_subscription_name', $name, $this);
2348 2348
     }
2349 2349
 
2350 2350
     public function get_subscription_id() {
2351
-        $subscription_id = $this->get_meta( '_wpinv_subscr_profile_id', true );
2351
+        $subscription_id = $this->get_meta('_wpinv_subscr_profile_id', true);
2352 2352
 
2353
-        if ( empty( $subscription_id ) && !empty( $this->parent_invoice ) ) {
2354
-            $parent_invoice = wpinv_get_invoice( $this->parent_invoice );
2353
+        if (empty($subscription_id) && !empty($this->parent_invoice)) {
2354
+            $parent_invoice = wpinv_get_invoice($this->parent_invoice);
2355 2355
 
2356
-            $subscription_id = $parent_invoice->get_meta( '_wpinv_subscr_profile_id', true );
2356
+            $subscription_id = $parent_invoice->get_meta('_wpinv_subscr_profile_id', true);
2357 2357
         }
2358 2358
         
2359 2359
         return $subscription_id;
2360 2360
     }
2361 2361
     
2362 2362
     public function is_parent() {
2363
-        $is_parent = empty( $this->parent_invoice ) ? true : false;
2363
+        $is_parent = empty($this->parent_invoice) ? true : false;
2364 2364
 
2365
-        return apply_filters( 'wpinv_invoice_is_parent', $is_parent, $this );
2365
+        return apply_filters('wpinv_invoice_is_parent', $is_parent, $this);
2366 2366
     }
2367 2367
     
2368 2368
     public function is_renewal() {
2369 2369
         $is_renewal = $this->parent_invoice && $this->parent_invoice != $this->ID ? true : false;
2370 2370
 
2371
-        return apply_filters( 'wpinv_invoice_is_renewal', $is_renewal, $this );
2371
+        return apply_filters('wpinv_invoice_is_renewal', $is_renewal, $this);
2372 2372
     }
2373 2373
     
2374 2374
     public function get_parent_payment() {
2375 2375
         $parent_payment = NULL;
2376 2376
         
2377
-        if ( $this->is_renewal() ) {
2378
-            $parent_payment = wpinv_get_invoice( $this->parent_invoice );
2377
+        if ($this->is_renewal()) {
2378
+            $parent_payment = wpinv_get_invoice($this->parent_invoice);
2379 2379
         }
2380 2380
         
2381 2381
         return $parent_payment;
2382 2382
     }
2383 2383
     
2384 2384
     public function is_paid() {
2385
-        $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) );
2385
+        $is_paid = $this->has_status(array('publish', 'wpi-processing', 'wpi-renewal'));
2386 2386
 
2387
-        return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this );
2387
+        return apply_filters('wpinv_invoice_is_paid', $is_paid, $this);
2388 2388
     }
2389 2389
 
2390 2390
     /**
@@ -2397,23 +2397,23 @@  discard block
 block discarded – undo
2397 2397
     }
2398 2398
     
2399 2399
     public function is_refunded() {
2400
-        $is_refunded = $this->has_status( array( 'wpi-refunded' ) );
2400
+        $is_refunded = $this->has_status(array('wpi-refunded'));
2401 2401
 
2402
-        return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this );
2402
+        return apply_filters('wpinv_invoice_is_refunded', $is_refunded, $this);
2403 2403
     }
2404 2404
     
2405 2405
     public function is_free() {
2406 2406
         $is_free = false;
2407 2407
         
2408
-        if ( !( (float)wpinv_round_amount( $this->get_total() ) > 0 ) ) {
2409
-            if ( $this->is_parent() && $this->is_recurring() ) {
2410
-                $is_free = (float)wpinv_round_amount( $this->get_recurring_details( 'total' ) ) > 0 ? false : true;
2408
+        if (!((float) wpinv_round_amount($this->get_total()) > 0)) {
2409
+            if ($this->is_parent() && $this->is_recurring()) {
2410
+                $is_free = (float) wpinv_round_amount($this->get_recurring_details('total')) > 0 ? false : true;
2411 2411
             } else {
2412 2412
                 $is_free = true;
2413 2413
             }
2414 2414
         }
2415 2415
         
2416
-        return apply_filters( 'wpinv_invoice_is_free', $is_free, $this );
2416
+        return apply_filters('wpinv_invoice_is_free', $is_free, $this);
2417 2417
     }
2418 2418
     
2419 2419
     public function has_vat() {
@@ -2421,41 +2421,41 @@  discard block
 block discarded – undo
2421 2421
         
2422 2422
         $requires_vat = false;
2423 2423
         
2424
-        if ( $this->country ) {
2424
+        if ($this->country) {
2425 2425
             $wpi_country        = $this->country;
2426 2426
             
2427
-            $requires_vat       = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) );
2427
+            $requires_vat       = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this));
2428 2428
         }
2429 2429
         
2430
-        return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this );
2430
+        return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this);
2431 2431
     }
2432 2432
     
2433 2433
     public function refresh_item_ids() {
2434 2434
         $item_ids = array();
2435 2435
         
2436
-        if ( !empty( $this->cart_details ) ) {
2437
-            foreach ( $this->cart_details as $key => $item ) {
2438
-                if ( !empty( $item['id'] ) ) {
2436
+        if (!empty($this->cart_details)) {
2437
+            foreach ($this->cart_details as $key => $item) {
2438
+                if (!empty($item['id'])) {
2439 2439
                     $item_ids[] = $item['id'];
2440 2440
                 }
2441 2441
             }
2442 2442
         }
2443 2443
         
2444
-        $item_ids = !empty( $item_ids ) ? implode( ',', array_unique( $item_ids ) ) : '';
2444
+        $item_ids = !empty($item_ids) ? implode(',', array_unique($item_ids)) : '';
2445 2445
         
2446
-        update_post_meta( $this->ID, '_wpinv_item_ids', $item_ids );
2446
+        update_post_meta($this->ID, '_wpinv_item_ids', $item_ids);
2447 2447
     }
2448 2448
     
2449
-    public function get_invoice_quote_type( $post_id ) {
2450
-        if ( empty( $post_id ) ) {
2449
+    public function get_invoice_quote_type($post_id) {
2450
+        if (empty($post_id)) {
2451 2451
             return '';
2452 2452
         }
2453 2453
 
2454
-        $type = get_post_type( $post_id );
2454
+        $type = get_post_type($post_id);
2455 2455
 
2456
-        if ( 'wpi_invoice' === $type ) {
2456
+        if ('wpi_invoice' === $type) {
2457 2457
             $post_type = __('Invoice', 'invoicing');
2458
-        } else{
2458
+        } else {
2459 2459
             $post_type = __('Quote', 'invoicing');
2460 2460
         }
2461 2461
 
Please login to merge, or discard this patch.