@@ -7,40 +7,40 @@ |
||
7 | 7 | * Bail if we are not in WP. |
8 | 8 | */ |
9 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
10 | - exit; |
|
10 | + exit; |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
14 | 14 | * Set the version only if its the current newest while loading. |
15 | 15 | */ |
16 | 16 | add_action('after_setup_theme', function () { |
17 | - global $ayecode_ui_version,$ayecode_ui_file_key; |
|
18 | - $this_version = "0.1.72"; |
|
19 | - if(empty($ayecode_ui_version) || version_compare($this_version , $ayecode_ui_version, '>')){ |
|
20 | - $ayecode_ui_version = $this_version ; |
|
21 | - $ayecode_ui_file_key = wp_hash( __FILE__ ); |
|
22 | - } |
|
17 | + global $ayecode_ui_version,$ayecode_ui_file_key; |
|
18 | + $this_version = "0.1.72"; |
|
19 | + if(empty($ayecode_ui_version) || version_compare($this_version , $ayecode_ui_version, '>')){ |
|
20 | + $ayecode_ui_version = $this_version ; |
|
21 | + $ayecode_ui_file_key = wp_hash( __FILE__ ); |
|
22 | + } |
|
23 | 23 | },0); |
24 | 24 | |
25 | 25 | /** |
26 | 26 | * Load this version of WP Bootstrap Settings only if the file hash is the current one. |
27 | 27 | */ |
28 | 28 | add_action('after_setup_theme', function () { |
29 | - global $ayecode_ui_file_key; |
|
30 | - if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){ |
|
31 | - include_once( dirname( __FILE__ ) . '/includes/class-aui.php' ); |
|
32 | - include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' ); |
|
33 | - } |
|
29 | + global $ayecode_ui_file_key; |
|
30 | + if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){ |
|
31 | + include_once( dirname( __FILE__ ) . '/includes/class-aui.php' ); |
|
32 | + include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' ); |
|
33 | + } |
|
34 | 34 | },1); |
35 | 35 | |
36 | 36 | /** |
37 | 37 | * Add the function that calls the class. |
38 | 38 | */ |
39 | 39 | if(!function_exists('aui')){ |
40 | - function aui(){ |
|
41 | - if(!class_exists("AUI",false)){ |
|
42 | - return false; |
|
43 | - } |
|
44 | - return AUI::instance(); |
|
45 | - } |
|
40 | + function aui(){ |
|
41 | + if(!class_exists("AUI",false)){ |
|
42 | + return false; |
|
43 | + } |
|
44 | + return AUI::instance(); |
|
45 | + } |
|
46 | 46 | } |
@@ -6,39 +6,39 @@ |
||
6 | 6 | /** |
7 | 7 | * Bail if we are not in WP. |
8 | 8 | */ |
9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
9 | +if (!defined('ABSPATH')) { |
|
10 | 10 | exit; |
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
14 | 14 | * Set the version only if its the current newest while loading. |
15 | 15 | */ |
16 | -add_action('after_setup_theme', function () { |
|
17 | - global $ayecode_ui_version,$ayecode_ui_file_key; |
|
16 | +add_action('after_setup_theme', function() { |
|
17 | + global $ayecode_ui_version, $ayecode_ui_file_key; |
|
18 | 18 | $this_version = "0.1.72"; |
19 | - if(empty($ayecode_ui_version) || version_compare($this_version , $ayecode_ui_version, '>')){ |
|
20 | - $ayecode_ui_version = $this_version ; |
|
21 | - $ayecode_ui_file_key = wp_hash( __FILE__ ); |
|
19 | + if (empty($ayecode_ui_version) || version_compare($this_version, $ayecode_ui_version, '>')) { |
|
20 | + $ayecode_ui_version = $this_version; |
|
21 | + $ayecode_ui_file_key = wp_hash(__FILE__); |
|
22 | 22 | } |
23 | 23 | },0); |
24 | 24 | |
25 | 25 | /** |
26 | 26 | * Load this version of WP Bootstrap Settings only if the file hash is the current one. |
27 | 27 | */ |
28 | -add_action('after_setup_theme', function () { |
|
28 | +add_action('after_setup_theme', function() { |
|
29 | 29 | global $ayecode_ui_file_key; |
30 | - if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){ |
|
31 | - include_once( dirname( __FILE__ ) . '/includes/class-aui.php' ); |
|
32 | - include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' ); |
|
30 | + if ($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash(__FILE__)) { |
|
31 | + include_once(dirname(__FILE__) . '/includes/class-aui.php'); |
|
32 | + include_once(dirname(__FILE__) . '/includes/ayecode-ui-settings.php'); |
|
33 | 33 | } |
34 | 34 | },1); |
35 | 35 | |
36 | 36 | /** |
37 | 37 | * Add the function that calls the class. |
38 | 38 | */ |
39 | -if(!function_exists('aui')){ |
|
40 | - function aui(){ |
|
41 | - if(!class_exists("AUI",false)){ |
|
39 | +if (!function_exists('aui')) { |
|
40 | + function aui() { |
|
41 | + if (!class_exists("AUI", false)) { |
|
42 | 42 | return false; |
43 | 43 | } |
44 | 44 | return AUI::instance(); |
@@ -1,7 +1,7 @@ discard block |
||
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,1240 +11,1240 @@ discard block |
||
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 | - 'wrap_class' => '', |
|
27 | - 'id' => '', |
|
28 | - 'placeholder' => '', |
|
29 | - 'title' => '', |
|
30 | - 'value' => '', |
|
31 | - 'required' => false, |
|
32 | - 'size' => '', // sm, lg, small, large |
|
33 | - 'clear_icon' => '', // true will show a clear icon, can't be used with input_group_right |
|
34 | - 'label' => '', |
|
35 | - 'label_after' => false, |
|
36 | - 'label_class' => '', |
|
37 | - 'label_col' => '2', |
|
38 | - 'label_type' => '', // top, horizontal, empty = hidden |
|
39 | - 'label_force_left' => false, // used to force checkbox label left when using horizontal |
|
40 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
41 | - 'help_text' => '', |
|
42 | - 'validation_text' => '', |
|
43 | - 'validation_pattern' => '', |
|
44 | - 'no_wrap' => false, |
|
45 | - 'input_group_right' => '', |
|
46 | - 'input_group_left' => '', |
|
47 | - 'input_group_right_inside' => false, |
|
48 | - // forces the input group inside the input |
|
49 | - 'input_group_left_inside' => false, |
|
50 | - // forces the input group inside the input |
|
51 | - 'step' => '', |
|
52 | - 'switch' => false, |
|
53 | - // to show checkbox as a switch |
|
54 | - 'checked' => false, |
|
55 | - // set a checkbox or radio as selected |
|
56 | - 'password_toggle' => true, |
|
57 | - // toggle view/hide password |
|
58 | - 'element_require' => '', |
|
59 | - // [%element_id%] == "1" |
|
60 | - 'extra_attributes' => array(), |
|
61 | - // an array of extra attributes |
|
62 | - 'wrap_attributes' => array() |
|
63 | - ); |
|
64 | - |
|
65 | - /** |
|
66 | - * Parse incoming $args into an array and merge it with $defaults |
|
67 | - */ |
|
68 | - $args = wp_parse_args( $args, $defaults ); |
|
69 | - $output = ''; |
|
70 | - if ( ! empty( $args['type'] ) ) { |
|
71 | - // hidden label option needs to be empty |
|
72 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
73 | - |
|
74 | - $type = sanitize_html_class( $args['type'] ); |
|
75 | - |
|
76 | - $help_text = ''; |
|
77 | - $label = ''; |
|
78 | - $label_after = $args['label_after']; |
|
79 | - $label_args = array( |
|
80 | - 'title' => $args['label'], |
|
81 | - 'for' => $args['id'], |
|
82 | - 'class' => $args['label_class'] . " ", |
|
83 | - 'label_type' => $args['label_type'], |
|
84 | - 'label_col' => $args['label_col'] |
|
85 | - ); |
|
86 | - |
|
87 | - // floating labels need label after |
|
88 | - if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) { |
|
89 | - $label_after = true; |
|
90 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
91 | - } |
|
92 | - |
|
93 | - // size |
|
94 | - $size = ''; |
|
95 | - if ( $args['size'] == 'lg' || $args['size'] == 'large' ) { |
|
96 | - $size = 'lg'; |
|
97 | - $args['class'] .= ' form-control-lg'; |
|
98 | - }elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) { |
|
99 | - $size = 'sm'; |
|
100 | - $args['class'] .= ' form-control-sm'; |
|
101 | - } |
|
102 | - |
|
103 | - // clear function |
|
104 | - $clear_function = 'jQuery(this).parent().parent().find(\'input\').val(\'\');'; |
|
105 | - |
|
106 | - // Some special sauce for files |
|
107 | - if ( $type == 'file' ) { |
|
108 | - $label_after = true; // if type file we need the label after |
|
109 | - $args['class'] .= ' custom-file-input '; |
|
110 | - } elseif ( $type == 'checkbox' ) { |
|
111 | - $label_after = true; // if type file we need the label after |
|
112 | - $args['class'] .= ' custom-control-input '; |
|
113 | - } elseif ( $type == 'datepicker' || $type == 'timepicker' ) { |
|
114 | - $type = 'text'; |
|
115 | - $args['class'] .= ' bg-initial '; // @todo not sure why we have this? |
|
116 | - |
|
117 | - $args['extra_attributes']['data-aui-init'] = 'flatpickr'; |
|
118 | - |
|
119 | - // set a way to clear field if empty |
|
120 | - if ( $args['input_group_right'] === '' && $args['clear_icon'] !== false ) { |
|
121 | - $args['input_group_right_inside'] = true; |
|
122 | - $args['clear_icon'] = true; |
|
123 | - } |
|
124 | - |
|
125 | - // enqueue the script |
|
126 | - $aui_settings = AyeCode_UI_Settings::instance(); |
|
127 | - $aui_settings->enqueue_flatpickr(); |
|
128 | - } elseif ( $type == 'iconpicker' ) { |
|
129 | - $type = 'text'; |
|
130 | - //$args['class'] .= ' aui-flatpickr bg-initial '; |
|
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 | + 'wrap_class' => '', |
|
27 | + 'id' => '', |
|
28 | + 'placeholder' => '', |
|
29 | + 'title' => '', |
|
30 | + 'value' => '', |
|
31 | + 'required' => false, |
|
32 | + 'size' => '', // sm, lg, small, large |
|
33 | + 'clear_icon' => '', // true will show a clear icon, can't be used with input_group_right |
|
34 | + 'label' => '', |
|
35 | + 'label_after' => false, |
|
36 | + 'label_class' => '', |
|
37 | + 'label_col' => '2', |
|
38 | + 'label_type' => '', // top, horizontal, empty = hidden |
|
39 | + 'label_force_left' => false, // used to force checkbox label left when using horizontal |
|
40 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
41 | + 'help_text' => '', |
|
42 | + 'validation_text' => '', |
|
43 | + 'validation_pattern' => '', |
|
44 | + 'no_wrap' => false, |
|
45 | + 'input_group_right' => '', |
|
46 | + 'input_group_left' => '', |
|
47 | + 'input_group_right_inside' => false, |
|
48 | + // forces the input group inside the input |
|
49 | + 'input_group_left_inside' => false, |
|
50 | + // forces the input group inside the input |
|
51 | + 'step' => '', |
|
52 | + 'switch' => false, |
|
53 | + // to show checkbox as a switch |
|
54 | + 'checked' => false, |
|
55 | + // set a checkbox or radio as selected |
|
56 | + 'password_toggle' => true, |
|
57 | + // toggle view/hide password |
|
58 | + 'element_require' => '', |
|
59 | + // [%element_id%] == "1" |
|
60 | + 'extra_attributes' => array(), |
|
61 | + // an array of extra attributes |
|
62 | + 'wrap_attributes' => array() |
|
63 | + ); |
|
64 | + |
|
65 | + /** |
|
66 | + * Parse incoming $args into an array and merge it with $defaults |
|
67 | + */ |
|
68 | + $args = wp_parse_args( $args, $defaults ); |
|
69 | + $output = ''; |
|
70 | + if ( ! empty( $args['type'] ) ) { |
|
71 | + // hidden label option needs to be empty |
|
72 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
73 | + |
|
74 | + $type = sanitize_html_class( $args['type'] ); |
|
75 | + |
|
76 | + $help_text = ''; |
|
77 | + $label = ''; |
|
78 | + $label_after = $args['label_after']; |
|
79 | + $label_args = array( |
|
80 | + 'title' => $args['label'], |
|
81 | + 'for' => $args['id'], |
|
82 | + 'class' => $args['label_class'] . " ", |
|
83 | + 'label_type' => $args['label_type'], |
|
84 | + 'label_col' => $args['label_col'] |
|
85 | + ); |
|
86 | + |
|
87 | + // floating labels need label after |
|
88 | + if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) { |
|
89 | + $label_after = true; |
|
90 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
91 | + } |
|
92 | + |
|
93 | + // size |
|
94 | + $size = ''; |
|
95 | + if ( $args['size'] == 'lg' || $args['size'] == 'large' ) { |
|
96 | + $size = 'lg'; |
|
97 | + $args['class'] .= ' form-control-lg'; |
|
98 | + }elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) { |
|
99 | + $size = 'sm'; |
|
100 | + $args['class'] .= ' form-control-sm'; |
|
101 | + } |
|
102 | + |
|
103 | + // clear function |
|
104 | + $clear_function = 'jQuery(this).parent().parent().find(\'input\').val(\'\');'; |
|
105 | + |
|
106 | + // Some special sauce for files |
|
107 | + if ( $type == 'file' ) { |
|
108 | + $label_after = true; // if type file we need the label after |
|
109 | + $args['class'] .= ' custom-file-input '; |
|
110 | + } elseif ( $type == 'checkbox' ) { |
|
111 | + $label_after = true; // if type file we need the label after |
|
112 | + $args['class'] .= ' custom-control-input '; |
|
113 | + } elseif ( $type == 'datepicker' || $type == 'timepicker' ) { |
|
114 | + $type = 'text'; |
|
115 | + $args['class'] .= ' bg-initial '; // @todo not sure why we have this? |
|
116 | + |
|
117 | + $args['extra_attributes']['data-aui-init'] = 'flatpickr'; |
|
118 | + |
|
119 | + // set a way to clear field if empty |
|
120 | + if ( $args['input_group_right'] === '' && $args['clear_icon'] !== false ) { |
|
121 | + $args['input_group_right_inside'] = true; |
|
122 | + $args['clear_icon'] = true; |
|
123 | + } |
|
124 | + |
|
125 | + // enqueue the script |
|
126 | + $aui_settings = AyeCode_UI_Settings::instance(); |
|
127 | + $aui_settings->enqueue_flatpickr(); |
|
128 | + } elseif ( $type == 'iconpicker' ) { |
|
129 | + $type = 'text'; |
|
130 | + //$args['class'] .= ' aui-flatpickr bg-initial '; |
|
131 | 131 | // $args['class'] .= ' bg-initial '; |
132 | 132 | |
133 | - $args['extra_attributes']['data-aui-init'] = 'iconpicker'; |
|
134 | - $args['extra_attributes']['data-placement'] = 'bottomRight'; |
|
133 | + $args['extra_attributes']['data-aui-init'] = 'iconpicker'; |
|
134 | + $args['extra_attributes']['data-placement'] = 'bottomRight'; |
|
135 | 135 | |
136 | - $args['input_group_right'] = '<span class="input-group-addon input-group-text c-pointer"></span>'; |
|
136 | + $args['input_group_right'] = '<span class="input-group-addon input-group-text c-pointer"></span>'; |
|
137 | 137 | // $args['input_group_right_inside'] = true; |
138 | - // enqueue the script |
|
139 | - $aui_settings = AyeCode_UI_Settings::instance(); |
|
140 | - $aui_settings->enqueue_iconpicker(); |
|
141 | - } |
|
142 | - |
|
143 | - if ( $type == 'checkbox' && !empty($args['name'] ) && strpos($args['name'], '[') === false ) { |
|
144 | - $output .= '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />'; |
|
145 | - } |
|
146 | - |
|
147 | - // allow clear icon |
|
148 | - if ( $args['input_group_right'] === '' && $args['clear_icon'] ) { |
|
149 | - $font_size = $size == 'sm' ? '1.3' : ( $size == 'lg' ? '1.65' : '1.5' ); |
|
150 | - $args['input_group_right_inside'] = true; |
|
151 | - $args['input_group_right'] = '<span class="input-group-text aui-clear-input c-pointer bg-initial border-0 px-2 d-none" onclick="' . $clear_function . '"><span style="font-size: '.$font_size.'rem" aria-hidden="true" class="close">×</span></span>'; |
|
152 | - } |
|
153 | - |
|
154 | - // open/type |
|
155 | - $output .= '<input type="' . $type . '" '; |
|
156 | - |
|
157 | - // name |
|
158 | - if ( ! empty( $args['name'] ) ) { |
|
159 | - $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
160 | - } |
|
161 | - |
|
162 | - // id |
|
163 | - if ( ! empty( $args['id'] ) ) { |
|
164 | - $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
165 | - } |
|
166 | - |
|
167 | - // placeholder |
|
168 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
169 | - $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
170 | - } |
|
171 | - |
|
172 | - // title |
|
173 | - if ( ! empty( $args['title'] ) ) { |
|
174 | - $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
175 | - } |
|
176 | - |
|
177 | - // value |
|
178 | - if ( ! empty( $args['value'] ) ) { |
|
179 | - $output .= AUI_Component_Helper::value( $args['value'] ); |
|
180 | - } |
|
181 | - |
|
182 | - // checked, for radio and checkboxes |
|
183 | - if ( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ) { |
|
184 | - $output .= ' checked '; |
|
185 | - } |
|
186 | - |
|
187 | - // validation text |
|
188 | - if ( ! empty( $args['validation_text'] ) ) { |
|
189 | - $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
190 | - $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
191 | - } |
|
192 | - |
|
193 | - // validation_pattern |
|
194 | - if ( ! empty( $args['validation_pattern'] ) ) { |
|
195 | - $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
196 | - } |
|
197 | - |
|
198 | - // step (for numbers) |
|
199 | - if ( ! empty( $args['step'] ) ) { |
|
200 | - $output .= ' step="' . $args['step'] . '" '; |
|
201 | - } |
|
202 | - |
|
203 | - // required |
|
204 | - if ( ! empty( $args['required'] ) ) { |
|
205 | - $output .= ' required '; |
|
206 | - } |
|
207 | - |
|
208 | - // class |
|
209 | - $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
210 | - $output .= ' class="form-control ' . $class . '" '; |
|
211 | - |
|
212 | - // data-attributes |
|
213 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
214 | - |
|
215 | - // extra attributes |
|
216 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
217 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
218 | - } |
|
219 | - |
|
220 | - // close |
|
221 | - $output .= ' >'; |
|
222 | - |
|
223 | - // help text |
|
224 | - if ( ! empty( $args['help_text'] ) ) { |
|
225 | - $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
226 | - } |
|
227 | - |
|
228 | - // label |
|
229 | - if ( ! empty( $args['label'] ) ) { |
|
230 | - $label_base_class = ''; |
|
231 | - if ( $type == 'file' ) { |
|
232 | - $label_base_class = ' custom-file-label'; |
|
233 | - } elseif ( $type == 'checkbox' ) { |
|
234 | - if ( ! empty( $args['label_force_left'] ) ) { |
|
235 | - $label_args['title'] = wp_kses_post( $args['help_text'] ); |
|
236 | - $help_text = ''; |
|
237 | - //$label_args['class'] .= ' d-inline '; |
|
238 | - $args['wrap_class'] .= ' align-items-center '; |
|
239 | - }else{ |
|
240 | - |
|
241 | - } |
|
242 | - |
|
243 | - $label_base_class = ' custom-control-label'; |
|
244 | - } |
|
245 | - $label_args['class'] .= $label_base_class; |
|
246 | - $temp_label_args = $label_args; |
|
247 | - if(! empty( $args['label_force_left'] )){$temp_label_args['class'] = $label_base_class." text-muted";} |
|
248 | - $label = self::label( $temp_label_args, $type ); |
|
249 | - } |
|
250 | - |
|
251 | - |
|
252 | - |
|
253 | - |
|
254 | - // set help text in the correct position |
|
255 | - if ( $label_after ) { |
|
256 | - $output .= $label . $help_text; |
|
257 | - } |
|
258 | - |
|
259 | - // some input types need a separate wrap |
|
260 | - if ( $type == 'file' ) { |
|
261 | - $output = self::wrap( array( |
|
262 | - 'content' => $output, |
|
263 | - 'class' => 'form-group custom-file' |
|
264 | - ) ); |
|
265 | - } elseif ( $type == 'checkbox' ) { |
|
266 | - |
|
267 | - $label_args['title'] = $args['label']; |
|
268 | - $label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ); |
|
269 | - $label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '<div class="' . $label_col . ' col-form-label"></div>'; |
|
270 | - $switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : ''; |
|
271 | - $wrap_class = $args['switch'] ? 'custom-switch'.$switch_size_class : 'custom-checkbox'; |
|
272 | - if ( ! empty( $args['label_force_left'] ) ) { |
|
273 | - $wrap_class .= ' d-flex align-content-center'; |
|
274 | - $label = str_replace("custom-control-label","", self::label( $label_args, 'cb' ) ); |
|
275 | - } |
|
276 | - $output = self::wrap( array( |
|
277 | - 'content' => $output, |
|
278 | - 'class' => 'custom-control ' . $wrap_class |
|
279 | - ) ); |
|
280 | - |
|
281 | - if ( $args['label_type'] == 'horizontal' ) { |
|
282 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
283 | - $output = $label . '<div class="' . $input_col . '">' . $output . '</div>'; |
|
284 | - } |
|
285 | - } elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) { |
|
286 | - |
|
287 | - |
|
288 | - // allow password field to toggle view |
|
289 | - $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" |
|
138 | + // enqueue the script |
|
139 | + $aui_settings = AyeCode_UI_Settings::instance(); |
|
140 | + $aui_settings->enqueue_iconpicker(); |
|
141 | + } |
|
142 | + |
|
143 | + if ( $type == 'checkbox' && !empty($args['name'] ) && strpos($args['name'], '[') === false ) { |
|
144 | + $output .= '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />'; |
|
145 | + } |
|
146 | + |
|
147 | + // allow clear icon |
|
148 | + if ( $args['input_group_right'] === '' && $args['clear_icon'] ) { |
|
149 | + $font_size = $size == 'sm' ? '1.3' : ( $size == 'lg' ? '1.65' : '1.5' ); |
|
150 | + $args['input_group_right_inside'] = true; |
|
151 | + $args['input_group_right'] = '<span class="input-group-text aui-clear-input c-pointer bg-initial border-0 px-2 d-none" onclick="' . $clear_function . '"><span style="font-size: '.$font_size.'rem" aria-hidden="true" class="close">×</span></span>'; |
|
152 | + } |
|
153 | + |
|
154 | + // open/type |
|
155 | + $output .= '<input type="' . $type . '" '; |
|
156 | + |
|
157 | + // name |
|
158 | + if ( ! empty( $args['name'] ) ) { |
|
159 | + $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
160 | + } |
|
161 | + |
|
162 | + // id |
|
163 | + if ( ! empty( $args['id'] ) ) { |
|
164 | + $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
165 | + } |
|
166 | + |
|
167 | + // placeholder |
|
168 | + if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
169 | + $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
170 | + } |
|
171 | + |
|
172 | + // title |
|
173 | + if ( ! empty( $args['title'] ) ) { |
|
174 | + $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
175 | + } |
|
176 | + |
|
177 | + // value |
|
178 | + if ( ! empty( $args['value'] ) ) { |
|
179 | + $output .= AUI_Component_Helper::value( $args['value'] ); |
|
180 | + } |
|
181 | + |
|
182 | + // checked, for radio and checkboxes |
|
183 | + if ( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ) { |
|
184 | + $output .= ' checked '; |
|
185 | + } |
|
186 | + |
|
187 | + // validation text |
|
188 | + if ( ! empty( $args['validation_text'] ) ) { |
|
189 | + $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
190 | + $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
191 | + } |
|
192 | + |
|
193 | + // validation_pattern |
|
194 | + if ( ! empty( $args['validation_pattern'] ) ) { |
|
195 | + $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
196 | + } |
|
197 | + |
|
198 | + // step (for numbers) |
|
199 | + if ( ! empty( $args['step'] ) ) { |
|
200 | + $output .= ' step="' . $args['step'] . '" '; |
|
201 | + } |
|
202 | + |
|
203 | + // required |
|
204 | + if ( ! empty( $args['required'] ) ) { |
|
205 | + $output .= ' required '; |
|
206 | + } |
|
207 | + |
|
208 | + // class |
|
209 | + $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
210 | + $output .= ' class="form-control ' . $class . '" '; |
|
211 | + |
|
212 | + // data-attributes |
|
213 | + $output .= AUI_Component_Helper::data_attributes( $args ); |
|
214 | + |
|
215 | + // extra attributes |
|
216 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
217 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
218 | + } |
|
219 | + |
|
220 | + // close |
|
221 | + $output .= ' >'; |
|
222 | + |
|
223 | + // help text |
|
224 | + if ( ! empty( $args['help_text'] ) ) { |
|
225 | + $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
226 | + } |
|
227 | + |
|
228 | + // label |
|
229 | + if ( ! empty( $args['label'] ) ) { |
|
230 | + $label_base_class = ''; |
|
231 | + if ( $type == 'file' ) { |
|
232 | + $label_base_class = ' custom-file-label'; |
|
233 | + } elseif ( $type == 'checkbox' ) { |
|
234 | + if ( ! empty( $args['label_force_left'] ) ) { |
|
235 | + $label_args['title'] = wp_kses_post( $args['help_text'] ); |
|
236 | + $help_text = ''; |
|
237 | + //$label_args['class'] .= ' d-inline '; |
|
238 | + $args['wrap_class'] .= ' align-items-center '; |
|
239 | + }else{ |
|
240 | + |
|
241 | + } |
|
242 | + |
|
243 | + $label_base_class = ' custom-control-label'; |
|
244 | + } |
|
245 | + $label_args['class'] .= $label_base_class; |
|
246 | + $temp_label_args = $label_args; |
|
247 | + if(! empty( $args['label_force_left'] )){$temp_label_args['class'] = $label_base_class." text-muted";} |
|
248 | + $label = self::label( $temp_label_args, $type ); |
|
249 | + } |
|
250 | + |
|
251 | + |
|
252 | + |
|
253 | + |
|
254 | + // set help text in the correct position |
|
255 | + if ( $label_after ) { |
|
256 | + $output .= $label . $help_text; |
|
257 | + } |
|
258 | + |
|
259 | + // some input types need a separate wrap |
|
260 | + if ( $type == 'file' ) { |
|
261 | + $output = self::wrap( array( |
|
262 | + 'content' => $output, |
|
263 | + 'class' => 'form-group custom-file' |
|
264 | + ) ); |
|
265 | + } elseif ( $type == 'checkbox' ) { |
|
266 | + |
|
267 | + $label_args['title'] = $args['label']; |
|
268 | + $label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ); |
|
269 | + $label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '<div class="' . $label_col . ' col-form-label"></div>'; |
|
270 | + $switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : ''; |
|
271 | + $wrap_class = $args['switch'] ? 'custom-switch'.$switch_size_class : 'custom-checkbox'; |
|
272 | + if ( ! empty( $args['label_force_left'] ) ) { |
|
273 | + $wrap_class .= ' d-flex align-content-center'; |
|
274 | + $label = str_replace("custom-control-label","", self::label( $label_args, 'cb' ) ); |
|
275 | + } |
|
276 | + $output = self::wrap( array( |
|
277 | + 'content' => $output, |
|
278 | + 'class' => 'custom-control ' . $wrap_class |
|
279 | + ) ); |
|
280 | + |
|
281 | + if ( $args['label_type'] == 'horizontal' ) { |
|
282 | + $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
283 | + $output = $label . '<div class="' . $input_col . '">' . $output . '</div>'; |
|
284 | + } |
|
285 | + } elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) { |
|
286 | + |
|
287 | + |
|
288 | + // allow password field to toggle view |
|
289 | + $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" |
|
290 | 290 | onclick="var $el = jQuery(this).find(\'i\');$el.toggleClass(\'fa-eye fa-eye-slash\'); |
291 | 291 | var $eli = jQuery(this).parent().parent().find(\'input\'); |
292 | 292 | if($el.hasClass(\'fa-eye\')) |
293 | 293 | {$eli.attr(\'type\',\'text\');} |
294 | 294 | else{$eli.attr(\'type\',\'password\');}" |
295 | 295 | ><i class="far fa-fw fa-eye-slash"></i></span>'; |
296 | - } |
|
297 | - |
|
298 | - // input group wraps |
|
299 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
300 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
301 | - $group_size = $size == 'lg' ? ' input-group-lg' : ''; |
|
302 | - $group_size = !$group_size && $size == 'sm' ? ' input-group-sm' : $group_size; |
|
303 | - |
|
304 | - if ( $args['input_group_left'] ) { |
|
305 | - $output = self::wrap( array( |
|
306 | - 'content' => $output, |
|
307 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
308 | - 'input_group_left' => $args['input_group_left'], |
|
309 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
310 | - ) ); |
|
311 | - } |
|
312 | - if ( $args['input_group_right'] ) { |
|
313 | - $output = self::wrap( array( |
|
314 | - 'content' => $output, |
|
315 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
316 | - 'input_group_right' => $args['input_group_right'], |
|
317 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
318 | - ) ); |
|
319 | - } |
|
320 | - |
|
321 | - } |
|
322 | - |
|
323 | - if ( ! $label_after ) { |
|
324 | - $output .= $help_text; |
|
325 | - } |
|
326 | - |
|
327 | - |
|
328 | - if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
329 | - $output = self::wrap( array( |
|
330 | - 'content' => $output, |
|
331 | - 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
332 | - ) ); |
|
333 | - } |
|
334 | - |
|
335 | - if ( ! $label_after ) { |
|
336 | - $output = $label . $output; |
|
337 | - } |
|
338 | - |
|
339 | - // wrap |
|
340 | - if ( ! $args['no_wrap'] ) { |
|
341 | - $form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group'; |
|
342 | - $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
343 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
344 | - $output = self::wrap( array( |
|
345 | - 'content' => $output, |
|
346 | - 'class' => $wrap_class, |
|
347 | - 'element_require' => $args['element_require'], |
|
348 | - 'argument_id' => $args['id'], |
|
349 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
350 | - ) ); |
|
351 | - } |
|
352 | - } |
|
353 | - |
|
354 | - return $output; |
|
355 | - } |
|
356 | - |
|
357 | - public static function label( $args = array(), $type = '' ) { |
|
358 | - //<label for="exampleInputEmail1">Email address</label> |
|
359 | - $defaults = array( |
|
360 | - 'title' => 'div', |
|
361 | - 'for' => '', |
|
362 | - 'class' => '', |
|
363 | - 'label_type' => '', // empty = hidden, top, horizontal |
|
364 | - 'label_col' => '', |
|
365 | - ); |
|
366 | - |
|
367 | - /** |
|
368 | - * Parse incoming $args into an array and merge it with $defaults |
|
369 | - */ |
|
370 | - $args = wp_parse_args( $args, $defaults ); |
|
371 | - $output = ''; |
|
372 | - |
|
373 | - if ( $args['title'] ) { |
|
374 | - |
|
375 | - // maybe hide labels //@todo set a global option for visibility class |
|
376 | - if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) { |
|
377 | - $class = $args['class']; |
|
378 | - } else { |
|
379 | - $class = 'sr-only ' . $args['class']; |
|
380 | - } |
|
381 | - |
|
382 | - // maybe horizontal |
|
383 | - if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
384 | - $class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label'; |
|
385 | - } |
|
386 | - |
|
387 | - // open |
|
388 | - $output .= '<label '; |
|
389 | - |
|
390 | - // for |
|
391 | - if ( ! empty( $args['for'] ) ) { |
|
392 | - $output .= ' for="' . esc_attr( $args['for'] ) . '" '; |
|
393 | - } |
|
394 | - |
|
395 | - // class |
|
396 | - $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
397 | - $output .= ' class="' . $class . '" '; |
|
398 | - |
|
399 | - // close |
|
400 | - $output .= '>'; |
|
401 | - |
|
402 | - |
|
403 | - // title, don't escape fully as can contain html |
|
404 | - if ( ! empty( $args['title'] ) ) { |
|
405 | - $output .= wp_kses_post( $args['title'] ); |
|
406 | - } |
|
407 | - |
|
408 | - // close wrap |
|
409 | - $output .= '</label>'; |
|
410 | - |
|
411 | - |
|
412 | - } |
|
413 | - |
|
414 | - |
|
415 | - return $output; |
|
416 | - } |
|
417 | - |
|
418 | - /** |
|
419 | - * Wrap some content in a HTML wrapper. |
|
420 | - * |
|
421 | - * @param array $args |
|
422 | - * |
|
423 | - * @return string |
|
424 | - */ |
|
425 | - public static function wrap( $args = array() ) { |
|
426 | - $defaults = array( |
|
427 | - 'type' => 'div', |
|
428 | - 'class' => 'form-group', |
|
429 | - 'content' => '', |
|
430 | - 'input_group_left' => '', |
|
431 | - 'input_group_right' => '', |
|
432 | - 'input_group_left_inside' => false, |
|
433 | - 'input_group_right_inside' => false, |
|
434 | - 'element_require' => '', |
|
435 | - 'argument_id' => '', |
|
436 | - 'wrap_attributes' => array() |
|
437 | - ); |
|
438 | - |
|
439 | - /** |
|
440 | - * Parse incoming $args into an array and merge it with $defaults |
|
441 | - */ |
|
442 | - $args = wp_parse_args( $args, $defaults ); |
|
443 | - $output = ''; |
|
444 | - if ( $args['type'] ) { |
|
445 | - |
|
446 | - // open |
|
447 | - $output .= '<' . sanitize_html_class( $args['type'] ); |
|
448 | - |
|
449 | - // element require |
|
450 | - if ( ! empty( $args['element_require'] ) ) { |
|
451 | - $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
452 | - $args['class'] .= " aui-conditional-field"; |
|
453 | - } |
|
454 | - |
|
455 | - // argument_id |
|
456 | - if ( ! empty( $args['argument_id'] ) ) { |
|
457 | - $output .= ' data-argument="' . esc_attr( $args['argument_id'] ) . '"'; |
|
458 | - } |
|
459 | - |
|
460 | - // class |
|
461 | - $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
462 | - $output .= ' class="' . $class . '" '; |
|
463 | - |
|
464 | - // Attributes |
|
465 | - if ( ! empty( $args['wrap_attributes'] ) ) { |
|
466 | - $output .= AUI_Component_Helper::extra_attributes( $args['wrap_attributes'] ); |
|
467 | - } |
|
468 | - |
|
469 | - // close wrap |
|
470 | - $output .= ' >'; |
|
471 | - |
|
472 | - |
|
473 | - // Input group left |
|
474 | - if ( ! empty( $args['input_group_left'] ) ) { |
|
475 | - $position_class = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : ''; |
|
476 | - $input_group_left = strpos( $args['input_group_left'], '<' ) !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>'; |
|
477 | - $output .= '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>'; |
|
478 | - } |
|
479 | - |
|
480 | - // content |
|
481 | - $output .= $args['content']; |
|
482 | - |
|
483 | - // Input group right |
|
484 | - if ( ! empty( $args['input_group_right'] ) ) { |
|
485 | - $position_class = ! empty( $args['input_group_right_inside'] ) ? 'position-absolute h-100' : ''; |
|
486 | - $input_group_right = strpos( $args['input_group_right'], '<' ) !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>'; |
|
487 | - $output .= '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>'; |
|
488 | - } |
|
489 | - |
|
490 | - |
|
491 | - // close wrap |
|
492 | - $output .= '</' . sanitize_html_class( $args['type'] ) . '>'; |
|
493 | - |
|
494 | - |
|
495 | - } else { |
|
496 | - $output = $args['content']; |
|
497 | - } |
|
498 | - |
|
499 | - return $output; |
|
500 | - } |
|
501 | - |
|
502 | - /** |
|
503 | - * Build the component. |
|
504 | - * |
|
505 | - * @param array $args |
|
506 | - * |
|
507 | - * @return string The rendered component. |
|
508 | - */ |
|
509 | - public static function textarea( $args = array() ) { |
|
510 | - $defaults = array( |
|
511 | - 'name' => '', |
|
512 | - 'class' => '', |
|
513 | - 'wrap_class' => '', |
|
514 | - 'id' => '', |
|
515 | - 'placeholder' => '', |
|
516 | - 'title' => '', |
|
517 | - 'value' => '', |
|
518 | - 'required' => false, |
|
519 | - 'label' => '', |
|
520 | - 'label_after' => false, |
|
521 | - 'label_class' => '', |
|
522 | - 'label_type' => '', |
|
523 | - 'label_col' => '', |
|
524 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
525 | - 'input_group_right' => '', |
|
526 | - 'input_group_left' => '', |
|
527 | - 'input_group_right_inside' => false, |
|
528 | - 'help_text' => '', |
|
529 | - 'validation_text' => '', |
|
530 | - 'validation_pattern' => '', |
|
531 | - 'no_wrap' => false, |
|
532 | - 'rows' => '', |
|
533 | - 'wysiwyg' => false, |
|
534 | - 'allow_tags' => false, |
|
535 | - // Allow HTML tags |
|
536 | - 'element_require' => '', |
|
537 | - // [%element_id%] == "1" |
|
538 | - 'extra_attributes' => array(), |
|
539 | - // an array of extra attributes |
|
540 | - 'wrap_attributes' => array(), |
|
541 | - ); |
|
542 | - |
|
543 | - /** |
|
544 | - * Parse incoming $args into an array and merge it with $defaults |
|
545 | - */ |
|
546 | - $args = wp_parse_args( $args, $defaults ); |
|
547 | - $output = ''; |
|
548 | - |
|
549 | - // hidden label option needs to be empty |
|
550 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
551 | - |
|
552 | - // floating labels don't work with wysiwyg so set it as top |
|
553 | - if ( $args['label_type'] == 'floating' && ! empty( $args['wysiwyg'] ) ) { |
|
554 | - $args['label_type'] = 'top'; |
|
555 | - } |
|
556 | - |
|
557 | - $label_after = $args['label_after']; |
|
558 | - |
|
559 | - // floating labels need label after |
|
560 | - if ( $args['label_type'] == 'floating' && empty( $args['wysiwyg'] ) ) { |
|
561 | - $label_after = true; |
|
562 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
563 | - } |
|
564 | - |
|
565 | - // label |
|
566 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
567 | - } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
568 | - $label_args = array( |
|
569 | - 'title' => $args['label'], |
|
570 | - 'for' => $args['id'], |
|
571 | - 'class' => $args['label_class'] . " ", |
|
572 | - 'label_type' => $args['label_type'], |
|
573 | - 'label_col' => $args['label_col'] |
|
574 | - ); |
|
575 | - $output .= self::label( $label_args ); |
|
576 | - } |
|
577 | - |
|
578 | - // maybe horizontal label |
|
579 | - if ( $args['label_type'] == 'horizontal' ) { |
|
580 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
581 | - $output .= '<div class="' . $input_col . '">'; |
|
582 | - } |
|
583 | - |
|
584 | - if ( ! empty( $args['wysiwyg'] ) ) { |
|
585 | - ob_start(); |
|
586 | - $content = $args['value']; |
|
587 | - $editor_id = ! empty( $args['id'] ) ? sanitize_html_class( $args['id'] ) : 'wp_editor'; |
|
588 | - $settings = array( |
|
589 | - 'textarea_rows' => ! empty( absint( $args['rows'] ) ) ? absint( $args['rows'] ) : 4, |
|
590 | - 'quicktags' => false, |
|
591 | - 'media_buttons' => false, |
|
592 | - 'editor_class' => 'form-control', |
|
593 | - 'textarea_name' => ! empty( $args['name'] ) ? sanitize_html_class( $args['name'] ) : sanitize_html_class( $args['id'] ), |
|
594 | - 'teeny' => true, |
|
595 | - ); |
|
596 | - |
|
597 | - // maybe set settings if array |
|
598 | - if ( is_array( $args['wysiwyg'] ) ) { |
|
599 | - $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
600 | - } |
|
601 | - |
|
602 | - wp_editor( $content, $editor_id, $settings ); |
|
603 | - $output .= ob_get_clean(); |
|
604 | - } else { |
|
605 | - |
|
606 | - // open |
|
607 | - $output .= '<textarea '; |
|
608 | - |
|
609 | - // name |
|
610 | - if ( ! empty( $args['name'] ) ) { |
|
611 | - $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
612 | - } |
|
613 | - |
|
614 | - // id |
|
615 | - if ( ! empty( $args['id'] ) ) { |
|
616 | - $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
617 | - } |
|
618 | - |
|
619 | - // placeholder |
|
620 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
621 | - $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
622 | - } |
|
623 | - |
|
624 | - // title |
|
625 | - if ( ! empty( $args['title'] ) ) { |
|
626 | - $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
627 | - } |
|
628 | - |
|
629 | - // validation text |
|
630 | - if ( ! empty( $args['validation_text'] ) ) { |
|
631 | - $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
632 | - $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
633 | - } |
|
634 | - |
|
635 | - // validation_pattern |
|
636 | - if ( ! empty( $args['validation_pattern'] ) ) { |
|
637 | - $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
638 | - } |
|
639 | - |
|
640 | - // required |
|
641 | - if ( ! empty( $args['required'] ) ) { |
|
642 | - $output .= ' required '; |
|
643 | - } |
|
644 | - |
|
645 | - // rows |
|
646 | - if ( ! empty( $args['rows'] ) ) { |
|
647 | - $output .= ' rows="' . absint( $args['rows'] ) . '" '; |
|
648 | - } |
|
649 | - |
|
650 | - |
|
651 | - // class |
|
652 | - $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
653 | - $output .= ' class="form-control ' . $class . '" '; |
|
654 | - |
|
655 | - // extra attributes |
|
656 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
657 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
658 | - } |
|
659 | - |
|
660 | - // close tag |
|
661 | - $output .= ' >'; |
|
662 | - |
|
663 | - // value |
|
664 | - if ( ! empty( $args['value'] ) ) { |
|
665 | - if ( ! empty( $args['allow_tags'] ) ) { |
|
666 | - $output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML. |
|
667 | - } else { |
|
668 | - $output .= AUI_Component_Helper::sanitize_textarea_field( $args['value'] ); |
|
669 | - } |
|
670 | - } |
|
671 | - |
|
672 | - // closing tag |
|
673 | - $output .= '</textarea>'; |
|
674 | - |
|
675 | - |
|
676 | - // input group wraps |
|
677 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
678 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
679 | - if ( $args['input_group_left'] ) { |
|
680 | - $output = self::wrap( array( |
|
681 | - 'content' => $output, |
|
682 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
683 | - 'input_group_left' => $args['input_group_left'], |
|
684 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
685 | - ) ); |
|
686 | - } |
|
687 | - if ( $args['input_group_right'] ) { |
|
688 | - $output = self::wrap( array( |
|
689 | - 'content' => $output, |
|
690 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
691 | - 'input_group_right' => $args['input_group_right'], |
|
692 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
693 | - ) ); |
|
694 | - } |
|
695 | - |
|
696 | - } |
|
697 | - |
|
698 | - |
|
699 | - } |
|
700 | - |
|
701 | - if ( ! empty( $args['label'] ) && $label_after ) { |
|
702 | - $label_args = array( |
|
703 | - 'title' => $args['label'], |
|
704 | - 'for' => $args['id'], |
|
705 | - 'class' => $args['label_class'] . " ", |
|
706 | - 'label_type' => $args['label_type'], |
|
707 | - 'label_col' => $args['label_col'] |
|
708 | - ); |
|
709 | - $output .= self::label( $label_args ); |
|
710 | - } |
|
711 | - |
|
712 | - // help text |
|
713 | - if ( ! empty( $args['help_text'] ) ) { |
|
714 | - $output .= AUI_Component_Helper::help_text( $args['help_text'] ); |
|
715 | - } |
|
716 | - |
|
717 | - // maybe horizontal label |
|
718 | - if ( $args['label_type'] == 'horizontal' ) { |
|
719 | - $output .= '</div>'; |
|
720 | - } |
|
721 | - |
|
722 | - |
|
723 | - // wrap |
|
724 | - if ( ! $args['no_wrap'] ) { |
|
725 | - $form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : 'form-group'; |
|
726 | - $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
727 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
728 | - $output = self::wrap( array( |
|
729 | - 'content' => $output, |
|
730 | - 'class' => $wrap_class, |
|
731 | - 'element_require' => $args['element_require'], |
|
732 | - 'argument_id' => $args['id'], |
|
733 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
734 | - ) ); |
|
735 | - } |
|
736 | - |
|
737 | - |
|
738 | - return $output; |
|
739 | - } |
|
740 | - |
|
741 | - /** |
|
742 | - * Build the component. |
|
743 | - * |
|
744 | - * @param array $args |
|
745 | - * |
|
746 | - * @return string The rendered component. |
|
747 | - */ |
|
748 | - public static function select( $args = array() ) { |
|
749 | - $defaults = array( |
|
750 | - 'class' => '', |
|
751 | - 'wrap_class' => '', |
|
752 | - 'id' => '', |
|
753 | - 'title' => '', |
|
754 | - 'value' => '', |
|
755 | - // can be an array or a string |
|
756 | - 'required' => false, |
|
757 | - 'label' => '', |
|
758 | - 'label_after' => false, |
|
759 | - 'label_type' => '', |
|
760 | - 'label_col' => '', |
|
761 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
762 | - 'label_class' => '', |
|
763 | - 'help_text' => '', |
|
764 | - 'placeholder' => '', |
|
765 | - 'options' => array(), |
|
766 | - // array or string |
|
767 | - 'icon' => '', |
|
768 | - 'multiple' => false, |
|
769 | - 'select2' => false, |
|
770 | - 'no_wrap' => false, |
|
771 | - 'input_group_right' => '', |
|
772 | - 'input_group_left' => '', |
|
773 | - 'input_group_right_inside' => false, // forces the input group inside the input |
|
774 | - 'input_group_left_inside' => false, // forces the input group inside the input |
|
775 | - 'element_require' => '', |
|
776 | - // [%element_id%] == "1" |
|
777 | - 'extra_attributes' => array(), |
|
778 | - // an array of extra attributes |
|
779 | - 'wrap_attributes' => array(), |
|
780 | - ); |
|
781 | - |
|
782 | - /** |
|
783 | - * Parse incoming $args into an array and merge it with $defaults |
|
784 | - */ |
|
785 | - $args = wp_parse_args( $args, $defaults ); |
|
786 | - $output = ''; |
|
787 | - |
|
788 | - // for now lets hide floating labels |
|
789 | - if ( $args['label_type'] == 'floating' ) { |
|
790 | - $args['label_type'] = 'hidden'; |
|
791 | - } |
|
792 | - |
|
793 | - // hidden label option needs to be empty |
|
794 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
795 | - |
|
796 | - |
|
797 | - $label_after = $args['label_after']; |
|
798 | - |
|
799 | - // floating labels need label after |
|
800 | - if ( $args['label_type'] == 'floating' ) { |
|
801 | - $label_after = true; |
|
802 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
803 | - } |
|
804 | - |
|
805 | - // Maybe setup select2 |
|
806 | - $is_select2 = false; |
|
807 | - if ( ! empty( $args['select2'] ) ) { |
|
808 | - $args['class'] .= ' aui-select2'; |
|
809 | - $is_select2 = true; |
|
810 | - } elseif ( strpos( $args['class'], 'aui-select2' ) !== false ) { |
|
811 | - $is_select2 = true; |
|
812 | - } |
|
813 | - |
|
814 | - // select2 tags |
|
815 | - if ( ! empty( $args['select2'] ) && $args['select2'] === 'tags' ) { // triple equals needed here for some reason |
|
816 | - $args['data-tags'] = 'true'; |
|
817 | - $args['data-token-separators'] = "[',']"; |
|
818 | - $args['multiple'] = true; |
|
819 | - } |
|
820 | - |
|
821 | - // select2 placeholder |
|
822 | - if ( $is_select2 && isset( $args['placeholder'] ) && '' != $args['placeholder'] && empty( $args['data-placeholder'] ) ) { |
|
823 | - $args['data-placeholder'] = esc_attr( $args['placeholder'] ); |
|
824 | - $args['data-allow-clear'] = isset( $args['data-allow-clear'] ) ? (bool) $args['data-allow-clear'] : true; |
|
825 | - } |
|
826 | - |
|
827 | - |
|
828 | - |
|
829 | - // maybe horizontal label |
|
296 | + } |
|
297 | + |
|
298 | + // input group wraps |
|
299 | + if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
300 | + $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
301 | + $group_size = $size == 'lg' ? ' input-group-lg' : ''; |
|
302 | + $group_size = !$group_size && $size == 'sm' ? ' input-group-sm' : $group_size; |
|
303 | + |
|
304 | + if ( $args['input_group_left'] ) { |
|
305 | + $output = self::wrap( array( |
|
306 | + 'content' => $output, |
|
307 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
308 | + 'input_group_left' => $args['input_group_left'], |
|
309 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
310 | + ) ); |
|
311 | + } |
|
312 | + if ( $args['input_group_right'] ) { |
|
313 | + $output = self::wrap( array( |
|
314 | + 'content' => $output, |
|
315 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
316 | + 'input_group_right' => $args['input_group_right'], |
|
317 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
318 | + ) ); |
|
319 | + } |
|
320 | + |
|
321 | + } |
|
322 | + |
|
323 | + if ( ! $label_after ) { |
|
324 | + $output .= $help_text; |
|
325 | + } |
|
326 | + |
|
327 | + |
|
328 | + if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
329 | + $output = self::wrap( array( |
|
330 | + 'content' => $output, |
|
331 | + 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
332 | + ) ); |
|
333 | + } |
|
334 | + |
|
335 | + if ( ! $label_after ) { |
|
336 | + $output = $label . $output; |
|
337 | + } |
|
338 | + |
|
339 | + // wrap |
|
340 | + if ( ! $args['no_wrap'] ) { |
|
341 | + $form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group'; |
|
342 | + $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
343 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
344 | + $output = self::wrap( array( |
|
345 | + 'content' => $output, |
|
346 | + 'class' => $wrap_class, |
|
347 | + 'element_require' => $args['element_require'], |
|
348 | + 'argument_id' => $args['id'], |
|
349 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
350 | + ) ); |
|
351 | + } |
|
352 | + } |
|
353 | + |
|
354 | + return $output; |
|
355 | + } |
|
356 | + |
|
357 | + public static function label( $args = array(), $type = '' ) { |
|
358 | + //<label for="exampleInputEmail1">Email address</label> |
|
359 | + $defaults = array( |
|
360 | + 'title' => 'div', |
|
361 | + 'for' => '', |
|
362 | + 'class' => '', |
|
363 | + 'label_type' => '', // empty = hidden, top, horizontal |
|
364 | + 'label_col' => '', |
|
365 | + ); |
|
366 | + |
|
367 | + /** |
|
368 | + * Parse incoming $args into an array and merge it with $defaults |
|
369 | + */ |
|
370 | + $args = wp_parse_args( $args, $defaults ); |
|
371 | + $output = ''; |
|
372 | + |
|
373 | + if ( $args['title'] ) { |
|
374 | + |
|
375 | + // maybe hide labels //@todo set a global option for visibility class |
|
376 | + if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) { |
|
377 | + $class = $args['class']; |
|
378 | + } else { |
|
379 | + $class = 'sr-only ' . $args['class']; |
|
380 | + } |
|
381 | + |
|
382 | + // maybe horizontal |
|
383 | + if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
384 | + $class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label'; |
|
385 | + } |
|
386 | + |
|
387 | + // open |
|
388 | + $output .= '<label '; |
|
389 | + |
|
390 | + // for |
|
391 | + if ( ! empty( $args['for'] ) ) { |
|
392 | + $output .= ' for="' . esc_attr( $args['for'] ) . '" '; |
|
393 | + } |
|
394 | + |
|
395 | + // class |
|
396 | + $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
397 | + $output .= ' class="' . $class . '" '; |
|
398 | + |
|
399 | + // close |
|
400 | + $output .= '>'; |
|
401 | + |
|
402 | + |
|
403 | + // title, don't escape fully as can contain html |
|
404 | + if ( ! empty( $args['title'] ) ) { |
|
405 | + $output .= wp_kses_post( $args['title'] ); |
|
406 | + } |
|
407 | + |
|
408 | + // close wrap |
|
409 | + $output .= '</label>'; |
|
410 | + |
|
411 | + |
|
412 | + } |
|
413 | + |
|
414 | + |
|
415 | + return $output; |
|
416 | + } |
|
417 | + |
|
418 | + /** |
|
419 | + * Wrap some content in a HTML wrapper. |
|
420 | + * |
|
421 | + * @param array $args |
|
422 | + * |
|
423 | + * @return string |
|
424 | + */ |
|
425 | + public static function wrap( $args = array() ) { |
|
426 | + $defaults = array( |
|
427 | + 'type' => 'div', |
|
428 | + 'class' => 'form-group', |
|
429 | + 'content' => '', |
|
430 | + 'input_group_left' => '', |
|
431 | + 'input_group_right' => '', |
|
432 | + 'input_group_left_inside' => false, |
|
433 | + 'input_group_right_inside' => false, |
|
434 | + 'element_require' => '', |
|
435 | + 'argument_id' => '', |
|
436 | + 'wrap_attributes' => array() |
|
437 | + ); |
|
438 | + |
|
439 | + /** |
|
440 | + * Parse incoming $args into an array and merge it with $defaults |
|
441 | + */ |
|
442 | + $args = wp_parse_args( $args, $defaults ); |
|
443 | + $output = ''; |
|
444 | + if ( $args['type'] ) { |
|
445 | + |
|
446 | + // open |
|
447 | + $output .= '<' . sanitize_html_class( $args['type'] ); |
|
448 | + |
|
449 | + // element require |
|
450 | + if ( ! empty( $args['element_require'] ) ) { |
|
451 | + $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
452 | + $args['class'] .= " aui-conditional-field"; |
|
453 | + } |
|
454 | + |
|
455 | + // argument_id |
|
456 | + if ( ! empty( $args['argument_id'] ) ) { |
|
457 | + $output .= ' data-argument="' . esc_attr( $args['argument_id'] ) . '"'; |
|
458 | + } |
|
459 | + |
|
460 | + // class |
|
461 | + $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
462 | + $output .= ' class="' . $class . '" '; |
|
463 | + |
|
464 | + // Attributes |
|
465 | + if ( ! empty( $args['wrap_attributes'] ) ) { |
|
466 | + $output .= AUI_Component_Helper::extra_attributes( $args['wrap_attributes'] ); |
|
467 | + } |
|
468 | + |
|
469 | + // close wrap |
|
470 | + $output .= ' >'; |
|
471 | + |
|
472 | + |
|
473 | + // Input group left |
|
474 | + if ( ! empty( $args['input_group_left'] ) ) { |
|
475 | + $position_class = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : ''; |
|
476 | + $input_group_left = strpos( $args['input_group_left'], '<' ) !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>'; |
|
477 | + $output .= '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>'; |
|
478 | + } |
|
479 | + |
|
480 | + // content |
|
481 | + $output .= $args['content']; |
|
482 | + |
|
483 | + // Input group right |
|
484 | + if ( ! empty( $args['input_group_right'] ) ) { |
|
485 | + $position_class = ! empty( $args['input_group_right_inside'] ) ? 'position-absolute h-100' : ''; |
|
486 | + $input_group_right = strpos( $args['input_group_right'], '<' ) !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>'; |
|
487 | + $output .= '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>'; |
|
488 | + } |
|
489 | + |
|
490 | + |
|
491 | + // close wrap |
|
492 | + $output .= '</' . sanitize_html_class( $args['type'] ) . '>'; |
|
493 | + |
|
494 | + |
|
495 | + } else { |
|
496 | + $output = $args['content']; |
|
497 | + } |
|
498 | + |
|
499 | + return $output; |
|
500 | + } |
|
501 | + |
|
502 | + /** |
|
503 | + * Build the component. |
|
504 | + * |
|
505 | + * @param array $args |
|
506 | + * |
|
507 | + * @return string The rendered component. |
|
508 | + */ |
|
509 | + public static function textarea( $args = array() ) { |
|
510 | + $defaults = array( |
|
511 | + 'name' => '', |
|
512 | + 'class' => '', |
|
513 | + 'wrap_class' => '', |
|
514 | + 'id' => '', |
|
515 | + 'placeholder' => '', |
|
516 | + 'title' => '', |
|
517 | + 'value' => '', |
|
518 | + 'required' => false, |
|
519 | + 'label' => '', |
|
520 | + 'label_after' => false, |
|
521 | + 'label_class' => '', |
|
522 | + 'label_type' => '', |
|
523 | + 'label_col' => '', |
|
524 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
525 | + 'input_group_right' => '', |
|
526 | + 'input_group_left' => '', |
|
527 | + 'input_group_right_inside' => false, |
|
528 | + 'help_text' => '', |
|
529 | + 'validation_text' => '', |
|
530 | + 'validation_pattern' => '', |
|
531 | + 'no_wrap' => false, |
|
532 | + 'rows' => '', |
|
533 | + 'wysiwyg' => false, |
|
534 | + 'allow_tags' => false, |
|
535 | + // Allow HTML tags |
|
536 | + 'element_require' => '', |
|
537 | + // [%element_id%] == "1" |
|
538 | + 'extra_attributes' => array(), |
|
539 | + // an array of extra attributes |
|
540 | + 'wrap_attributes' => array(), |
|
541 | + ); |
|
542 | + |
|
543 | + /** |
|
544 | + * Parse incoming $args into an array and merge it with $defaults |
|
545 | + */ |
|
546 | + $args = wp_parse_args( $args, $defaults ); |
|
547 | + $output = ''; |
|
548 | + |
|
549 | + // hidden label option needs to be empty |
|
550 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
551 | + |
|
552 | + // floating labels don't work with wysiwyg so set it as top |
|
553 | + if ( $args['label_type'] == 'floating' && ! empty( $args['wysiwyg'] ) ) { |
|
554 | + $args['label_type'] = 'top'; |
|
555 | + } |
|
556 | + |
|
557 | + $label_after = $args['label_after']; |
|
558 | + |
|
559 | + // floating labels need label after |
|
560 | + if ( $args['label_type'] == 'floating' && empty( $args['wysiwyg'] ) ) { |
|
561 | + $label_after = true; |
|
562 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
563 | + } |
|
564 | + |
|
565 | + // label |
|
566 | + if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
567 | + } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
568 | + $label_args = array( |
|
569 | + 'title' => $args['label'], |
|
570 | + 'for' => $args['id'], |
|
571 | + 'class' => $args['label_class'] . " ", |
|
572 | + 'label_type' => $args['label_type'], |
|
573 | + 'label_col' => $args['label_col'] |
|
574 | + ); |
|
575 | + $output .= self::label( $label_args ); |
|
576 | + } |
|
577 | + |
|
578 | + // maybe horizontal label |
|
579 | + if ( $args['label_type'] == 'horizontal' ) { |
|
580 | + $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
581 | + $output .= '<div class="' . $input_col . '">'; |
|
582 | + } |
|
583 | + |
|
584 | + if ( ! empty( $args['wysiwyg'] ) ) { |
|
585 | + ob_start(); |
|
586 | + $content = $args['value']; |
|
587 | + $editor_id = ! empty( $args['id'] ) ? sanitize_html_class( $args['id'] ) : 'wp_editor'; |
|
588 | + $settings = array( |
|
589 | + 'textarea_rows' => ! empty( absint( $args['rows'] ) ) ? absint( $args['rows'] ) : 4, |
|
590 | + 'quicktags' => false, |
|
591 | + 'media_buttons' => false, |
|
592 | + 'editor_class' => 'form-control', |
|
593 | + 'textarea_name' => ! empty( $args['name'] ) ? sanitize_html_class( $args['name'] ) : sanitize_html_class( $args['id'] ), |
|
594 | + 'teeny' => true, |
|
595 | + ); |
|
596 | + |
|
597 | + // maybe set settings if array |
|
598 | + if ( is_array( $args['wysiwyg'] ) ) { |
|
599 | + $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
600 | + } |
|
601 | + |
|
602 | + wp_editor( $content, $editor_id, $settings ); |
|
603 | + $output .= ob_get_clean(); |
|
604 | + } else { |
|
605 | + |
|
606 | + // open |
|
607 | + $output .= '<textarea '; |
|
608 | + |
|
609 | + // name |
|
610 | + if ( ! empty( $args['name'] ) ) { |
|
611 | + $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
612 | + } |
|
613 | + |
|
614 | + // id |
|
615 | + if ( ! empty( $args['id'] ) ) { |
|
616 | + $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
617 | + } |
|
618 | + |
|
619 | + // placeholder |
|
620 | + if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
621 | + $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
622 | + } |
|
623 | + |
|
624 | + // title |
|
625 | + if ( ! empty( $args['title'] ) ) { |
|
626 | + $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
627 | + } |
|
628 | + |
|
629 | + // validation text |
|
630 | + if ( ! empty( $args['validation_text'] ) ) { |
|
631 | + $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
632 | + $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
633 | + } |
|
634 | + |
|
635 | + // validation_pattern |
|
636 | + if ( ! empty( $args['validation_pattern'] ) ) { |
|
637 | + $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
638 | + } |
|
639 | + |
|
640 | + // required |
|
641 | + if ( ! empty( $args['required'] ) ) { |
|
642 | + $output .= ' required '; |
|
643 | + } |
|
644 | + |
|
645 | + // rows |
|
646 | + if ( ! empty( $args['rows'] ) ) { |
|
647 | + $output .= ' rows="' . absint( $args['rows'] ) . '" '; |
|
648 | + } |
|
649 | + |
|
650 | + |
|
651 | + // class |
|
652 | + $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
653 | + $output .= ' class="form-control ' . $class . '" '; |
|
654 | + |
|
655 | + // extra attributes |
|
656 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
657 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
658 | + } |
|
659 | + |
|
660 | + // close tag |
|
661 | + $output .= ' >'; |
|
662 | + |
|
663 | + // value |
|
664 | + if ( ! empty( $args['value'] ) ) { |
|
665 | + if ( ! empty( $args['allow_tags'] ) ) { |
|
666 | + $output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML. |
|
667 | + } else { |
|
668 | + $output .= AUI_Component_Helper::sanitize_textarea_field( $args['value'] ); |
|
669 | + } |
|
670 | + } |
|
671 | + |
|
672 | + // closing tag |
|
673 | + $output .= '</textarea>'; |
|
674 | + |
|
675 | + |
|
676 | + // input group wraps |
|
677 | + if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
678 | + $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
679 | + if ( $args['input_group_left'] ) { |
|
680 | + $output = self::wrap( array( |
|
681 | + 'content' => $output, |
|
682 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
683 | + 'input_group_left' => $args['input_group_left'], |
|
684 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
685 | + ) ); |
|
686 | + } |
|
687 | + if ( $args['input_group_right'] ) { |
|
688 | + $output = self::wrap( array( |
|
689 | + 'content' => $output, |
|
690 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
691 | + 'input_group_right' => $args['input_group_right'], |
|
692 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
693 | + ) ); |
|
694 | + } |
|
695 | + |
|
696 | + } |
|
697 | + |
|
698 | + |
|
699 | + } |
|
700 | + |
|
701 | + if ( ! empty( $args['label'] ) && $label_after ) { |
|
702 | + $label_args = array( |
|
703 | + 'title' => $args['label'], |
|
704 | + 'for' => $args['id'], |
|
705 | + 'class' => $args['label_class'] . " ", |
|
706 | + 'label_type' => $args['label_type'], |
|
707 | + 'label_col' => $args['label_col'] |
|
708 | + ); |
|
709 | + $output .= self::label( $label_args ); |
|
710 | + } |
|
711 | + |
|
712 | + // help text |
|
713 | + if ( ! empty( $args['help_text'] ) ) { |
|
714 | + $output .= AUI_Component_Helper::help_text( $args['help_text'] ); |
|
715 | + } |
|
716 | + |
|
717 | + // maybe horizontal label |
|
718 | + if ( $args['label_type'] == 'horizontal' ) { |
|
719 | + $output .= '</div>'; |
|
720 | + } |
|
721 | + |
|
722 | + |
|
723 | + // wrap |
|
724 | + if ( ! $args['no_wrap'] ) { |
|
725 | + $form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : 'form-group'; |
|
726 | + $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
727 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
728 | + $output = self::wrap( array( |
|
729 | + 'content' => $output, |
|
730 | + 'class' => $wrap_class, |
|
731 | + 'element_require' => $args['element_require'], |
|
732 | + 'argument_id' => $args['id'], |
|
733 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
734 | + ) ); |
|
735 | + } |
|
736 | + |
|
737 | + |
|
738 | + return $output; |
|
739 | + } |
|
740 | + |
|
741 | + /** |
|
742 | + * Build the component. |
|
743 | + * |
|
744 | + * @param array $args |
|
745 | + * |
|
746 | + * @return string The rendered component. |
|
747 | + */ |
|
748 | + public static function select( $args = array() ) { |
|
749 | + $defaults = array( |
|
750 | + 'class' => '', |
|
751 | + 'wrap_class' => '', |
|
752 | + 'id' => '', |
|
753 | + 'title' => '', |
|
754 | + 'value' => '', |
|
755 | + // can be an array or a string |
|
756 | + 'required' => false, |
|
757 | + 'label' => '', |
|
758 | + 'label_after' => false, |
|
759 | + 'label_type' => '', |
|
760 | + 'label_col' => '', |
|
761 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
762 | + 'label_class' => '', |
|
763 | + 'help_text' => '', |
|
764 | + 'placeholder' => '', |
|
765 | + 'options' => array(), |
|
766 | + // array or string |
|
767 | + 'icon' => '', |
|
768 | + 'multiple' => false, |
|
769 | + 'select2' => false, |
|
770 | + 'no_wrap' => false, |
|
771 | + 'input_group_right' => '', |
|
772 | + 'input_group_left' => '', |
|
773 | + 'input_group_right_inside' => false, // forces the input group inside the input |
|
774 | + 'input_group_left_inside' => false, // forces the input group inside the input |
|
775 | + 'element_require' => '', |
|
776 | + // [%element_id%] == "1" |
|
777 | + 'extra_attributes' => array(), |
|
778 | + // an array of extra attributes |
|
779 | + 'wrap_attributes' => array(), |
|
780 | + ); |
|
781 | + |
|
782 | + /** |
|
783 | + * Parse incoming $args into an array and merge it with $defaults |
|
784 | + */ |
|
785 | + $args = wp_parse_args( $args, $defaults ); |
|
786 | + $output = ''; |
|
787 | + |
|
788 | + // for now lets hide floating labels |
|
789 | + if ( $args['label_type'] == 'floating' ) { |
|
790 | + $args['label_type'] = 'hidden'; |
|
791 | + } |
|
792 | + |
|
793 | + // hidden label option needs to be empty |
|
794 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
795 | + |
|
796 | + |
|
797 | + $label_after = $args['label_after']; |
|
798 | + |
|
799 | + // floating labels need label after |
|
800 | + if ( $args['label_type'] == 'floating' ) { |
|
801 | + $label_after = true; |
|
802 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
803 | + } |
|
804 | + |
|
805 | + // Maybe setup select2 |
|
806 | + $is_select2 = false; |
|
807 | + if ( ! empty( $args['select2'] ) ) { |
|
808 | + $args['class'] .= ' aui-select2'; |
|
809 | + $is_select2 = true; |
|
810 | + } elseif ( strpos( $args['class'], 'aui-select2' ) !== false ) { |
|
811 | + $is_select2 = true; |
|
812 | + } |
|
813 | + |
|
814 | + // select2 tags |
|
815 | + if ( ! empty( $args['select2'] ) && $args['select2'] === 'tags' ) { // triple equals needed here for some reason |
|
816 | + $args['data-tags'] = 'true'; |
|
817 | + $args['data-token-separators'] = "[',']"; |
|
818 | + $args['multiple'] = true; |
|
819 | + } |
|
820 | + |
|
821 | + // select2 placeholder |
|
822 | + if ( $is_select2 && isset( $args['placeholder'] ) && '' != $args['placeholder'] && empty( $args['data-placeholder'] ) ) { |
|
823 | + $args['data-placeholder'] = esc_attr( $args['placeholder'] ); |
|
824 | + $args['data-allow-clear'] = isset( $args['data-allow-clear'] ) ? (bool) $args['data-allow-clear'] : true; |
|
825 | + } |
|
826 | + |
|
827 | + |
|
828 | + |
|
829 | + // maybe horizontal label |
|
830 | 830 | // if ( $args['label_type'] == 'horizontal' ) { |
831 | 831 | // $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
832 | 832 | // $output .= '<div class="' . $input_col . '">'; |
833 | 833 | // } |
834 | 834 | |
835 | - // Set hidden input to save empty value for multiselect. |
|
836 | - if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) { |
|
837 | - $output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value=""/>'; |
|
838 | - } |
|
839 | - |
|
840 | - // open/type |
|
841 | - $output .= '<select '; |
|
842 | - |
|
843 | - // style |
|
844 | - if ( $is_select2 && !($args['input_group_left'] || $args['input_group_right'])) { |
|
845 | - $output .= " style='width:100%;' "; |
|
846 | - } |
|
847 | - |
|
848 | - // element require |
|
849 | - if ( ! empty( $args['element_require'] ) ) { |
|
850 | - $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
851 | - $args['class'] .= " aui-conditional-field"; |
|
852 | - } |
|
853 | - |
|
854 | - // class |
|
855 | - $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
856 | - $output .= AUI_Component_Helper::class_attr( 'custom-select ' . $class ); |
|
857 | - |
|
858 | - // name |
|
859 | - if ( ! empty( $args['name'] ) ) { |
|
860 | - $output .= AUI_Component_Helper::name( $args['name'], $args['multiple'] ); |
|
861 | - } |
|
862 | - |
|
863 | - // id |
|
864 | - if ( ! empty( $args['id'] ) ) { |
|
865 | - $output .= AUI_Component_Helper::id( $args['id'] ); |
|
866 | - } |
|
867 | - |
|
868 | - // title |
|
869 | - if ( ! empty( $args['title'] ) ) { |
|
870 | - $output .= AUI_Component_Helper::title( $args['title'] ); |
|
871 | - } |
|
872 | - |
|
873 | - // data-attributes |
|
874 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
875 | - |
|
876 | - // aria-attributes |
|
877 | - $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
878 | - |
|
879 | - // extra attributes |
|
880 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
881 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
882 | - } |
|
883 | - |
|
884 | - // required |
|
885 | - if ( ! empty( $args['required'] ) ) { |
|
886 | - $output .= ' required '; |
|
887 | - } |
|
888 | - |
|
889 | - // multiple |
|
890 | - if ( ! empty( $args['multiple'] ) ) { |
|
891 | - $output .= ' multiple '; |
|
892 | - } |
|
893 | - |
|
894 | - // close opening tag |
|
895 | - $output .= ' >'; |
|
896 | - |
|
897 | - // placeholder |
|
898 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] && ! $is_select2 ) { |
|
899 | - $output .= '<option value="" disabled selected hidden>' . esc_attr( $args['placeholder'] ) . '</option>'; |
|
900 | - } elseif ( $is_select2 && ! empty( $args['placeholder'] ) ) { |
|
901 | - $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
|
902 | - } |
|
903 | - |
|
904 | - // Options |
|
905 | - if ( ! empty( $args['options'] ) ) { |
|
906 | - |
|
907 | - if ( ! is_array( $args['options'] ) ) { |
|
908 | - $output .= $args['options']; // not the preferred way but an option |
|
909 | - } else { |
|
910 | - foreach ( $args['options'] as $val => $name ) { |
|
911 | - $selected = ''; |
|
912 | - if ( is_array( $name ) ) { |
|
913 | - if ( isset( $name['optgroup'] ) && ( $name['optgroup'] == 'start' || $name['optgroup'] == 'end' ) ) { |
|
914 | - $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
915 | - |
|
916 | - $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>'; |
|
917 | - } else { |
|
918 | - $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
919 | - $option_value = isset( $name['value'] ) ? $name['value'] : ''; |
|
920 | - $extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes( $name['extra_attributes'] ) : ''; |
|
921 | - if ( ! empty( $args['multiple'] ) && ! empty( $args['value'] ) && is_array( $args['value'] ) ) { |
|
922 | - $selected = in_array( $option_value, stripslashes_deep( $args['value'] ) ) ? "selected" : ""; |
|
923 | - } elseif ( ! empty( $args['value'] ) ) { |
|
924 | - $selected = selected( $option_value, stripslashes_deep( $args['value'] ), false ); |
|
925 | - } elseif ( empty( $args['value'] ) && $args['value'] === $option_value ) { |
|
926 | - $selected = selected( $option_value, $args['value'], false ); |
|
927 | - } |
|
928 | - |
|
929 | - $output .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . ' '.$extra_attributes .'>' . $option_label . '</option>'; |
|
930 | - } |
|
931 | - } else { |
|
932 | - if ( ! empty( $args['value'] ) ) { |
|
933 | - if ( is_array( $args['value'] ) ) { |
|
934 | - $selected = in_array( $val, $args['value'] ) ? 'selected="selected"' : ''; |
|
935 | - } elseif ( ! empty( $args['value'] ) ) { |
|
936 | - $selected = selected( $args['value'], $val, false ); |
|
937 | - } |
|
938 | - } elseif ( $args['value'] === $val ) { |
|
939 | - $selected = selected( $args['value'], $val, false ); |
|
940 | - } |
|
941 | - $output .= '<option value="' . esc_attr( $val ) . '" ' . $selected . '>' . esc_attr( $name ) . '</option>'; |
|
942 | - } |
|
943 | - } |
|
944 | - } |
|
945 | - |
|
946 | - } |
|
947 | - |
|
948 | - // closing tag |
|
949 | - $output .= '</select>'; |
|
950 | - |
|
951 | - $label = ''; |
|
952 | - $help_text = ''; |
|
953 | - // label |
|
954 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
955 | - } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
956 | - $label_args = array( |
|
957 | - 'title' => $args['label'], |
|
958 | - 'for' => $args['id'], |
|
959 | - 'class' => $args['label_class'] . " ", |
|
960 | - 'label_type' => $args['label_type'], |
|
961 | - 'label_col' => $args['label_col'] |
|
962 | - ); |
|
963 | - $label = self::label( $label_args ); |
|
964 | - } |
|
965 | - |
|
966 | - // help text |
|
967 | - if ( ! empty( $args['help_text'] ) ) { |
|
968 | - $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
969 | - } |
|
970 | - |
|
971 | - // input group wraps |
|
972 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
973 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
974 | - if ( $args['input_group_left'] ) { |
|
975 | - $output = self::wrap( array( |
|
976 | - 'content' => $output, |
|
977 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
978 | - 'input_group_left' => $args['input_group_left'], |
|
979 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
980 | - ) ); |
|
981 | - } |
|
982 | - if ( $args['input_group_right'] ) { |
|
983 | - $output = self::wrap( array( |
|
984 | - 'content' => $output, |
|
985 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
986 | - 'input_group_right' => $args['input_group_right'], |
|
987 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
988 | - ) ); |
|
989 | - } |
|
990 | - |
|
991 | - } |
|
992 | - |
|
993 | - if ( ! $label_after ) { |
|
994 | - $output .= $help_text; |
|
995 | - } |
|
996 | - |
|
997 | - |
|
998 | - if ( $args['label_type'] == 'horizontal' ) { |
|
999 | - $output = self::wrap( array( |
|
1000 | - 'content' => $output, |
|
1001 | - 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
1002 | - ) ); |
|
1003 | - } |
|
1004 | - |
|
1005 | - if ( ! $label_after ) { |
|
1006 | - $output = $label . $output; |
|
1007 | - } |
|
1008 | - |
|
1009 | - // maybe horizontal label |
|
835 | + // Set hidden input to save empty value for multiselect. |
|
836 | + if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) { |
|
837 | + $output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value=""/>'; |
|
838 | + } |
|
839 | + |
|
840 | + // open/type |
|
841 | + $output .= '<select '; |
|
842 | + |
|
843 | + // style |
|
844 | + if ( $is_select2 && !($args['input_group_left'] || $args['input_group_right'])) { |
|
845 | + $output .= " style='width:100%;' "; |
|
846 | + } |
|
847 | + |
|
848 | + // element require |
|
849 | + if ( ! empty( $args['element_require'] ) ) { |
|
850 | + $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
851 | + $args['class'] .= " aui-conditional-field"; |
|
852 | + } |
|
853 | + |
|
854 | + // class |
|
855 | + $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
856 | + $output .= AUI_Component_Helper::class_attr( 'custom-select ' . $class ); |
|
857 | + |
|
858 | + // name |
|
859 | + if ( ! empty( $args['name'] ) ) { |
|
860 | + $output .= AUI_Component_Helper::name( $args['name'], $args['multiple'] ); |
|
861 | + } |
|
862 | + |
|
863 | + // id |
|
864 | + if ( ! empty( $args['id'] ) ) { |
|
865 | + $output .= AUI_Component_Helper::id( $args['id'] ); |
|
866 | + } |
|
867 | + |
|
868 | + // title |
|
869 | + if ( ! empty( $args['title'] ) ) { |
|
870 | + $output .= AUI_Component_Helper::title( $args['title'] ); |
|
871 | + } |
|
872 | + |
|
873 | + // data-attributes |
|
874 | + $output .= AUI_Component_Helper::data_attributes( $args ); |
|
875 | + |
|
876 | + // aria-attributes |
|
877 | + $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
878 | + |
|
879 | + // extra attributes |
|
880 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
881 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
882 | + } |
|
883 | + |
|
884 | + // required |
|
885 | + if ( ! empty( $args['required'] ) ) { |
|
886 | + $output .= ' required '; |
|
887 | + } |
|
888 | + |
|
889 | + // multiple |
|
890 | + if ( ! empty( $args['multiple'] ) ) { |
|
891 | + $output .= ' multiple '; |
|
892 | + } |
|
893 | + |
|
894 | + // close opening tag |
|
895 | + $output .= ' >'; |
|
896 | + |
|
897 | + // placeholder |
|
898 | + if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] && ! $is_select2 ) { |
|
899 | + $output .= '<option value="" disabled selected hidden>' . esc_attr( $args['placeholder'] ) . '</option>'; |
|
900 | + } elseif ( $is_select2 && ! empty( $args['placeholder'] ) ) { |
|
901 | + $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
|
902 | + } |
|
903 | + |
|
904 | + // Options |
|
905 | + if ( ! empty( $args['options'] ) ) { |
|
906 | + |
|
907 | + if ( ! is_array( $args['options'] ) ) { |
|
908 | + $output .= $args['options']; // not the preferred way but an option |
|
909 | + } else { |
|
910 | + foreach ( $args['options'] as $val => $name ) { |
|
911 | + $selected = ''; |
|
912 | + if ( is_array( $name ) ) { |
|
913 | + if ( isset( $name['optgroup'] ) && ( $name['optgroup'] == 'start' || $name['optgroup'] == 'end' ) ) { |
|
914 | + $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
915 | + |
|
916 | + $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>'; |
|
917 | + } else { |
|
918 | + $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
919 | + $option_value = isset( $name['value'] ) ? $name['value'] : ''; |
|
920 | + $extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes( $name['extra_attributes'] ) : ''; |
|
921 | + if ( ! empty( $args['multiple'] ) && ! empty( $args['value'] ) && is_array( $args['value'] ) ) { |
|
922 | + $selected = in_array( $option_value, stripslashes_deep( $args['value'] ) ) ? "selected" : ""; |
|
923 | + } elseif ( ! empty( $args['value'] ) ) { |
|
924 | + $selected = selected( $option_value, stripslashes_deep( $args['value'] ), false ); |
|
925 | + } elseif ( empty( $args['value'] ) && $args['value'] === $option_value ) { |
|
926 | + $selected = selected( $option_value, $args['value'], false ); |
|
927 | + } |
|
928 | + |
|
929 | + $output .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . ' '.$extra_attributes .'>' . $option_label . '</option>'; |
|
930 | + } |
|
931 | + } else { |
|
932 | + if ( ! empty( $args['value'] ) ) { |
|
933 | + if ( is_array( $args['value'] ) ) { |
|
934 | + $selected = in_array( $val, $args['value'] ) ? 'selected="selected"' : ''; |
|
935 | + } elseif ( ! empty( $args['value'] ) ) { |
|
936 | + $selected = selected( $args['value'], $val, false ); |
|
937 | + } |
|
938 | + } elseif ( $args['value'] === $val ) { |
|
939 | + $selected = selected( $args['value'], $val, false ); |
|
940 | + } |
|
941 | + $output .= '<option value="' . esc_attr( $val ) . '" ' . $selected . '>' . esc_attr( $name ) . '</option>'; |
|
942 | + } |
|
943 | + } |
|
944 | + } |
|
945 | + |
|
946 | + } |
|
947 | + |
|
948 | + // closing tag |
|
949 | + $output .= '</select>'; |
|
950 | + |
|
951 | + $label = ''; |
|
952 | + $help_text = ''; |
|
953 | + // label |
|
954 | + if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
955 | + } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
956 | + $label_args = array( |
|
957 | + 'title' => $args['label'], |
|
958 | + 'for' => $args['id'], |
|
959 | + 'class' => $args['label_class'] . " ", |
|
960 | + 'label_type' => $args['label_type'], |
|
961 | + 'label_col' => $args['label_col'] |
|
962 | + ); |
|
963 | + $label = self::label( $label_args ); |
|
964 | + } |
|
965 | + |
|
966 | + // help text |
|
967 | + if ( ! empty( $args['help_text'] ) ) { |
|
968 | + $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
969 | + } |
|
970 | + |
|
971 | + // input group wraps |
|
972 | + if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
973 | + $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
974 | + if ( $args['input_group_left'] ) { |
|
975 | + $output = self::wrap( array( |
|
976 | + 'content' => $output, |
|
977 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
978 | + 'input_group_left' => $args['input_group_left'], |
|
979 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
980 | + ) ); |
|
981 | + } |
|
982 | + if ( $args['input_group_right'] ) { |
|
983 | + $output = self::wrap( array( |
|
984 | + 'content' => $output, |
|
985 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
986 | + 'input_group_right' => $args['input_group_right'], |
|
987 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
988 | + ) ); |
|
989 | + } |
|
990 | + |
|
991 | + } |
|
992 | + |
|
993 | + if ( ! $label_after ) { |
|
994 | + $output .= $help_text; |
|
995 | + } |
|
996 | + |
|
997 | + |
|
998 | + if ( $args['label_type'] == 'horizontal' ) { |
|
999 | + $output = self::wrap( array( |
|
1000 | + 'content' => $output, |
|
1001 | + 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
1002 | + ) ); |
|
1003 | + } |
|
1004 | + |
|
1005 | + if ( ! $label_after ) { |
|
1006 | + $output = $label . $output; |
|
1007 | + } |
|
1008 | + |
|
1009 | + // maybe horizontal label |
|
1010 | 1010 | // if ( $args['label_type'] == 'horizontal' ) { |
1011 | 1011 | // $output .= '</div>'; |
1012 | 1012 | // } |
1013 | 1013 | |
1014 | 1014 | |
1015 | - // wrap |
|
1016 | - if ( ! $args['no_wrap'] ) { |
|
1017 | - $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group'; |
|
1018 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1019 | - $output = self::wrap( array( |
|
1020 | - 'content' => $output, |
|
1021 | - 'class' => $wrap_class, |
|
1022 | - 'element_require' => $args['element_require'], |
|
1023 | - 'argument_id' => $args['id'], |
|
1024 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
1025 | - ) ); |
|
1026 | - } |
|
1027 | - |
|
1028 | - |
|
1029 | - return $output; |
|
1030 | - } |
|
1031 | - |
|
1032 | - /** |
|
1033 | - * Build the component. |
|
1034 | - * |
|
1035 | - * @param array $args |
|
1036 | - * |
|
1037 | - * @return string The rendered component. |
|
1038 | - */ |
|
1039 | - public static function radio( $args = array() ) { |
|
1040 | - $defaults = array( |
|
1041 | - 'class' => '', |
|
1042 | - 'wrap_class' => '', |
|
1043 | - 'id' => '', |
|
1044 | - 'title' => '', |
|
1045 | - 'horizontal' => false, |
|
1046 | - // sets the lable horizontal |
|
1047 | - 'value' => '', |
|
1048 | - 'label' => '', |
|
1049 | - 'label_class' => '', |
|
1050 | - 'label_type' => '', |
|
1051 | - 'label_col' => '', |
|
1052 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
1053 | - 'help_text' => '', |
|
1054 | - 'inline' => true, |
|
1055 | - 'required' => false, |
|
1056 | - 'options' => array(), |
|
1057 | - 'icon' => '', |
|
1058 | - 'no_wrap' => false, |
|
1059 | - 'element_require' => '', |
|
1060 | - // [%element_id%] == "1" |
|
1061 | - 'extra_attributes' => array(), |
|
1062 | - // an array of extra attributes |
|
1063 | - 'wrap_attributes' => array() |
|
1064 | - ); |
|
1065 | - |
|
1066 | - /** |
|
1067 | - * Parse incoming $args into an array and merge it with $defaults |
|
1068 | - */ |
|
1069 | - $args = wp_parse_args( $args, $defaults ); |
|
1070 | - |
|
1071 | - // for now lets use horizontal for floating |
|
1072 | - if ( $args['label_type'] == 'floating' ) { |
|
1073 | - $args['label_type'] = 'horizontal'; |
|
1074 | - } |
|
1075 | - |
|
1076 | - $label_args = array( |
|
1077 | - 'title' => $args['label'], |
|
1078 | - 'class' => $args['label_class'] . " pt-0 ", |
|
1079 | - 'label_type' => $args['label_type'], |
|
1080 | - 'label_col' => $args['label_col'] |
|
1081 | - ); |
|
1082 | - |
|
1083 | - $output = ''; |
|
1084 | - |
|
1085 | - |
|
1086 | - // label before |
|
1087 | - if ( ! empty( $args['label'] ) ) { |
|
1088 | - $output .= self::label( $label_args, 'radio' ); |
|
1089 | - } |
|
1090 | - |
|
1091 | - // maybe horizontal label |
|
1092 | - if ( $args['label_type'] == 'horizontal' ) { |
|
1093 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
1094 | - $output .= '<div class="' . $input_col . '">'; |
|
1095 | - } |
|
1096 | - |
|
1097 | - if ( ! empty( $args['options'] ) ) { |
|
1098 | - $count = 0; |
|
1099 | - foreach ( $args['options'] as $value => $label ) { |
|
1100 | - $option_args = $args; |
|
1101 | - $option_args['value'] = $value; |
|
1102 | - $option_args['label'] = $label; |
|
1103 | - $option_args['checked'] = $value == $args['value'] ? true : false; |
|
1104 | - $output .= self::radio_option( $option_args, $count ); |
|
1105 | - $count ++; |
|
1106 | - } |
|
1107 | - } |
|
1108 | - |
|
1109 | - // help text |
|
1110 | - $help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : ''; |
|
1111 | - $output .= $help_text; |
|
1112 | - |
|
1113 | - // maybe horizontal label |
|
1114 | - if ( $args['label_type'] == 'horizontal' ) { |
|
1115 | - $output .= '</div>'; |
|
1116 | - } |
|
1117 | - |
|
1118 | - // wrap |
|
1119 | - $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group'; |
|
1120 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1121 | - $output = self::wrap( array( |
|
1122 | - 'content' => $output, |
|
1123 | - 'class' => $wrap_class, |
|
1124 | - 'element_require' => $args['element_require'], |
|
1125 | - 'argument_id' => $args['id'], |
|
1126 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
1127 | - ) ); |
|
1128 | - |
|
1129 | - |
|
1130 | - return $output; |
|
1131 | - } |
|
1132 | - |
|
1133 | - /** |
|
1134 | - * Build the component. |
|
1135 | - * |
|
1136 | - * @param array $args |
|
1137 | - * |
|
1138 | - * @return string The rendered component. |
|
1139 | - */ |
|
1140 | - public static function radio_option( $args = array(), $count = '' ) { |
|
1141 | - $defaults = array( |
|
1142 | - 'class' => '', |
|
1143 | - 'id' => '', |
|
1144 | - 'title' => '', |
|
1145 | - 'value' => '', |
|
1146 | - 'required' => false, |
|
1147 | - 'inline' => true, |
|
1148 | - 'label' => '', |
|
1149 | - 'options' => array(), |
|
1150 | - 'icon' => '', |
|
1151 | - 'no_wrap' => false, |
|
1152 | - 'extra_attributes' => array() // an array of extra attributes |
|
1153 | - ); |
|
1154 | - |
|
1155 | - /** |
|
1156 | - * Parse incoming $args into an array and merge it with $defaults |
|
1157 | - */ |
|
1158 | - $args = wp_parse_args( $args, $defaults ); |
|
1159 | - |
|
1160 | - $output = ''; |
|
1161 | - |
|
1162 | - // open/type |
|
1163 | - $output .= '<input type="radio"'; |
|
1164 | - |
|
1165 | - // class |
|
1166 | - $output .= ' class="form-check-input" '; |
|
1167 | - |
|
1168 | - // name |
|
1169 | - if ( ! empty( $args['name'] ) ) { |
|
1170 | - $output .= AUI_Component_Helper::name( $args['name'] ); |
|
1171 | - } |
|
1172 | - |
|
1173 | - // id |
|
1174 | - if ( ! empty( $args['id'] ) ) { |
|
1175 | - $output .= AUI_Component_Helper::id( $args['id'] . $count ); |
|
1176 | - } |
|
1177 | - |
|
1178 | - // title |
|
1179 | - if ( ! empty( $args['title'] ) ) { |
|
1180 | - $output .= AUI_Component_Helper::title( $args['title'] ); |
|
1181 | - } |
|
1182 | - |
|
1183 | - // value |
|
1184 | - if ( isset( $args['value'] ) ) { |
|
1185 | - $output .= AUI_Component_Helper::value( $args['value'] ); |
|
1186 | - } |
|
1187 | - |
|
1188 | - // checked, for radio and checkboxes |
|
1189 | - if ( $args['checked'] ) { |
|
1190 | - $output .= ' checked '; |
|
1191 | - } |
|
1192 | - |
|
1193 | - // data-attributes |
|
1194 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
1195 | - |
|
1196 | - // aria-attributes |
|
1197 | - $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
1198 | - |
|
1199 | - // extra attributes |
|
1200 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
1201 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
1202 | - } |
|
1203 | - |
|
1204 | - // required |
|
1205 | - if ( ! empty( $args['required'] ) ) { |
|
1206 | - $output .= ' required '; |
|
1207 | - } |
|
1208 | - |
|
1209 | - // close opening tag |
|
1210 | - $output .= ' >'; |
|
1211 | - |
|
1212 | - // label |
|
1213 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
1214 | - } elseif ( ! empty( $args['label'] ) ) { |
|
1215 | - $output .= self::label( array( |
|
1216 | - 'title' => $args['label'], |
|
1217 | - 'for' => $args['id'] . $count, |
|
1218 | - 'class' => 'form-check-label' |
|
1219 | - ), 'radio' ); |
|
1220 | - } |
|
1221 | - |
|
1222 | - // wrap |
|
1223 | - if ( ! $args['no_wrap'] ) { |
|
1224 | - $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
|
1225 | - |
|
1226 | - // Unique wrap class |
|
1227 | - $uniq_class = 'fwrap'; |
|
1228 | - if ( ! empty( $args['name'] ) ) { |
|
1229 | - $uniq_class .= '-' . $args['name']; |
|
1230 | - } else if ( ! empty( $args['id'] ) ) { |
|
1231 | - $uniq_class .= '-' . $args['id']; |
|
1232 | - } |
|
1233 | - |
|
1234 | - if ( isset( $args['value'] ) || $args['value'] !== "" ) { |
|
1235 | - $uniq_class .= '-' . $args['value']; |
|
1236 | - } else { |
|
1237 | - $uniq_class .= '-' . $count; |
|
1238 | - } |
|
1239 | - $wrap_class .= ' ' . sanitize_html_class( $uniq_class ); |
|
1240 | - |
|
1241 | - $output = self::wrap( array( |
|
1242 | - 'content' => $output, |
|
1243 | - 'class' => $wrap_class |
|
1244 | - ) ); |
|
1245 | - } |
|
1246 | - |
|
1247 | - return $output; |
|
1248 | - } |
|
1015 | + // wrap |
|
1016 | + if ( ! $args['no_wrap'] ) { |
|
1017 | + $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group'; |
|
1018 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1019 | + $output = self::wrap( array( |
|
1020 | + 'content' => $output, |
|
1021 | + 'class' => $wrap_class, |
|
1022 | + 'element_require' => $args['element_require'], |
|
1023 | + 'argument_id' => $args['id'], |
|
1024 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
1025 | + ) ); |
|
1026 | + } |
|
1027 | + |
|
1028 | + |
|
1029 | + return $output; |
|
1030 | + } |
|
1031 | + |
|
1032 | + /** |
|
1033 | + * Build the component. |
|
1034 | + * |
|
1035 | + * @param array $args |
|
1036 | + * |
|
1037 | + * @return string The rendered component. |
|
1038 | + */ |
|
1039 | + public static function radio( $args = array() ) { |
|
1040 | + $defaults = array( |
|
1041 | + 'class' => '', |
|
1042 | + 'wrap_class' => '', |
|
1043 | + 'id' => '', |
|
1044 | + 'title' => '', |
|
1045 | + 'horizontal' => false, |
|
1046 | + // sets the lable horizontal |
|
1047 | + 'value' => '', |
|
1048 | + 'label' => '', |
|
1049 | + 'label_class' => '', |
|
1050 | + 'label_type' => '', |
|
1051 | + 'label_col' => '', |
|
1052 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
1053 | + 'help_text' => '', |
|
1054 | + 'inline' => true, |
|
1055 | + 'required' => false, |
|
1056 | + 'options' => array(), |
|
1057 | + 'icon' => '', |
|
1058 | + 'no_wrap' => false, |
|
1059 | + 'element_require' => '', |
|
1060 | + // [%element_id%] == "1" |
|
1061 | + 'extra_attributes' => array(), |
|
1062 | + // an array of extra attributes |
|
1063 | + 'wrap_attributes' => array() |
|
1064 | + ); |
|
1065 | + |
|
1066 | + /** |
|
1067 | + * Parse incoming $args into an array and merge it with $defaults |
|
1068 | + */ |
|
1069 | + $args = wp_parse_args( $args, $defaults ); |
|
1070 | + |
|
1071 | + // for now lets use horizontal for floating |
|
1072 | + if ( $args['label_type'] == 'floating' ) { |
|
1073 | + $args['label_type'] = 'horizontal'; |
|
1074 | + } |
|
1075 | + |
|
1076 | + $label_args = array( |
|
1077 | + 'title' => $args['label'], |
|
1078 | + 'class' => $args['label_class'] . " pt-0 ", |
|
1079 | + 'label_type' => $args['label_type'], |
|
1080 | + 'label_col' => $args['label_col'] |
|
1081 | + ); |
|
1082 | + |
|
1083 | + $output = ''; |
|
1084 | + |
|
1085 | + |
|
1086 | + // label before |
|
1087 | + if ( ! empty( $args['label'] ) ) { |
|
1088 | + $output .= self::label( $label_args, 'radio' ); |
|
1089 | + } |
|
1090 | + |
|
1091 | + // maybe horizontal label |
|
1092 | + if ( $args['label_type'] == 'horizontal' ) { |
|
1093 | + $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
1094 | + $output .= '<div class="' . $input_col . '">'; |
|
1095 | + } |
|
1096 | + |
|
1097 | + if ( ! empty( $args['options'] ) ) { |
|
1098 | + $count = 0; |
|
1099 | + foreach ( $args['options'] as $value => $label ) { |
|
1100 | + $option_args = $args; |
|
1101 | + $option_args['value'] = $value; |
|
1102 | + $option_args['label'] = $label; |
|
1103 | + $option_args['checked'] = $value == $args['value'] ? true : false; |
|
1104 | + $output .= self::radio_option( $option_args, $count ); |
|
1105 | + $count ++; |
|
1106 | + } |
|
1107 | + } |
|
1108 | + |
|
1109 | + // help text |
|
1110 | + $help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : ''; |
|
1111 | + $output .= $help_text; |
|
1112 | + |
|
1113 | + // maybe horizontal label |
|
1114 | + if ( $args['label_type'] == 'horizontal' ) { |
|
1115 | + $output .= '</div>'; |
|
1116 | + } |
|
1117 | + |
|
1118 | + // wrap |
|
1119 | + $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group'; |
|
1120 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1121 | + $output = self::wrap( array( |
|
1122 | + 'content' => $output, |
|
1123 | + 'class' => $wrap_class, |
|
1124 | + 'element_require' => $args['element_require'], |
|
1125 | + 'argument_id' => $args['id'], |
|
1126 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
1127 | + ) ); |
|
1128 | + |
|
1129 | + |
|
1130 | + return $output; |
|
1131 | + } |
|
1132 | + |
|
1133 | + /** |
|
1134 | + * Build the component. |
|
1135 | + * |
|
1136 | + * @param array $args |
|
1137 | + * |
|
1138 | + * @return string The rendered component. |
|
1139 | + */ |
|
1140 | + public static function radio_option( $args = array(), $count = '' ) { |
|
1141 | + $defaults = array( |
|
1142 | + 'class' => '', |
|
1143 | + 'id' => '', |
|
1144 | + 'title' => '', |
|
1145 | + 'value' => '', |
|
1146 | + 'required' => false, |
|
1147 | + 'inline' => true, |
|
1148 | + 'label' => '', |
|
1149 | + 'options' => array(), |
|
1150 | + 'icon' => '', |
|
1151 | + 'no_wrap' => false, |
|
1152 | + 'extra_attributes' => array() // an array of extra attributes |
|
1153 | + ); |
|
1154 | + |
|
1155 | + /** |
|
1156 | + * Parse incoming $args into an array and merge it with $defaults |
|
1157 | + */ |
|
1158 | + $args = wp_parse_args( $args, $defaults ); |
|
1159 | + |
|
1160 | + $output = ''; |
|
1161 | + |
|
1162 | + // open/type |
|
1163 | + $output .= '<input type="radio"'; |
|
1164 | + |
|
1165 | + // class |
|
1166 | + $output .= ' class="form-check-input" '; |
|
1167 | + |
|
1168 | + // name |
|
1169 | + if ( ! empty( $args['name'] ) ) { |
|
1170 | + $output .= AUI_Component_Helper::name( $args['name'] ); |
|
1171 | + } |
|
1172 | + |
|
1173 | + // id |
|
1174 | + if ( ! empty( $args['id'] ) ) { |
|
1175 | + $output .= AUI_Component_Helper::id( $args['id'] . $count ); |
|
1176 | + } |
|
1177 | + |
|
1178 | + // title |
|
1179 | + if ( ! empty( $args['title'] ) ) { |
|
1180 | + $output .= AUI_Component_Helper::title( $args['title'] ); |
|
1181 | + } |
|
1182 | + |
|
1183 | + // value |
|
1184 | + if ( isset( $args['value'] ) ) { |
|
1185 | + $output .= AUI_Component_Helper::value( $args['value'] ); |
|
1186 | + } |
|
1187 | + |
|
1188 | + // checked, for radio and checkboxes |
|
1189 | + if ( $args['checked'] ) { |
|
1190 | + $output .= ' checked '; |
|
1191 | + } |
|
1192 | + |
|
1193 | + // data-attributes |
|
1194 | + $output .= AUI_Component_Helper::data_attributes( $args ); |
|
1195 | + |
|
1196 | + // aria-attributes |
|
1197 | + $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
1198 | + |
|
1199 | + // extra attributes |
|
1200 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
1201 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
1202 | + } |
|
1203 | + |
|
1204 | + // required |
|
1205 | + if ( ! empty( $args['required'] ) ) { |
|
1206 | + $output .= ' required '; |
|
1207 | + } |
|
1208 | + |
|
1209 | + // close opening tag |
|
1210 | + $output .= ' >'; |
|
1211 | + |
|
1212 | + // label |
|
1213 | + if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
1214 | + } elseif ( ! empty( $args['label'] ) ) { |
|
1215 | + $output .= self::label( array( |
|
1216 | + 'title' => $args['label'], |
|
1217 | + 'for' => $args['id'] . $count, |
|
1218 | + 'class' => 'form-check-label' |
|
1219 | + ), 'radio' ); |
|
1220 | + } |
|
1221 | + |
|
1222 | + // wrap |
|
1223 | + if ( ! $args['no_wrap'] ) { |
|
1224 | + $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
|
1225 | + |
|
1226 | + // Unique wrap class |
|
1227 | + $uniq_class = 'fwrap'; |
|
1228 | + if ( ! empty( $args['name'] ) ) { |
|
1229 | + $uniq_class .= '-' . $args['name']; |
|
1230 | + } else if ( ! empty( $args['id'] ) ) { |
|
1231 | + $uniq_class .= '-' . $args['id']; |
|
1232 | + } |
|
1233 | + |
|
1234 | + if ( isset( $args['value'] ) || $args['value'] !== "" ) { |
|
1235 | + $uniq_class .= '-' . $args['value']; |
|
1236 | + } else { |
|
1237 | + $uniq_class .= '-' . $count; |
|
1238 | + } |
|
1239 | + $wrap_class .= ' ' . sanitize_html_class( $uniq_class ); |
|
1240 | + |
|
1241 | + $output = self::wrap( array( |
|
1242 | + 'content' => $output, |
|
1243 | + 'class' => $wrap_class |
|
1244 | + ) ); |
|
1245 | + } |
|
1246 | + |
|
1247 | + return $output; |
|
1248 | + } |
|
1249 | 1249 | |
1250 | 1250 | } |
1251 | 1251 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
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 |
||
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' => '', |
@@ -65,13 +65,13 @@ discard block |
||
65 | 65 | /** |
66 | 66 | * Parse incoming $args into an array and merge it with $defaults |
67 | 67 | */ |
68 | - $args = wp_parse_args( $args, $defaults ); |
|
68 | + $args = wp_parse_args($args, $defaults); |
|
69 | 69 | $output = ''; |
70 | - if ( ! empty( $args['type'] ) ) { |
|
70 | + if (!empty($args['type'])) { |
|
71 | 71 | // hidden label option needs to be empty |
72 | 72 | $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
73 | 73 | |
74 | - $type = sanitize_html_class( $args['type'] ); |
|
74 | + $type = sanitize_html_class($args['type']); |
|
75 | 75 | |
76 | 76 | $help_text = ''; |
77 | 77 | $label = ''; |
@@ -85,17 +85,17 @@ discard block |
||
85 | 85 | ); |
86 | 86 | |
87 | 87 | // floating labels need label after |
88 | - if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) { |
|
88 | + if ($args['label_type'] == 'floating' && $type != 'checkbox') { |
|
89 | 89 | $label_after = true; |
90 | 90 | $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
91 | 91 | } |
92 | 92 | |
93 | 93 | // size |
94 | 94 | $size = ''; |
95 | - if ( $args['size'] == 'lg' || $args['size'] == 'large' ) { |
|
95 | + if ($args['size'] == 'lg' || $args['size'] == 'large') { |
|
96 | 96 | $size = 'lg'; |
97 | 97 | $args['class'] .= ' form-control-lg'; |
98 | - }elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) { |
|
98 | + }elseif ($args['size'] == 'sm' || $args['size'] == 'small') { |
|
99 | 99 | $size = 'sm'; |
100 | 100 | $args['class'] .= ' form-control-sm'; |
101 | 101 | } |
@@ -104,20 +104,20 @@ discard block |
||
104 | 104 | $clear_function = 'jQuery(this).parent().parent().find(\'input\').val(\'\');'; |
105 | 105 | |
106 | 106 | // Some special sauce for files |
107 | - if ( $type == 'file' ) { |
|
107 | + if ($type == 'file') { |
|
108 | 108 | $label_after = true; // if type file we need the label after |
109 | 109 | $args['class'] .= ' custom-file-input '; |
110 | - } elseif ( $type == 'checkbox' ) { |
|
110 | + } elseif ($type == 'checkbox') { |
|
111 | 111 | $label_after = true; // if type file we need the label after |
112 | 112 | $args['class'] .= ' custom-control-input '; |
113 | - } elseif ( $type == 'datepicker' || $type == 'timepicker' ) { |
|
113 | + } elseif ($type == 'datepicker' || $type == 'timepicker') { |
|
114 | 114 | $type = 'text'; |
115 | 115 | $args['class'] .= ' bg-initial '; // @todo not sure why we have this? |
116 | 116 | |
117 | 117 | $args['extra_attributes']['data-aui-init'] = 'flatpickr'; |
118 | 118 | |
119 | 119 | // set a way to clear field if empty |
120 | - if ( $args['input_group_right'] === '' && $args['clear_icon'] !== false ) { |
|
120 | + if ($args['input_group_right'] === '' && $args['clear_icon'] !== false) { |
|
121 | 121 | $args['input_group_right_inside'] = true; |
122 | 122 | $args['clear_icon'] = true; |
123 | 123 | } |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | // enqueue the script |
126 | 126 | $aui_settings = AyeCode_UI_Settings::instance(); |
127 | 127 | $aui_settings->enqueue_flatpickr(); |
128 | - } elseif ( $type == 'iconpicker' ) { |
|
128 | + } elseif ($type == 'iconpicker') { |
|
129 | 129 | $type = 'text'; |
130 | 130 | //$args['class'] .= ' aui-flatpickr bg-initial '; |
131 | 131 | // $args['class'] .= ' bg-initial '; |
@@ -140,103 +140,103 @@ discard block |
||
140 | 140 | $aui_settings->enqueue_iconpicker(); |
141 | 141 | } |
142 | 142 | |
143 | - if ( $type == 'checkbox' && !empty($args['name'] ) && strpos($args['name'], '[') === false ) { |
|
144 | - $output .= '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />'; |
|
143 | + if ($type == 'checkbox' && !empty($args['name']) && strpos($args['name'], '[') === false) { |
|
144 | + $output .= '<input type="hidden" name="' . esc_attr($args['name']) . '" value="0" />'; |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | // allow clear icon |
148 | - if ( $args['input_group_right'] === '' && $args['clear_icon'] ) { |
|
149 | - $font_size = $size == 'sm' ? '1.3' : ( $size == 'lg' ? '1.65' : '1.5' ); |
|
148 | + if ($args['input_group_right'] === '' && $args['clear_icon']) { |
|
149 | + $font_size = $size == 'sm' ? '1.3' : ($size == 'lg' ? '1.65' : '1.5'); |
|
150 | 150 | $args['input_group_right_inside'] = true; |
151 | - $args['input_group_right'] = '<span class="input-group-text aui-clear-input c-pointer bg-initial border-0 px-2 d-none" onclick="' . $clear_function . '"><span style="font-size: '.$font_size.'rem" aria-hidden="true" class="close">×</span></span>'; |
|
151 | + $args['input_group_right'] = '<span class="input-group-text aui-clear-input c-pointer bg-initial border-0 px-2 d-none" onclick="' . $clear_function . '"><span style="font-size: ' . $font_size . 'rem" aria-hidden="true" class="close">×</span></span>'; |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | // open/type |
155 | 155 | $output .= '<input type="' . $type . '" '; |
156 | 156 | |
157 | 157 | // name |
158 | - if ( ! empty( $args['name'] ) ) { |
|
159 | - $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
158 | + if (!empty($args['name'])) { |
|
159 | + $output .= ' name="' . esc_attr($args['name']) . '" '; |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | // id |
163 | - if ( ! empty( $args['id'] ) ) { |
|
164 | - $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
163 | + if (!empty($args['id'])) { |
|
164 | + $output .= ' id="' . sanitize_html_class($args['id']) . '" '; |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | // placeholder |
168 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
169 | - $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
168 | + if (isset($args['placeholder']) && '' != $args['placeholder']) { |
|
169 | + $output .= ' placeholder="' . esc_attr($args['placeholder']) . '" '; |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | // title |
173 | - if ( ! empty( $args['title'] ) ) { |
|
174 | - $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
173 | + if (!empty($args['title'])) { |
|
174 | + $output .= ' title="' . esc_attr($args['title']) . '" '; |
|
175 | 175 | } |
176 | 176 | |
177 | 177 | // value |
178 | - if ( ! empty( $args['value'] ) ) { |
|
179 | - $output .= AUI_Component_Helper::value( $args['value'] ); |
|
178 | + if (!empty($args['value'])) { |
|
179 | + $output .= AUI_Component_Helper::value($args['value']); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | // checked, for radio and checkboxes |
183 | - if ( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ) { |
|
183 | + if (($type == 'checkbox' || $type == 'radio') && $args['checked']) { |
|
184 | 184 | $output .= ' checked '; |
185 | 185 | } |
186 | 186 | |
187 | 187 | // validation text |
188 | - if ( ! empty( $args['validation_text'] ) ) { |
|
189 | - $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
188 | + if (!empty($args['validation_text'])) { |
|
189 | + $output .= ' oninvalid="setCustomValidity(\'' . esc_attr($args['validation_text']) . '\')" '; |
|
190 | 190 | $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
191 | 191 | } |
192 | 192 | |
193 | 193 | // validation_pattern |
194 | - if ( ! empty( $args['validation_pattern'] ) ) { |
|
195 | - $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
194 | + if (!empty($args['validation_pattern'])) { |
|
195 | + $output .= ' pattern="' . esc_attr($args['validation_pattern']) . '" '; |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | // step (for numbers) |
199 | - if ( ! empty( $args['step'] ) ) { |
|
199 | + if (!empty($args['step'])) { |
|
200 | 200 | $output .= ' step="' . $args['step'] . '" '; |
201 | 201 | } |
202 | 202 | |
203 | 203 | // required |
204 | - if ( ! empty( $args['required'] ) ) { |
|
204 | + if (!empty($args['required'])) { |
|
205 | 205 | $output .= ' required '; |
206 | 206 | } |
207 | 207 | |
208 | 208 | // class |
209 | - $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
209 | + $class = !empty($args['class']) ? AUI_Component_Helper::esc_classes($args['class']) : ''; |
|
210 | 210 | $output .= ' class="form-control ' . $class . '" '; |
211 | 211 | |
212 | 212 | // data-attributes |
213 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
213 | + $output .= AUI_Component_Helper::data_attributes($args); |
|
214 | 214 | |
215 | 215 | // extra attributes |
216 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
217 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
216 | + if (!empty($args['extra_attributes'])) { |
|
217 | + $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | // close |
221 | 221 | $output .= ' >'; |
222 | 222 | |
223 | 223 | // help text |
224 | - if ( ! empty( $args['help_text'] ) ) { |
|
225 | - $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
224 | + if (!empty($args['help_text'])) { |
|
225 | + $help_text = AUI_Component_Helper::help_text($args['help_text']); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | // label |
229 | - if ( ! empty( $args['label'] ) ) { |
|
229 | + if (!empty($args['label'])) { |
|
230 | 230 | $label_base_class = ''; |
231 | - if ( $type == 'file' ) { |
|
231 | + if ($type == 'file') { |
|
232 | 232 | $label_base_class = ' custom-file-label'; |
233 | - } elseif ( $type == 'checkbox' ) { |
|
234 | - if ( ! empty( $args['label_force_left'] ) ) { |
|
235 | - $label_args['title'] = wp_kses_post( $args['help_text'] ); |
|
233 | + } elseif ($type == 'checkbox') { |
|
234 | + if (!empty($args['label_force_left'])) { |
|
235 | + $label_args['title'] = wp_kses_post($args['help_text']); |
|
236 | 236 | $help_text = ''; |
237 | 237 | //$label_args['class'] .= ' d-inline '; |
238 | 238 | $args['wrap_class'] .= ' align-items-center '; |
239 | - }else{ |
|
239 | + } else { |
|
240 | 240 | |
241 | 241 | } |
242 | 242 | |
@@ -244,45 +244,45 @@ discard block |
||
244 | 244 | } |
245 | 245 | $label_args['class'] .= $label_base_class; |
246 | 246 | $temp_label_args = $label_args; |
247 | - if(! empty( $args['label_force_left'] )){$temp_label_args['class'] = $label_base_class." text-muted";} |
|
248 | - $label = self::label( $temp_label_args, $type ); |
|
247 | + if (!empty($args['label_force_left'])) {$temp_label_args['class'] = $label_base_class . " text-muted"; } |
|
248 | + $label = self::label($temp_label_args, $type); |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | |
252 | 252 | |
253 | 253 | |
254 | 254 | // set help text in the correct position |
255 | - if ( $label_after ) { |
|
255 | + if ($label_after) { |
|
256 | 256 | $output .= $label . $help_text; |
257 | 257 | } |
258 | 258 | |
259 | 259 | // some input types need a separate wrap |
260 | - if ( $type == 'file' ) { |
|
261 | - $output = self::wrap( array( |
|
260 | + if ($type == 'file') { |
|
261 | + $output = self::wrap(array( |
|
262 | 262 | 'content' => $output, |
263 | 263 | 'class' => 'form-group custom-file' |
264 | - ) ); |
|
265 | - } elseif ( $type == 'checkbox' ) { |
|
264 | + )); |
|
265 | + } elseif ($type == 'checkbox') { |
|
266 | 266 | |
267 | 267 | $label_args['title'] = $args['label']; |
268 | - $label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ); |
|
269 | - $label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '<div class="' . $label_col . ' col-form-label"></div>'; |
|
270 | - $switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : ''; |
|
271 | - $wrap_class = $args['switch'] ? 'custom-switch'.$switch_size_class : 'custom-checkbox'; |
|
272 | - if ( ! empty( $args['label_force_left'] ) ) { |
|
268 | + $label_col = AUI_Component_Helper::get_column_class($args['label_col'], 'label'); |
|
269 | + $label = !empty($args['label_force_left']) ? self::label($label_args, 'cb') : '<div class="' . $label_col . ' col-form-label"></div>'; |
|
270 | + $switch_size_class = $args['switch'] && !is_bool($args['switch']) ? ' custom-switch-' . esc_attr($args['switch']) : ''; |
|
271 | + $wrap_class = $args['switch'] ? 'custom-switch' . $switch_size_class : 'custom-checkbox'; |
|
272 | + if (!empty($args['label_force_left'])) { |
|
273 | 273 | $wrap_class .= ' d-flex align-content-center'; |
274 | - $label = str_replace("custom-control-label","", self::label( $label_args, 'cb' ) ); |
|
274 | + $label = str_replace("custom-control-label", "", self::label($label_args, 'cb')); |
|
275 | 275 | } |
276 | - $output = self::wrap( array( |
|
276 | + $output = self::wrap(array( |
|
277 | 277 | 'content' => $output, |
278 | 278 | 'class' => 'custom-control ' . $wrap_class |
279 | - ) ); |
|
279 | + )); |
|
280 | 280 | |
281 | - if ( $args['label_type'] == 'horizontal' ) { |
|
282 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
281 | + if ($args['label_type'] == 'horizontal') { |
|
282 | + $input_col = AUI_Component_Helper::get_column_class($args['label_col'], 'input'); |
|
283 | 283 | $output = $label . '<div class="' . $input_col . '">' . $output . '</div>'; |
284 | 284 | } |
285 | - } elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) { |
|
285 | + } elseif ($type == 'password' && $args['password_toggle'] && !$args['input_group_right']) { |
|
286 | 286 | |
287 | 287 | |
288 | 288 | // allow password field to toggle view |
@@ -296,65 +296,65 @@ discard block |
||
296 | 296 | } |
297 | 297 | |
298 | 298 | // input group wraps |
299 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
300 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
299 | + if ($args['input_group_left'] || $args['input_group_right']) { |
|
300 | + $w100 = strpos($args['class'], 'w-100') !== false ? ' w-100' : ''; |
|
301 | 301 | $group_size = $size == 'lg' ? ' input-group-lg' : ''; |
302 | 302 | $group_size = !$group_size && $size == 'sm' ? ' input-group-sm' : $group_size; |
303 | 303 | |
304 | - if ( $args['input_group_left'] ) { |
|
305 | - $output = self::wrap( array( |
|
304 | + if ($args['input_group_left']) { |
|
305 | + $output = self::wrap(array( |
|
306 | 306 | 'content' => $output, |
307 | 307 | 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
308 | 308 | 'input_group_left' => $args['input_group_left'], |
309 | 309 | 'input_group_left_inside' => $args['input_group_left_inside'] |
310 | - ) ); |
|
310 | + )); |
|
311 | 311 | } |
312 | - if ( $args['input_group_right'] ) { |
|
313 | - $output = self::wrap( array( |
|
312 | + if ($args['input_group_right']) { |
|
313 | + $output = self::wrap(array( |
|
314 | 314 | 'content' => $output, |
315 | 315 | 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
316 | 316 | 'input_group_right' => $args['input_group_right'], |
317 | 317 | 'input_group_right_inside' => $args['input_group_right_inside'] |
318 | - ) ); |
|
318 | + )); |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | } |
322 | 322 | |
323 | - if ( ! $label_after ) { |
|
323 | + if (!$label_after) { |
|
324 | 324 | $output .= $help_text; |
325 | 325 | } |
326 | 326 | |
327 | 327 | |
328 | - if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
329 | - $output = self::wrap( array( |
|
328 | + if ($args['label_type'] == 'horizontal' && $type != 'checkbox') { |
|
329 | + $output = self::wrap(array( |
|
330 | 330 | 'content' => $output, |
331 | - 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
332 | - ) ); |
|
331 | + 'class' => AUI_Component_Helper::get_column_class($args['label_col'], 'input') |
|
332 | + )); |
|
333 | 333 | } |
334 | 334 | |
335 | - if ( ! $label_after ) { |
|
335 | + if (!$label_after) { |
|
336 | 336 | $output = $label . $output; |
337 | 337 | } |
338 | 338 | |
339 | 339 | // wrap |
340 | - if ( ! $args['no_wrap'] ) { |
|
340 | + if (!$args['no_wrap']) { |
|
341 | 341 | $form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group'; |
342 | 342 | $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
343 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
344 | - $output = self::wrap( array( |
|
343 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
344 | + $output = self::wrap(array( |
|
345 | 345 | 'content' => $output, |
346 | 346 | 'class' => $wrap_class, |
347 | 347 | 'element_require' => $args['element_require'], |
348 | 348 | 'argument_id' => $args['id'], |
349 | 349 | 'wrap_attributes' => $args['wrap_attributes'], |
350 | - ) ); |
|
350 | + )); |
|
351 | 351 | } |
352 | 352 | } |
353 | 353 | |
354 | 354 | return $output; |
355 | 355 | } |
356 | 356 | |
357 | - public static function label( $args = array(), $type = '' ) { |
|
357 | + public static function label($args = array(), $type = '') { |
|
358 | 358 | //<label for="exampleInputEmail1">Email address</label> |
359 | 359 | $defaults = array( |
360 | 360 | 'title' => 'div', |
@@ -367,33 +367,33 @@ discard block |
||
367 | 367 | /** |
368 | 368 | * Parse incoming $args into an array and merge it with $defaults |
369 | 369 | */ |
370 | - $args = wp_parse_args( $args, $defaults ); |
|
370 | + $args = wp_parse_args($args, $defaults); |
|
371 | 371 | $output = ''; |
372 | 372 | |
373 | - if ( $args['title'] ) { |
|
373 | + if ($args['title']) { |
|
374 | 374 | |
375 | 375 | // maybe hide labels //@todo set a global option for visibility class |
376 | - if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) { |
|
376 | + if ($type == 'file' || $type == 'checkbox' || $type == 'radio' || !empty($args['label_type'])) { |
|
377 | 377 | $class = $args['class']; |
378 | 378 | } else { |
379 | 379 | $class = 'sr-only ' . $args['class']; |
380 | 380 | } |
381 | 381 | |
382 | 382 | // maybe horizontal |
383 | - if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
384 | - $class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label'; |
|
383 | + if ($args['label_type'] == 'horizontal' && $type != 'checkbox') { |
|
384 | + $class .= ' ' . AUI_Component_Helper::get_column_class($args['label_col'], 'label') . ' col-form-label'; |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | // open |
388 | 388 | $output .= '<label '; |
389 | 389 | |
390 | 390 | // for |
391 | - if ( ! empty( $args['for'] ) ) { |
|
392 | - $output .= ' for="' . esc_attr( $args['for'] ) . '" '; |
|
391 | + if (!empty($args['for'])) { |
|
392 | + $output .= ' for="' . esc_attr($args['for']) . '" '; |
|
393 | 393 | } |
394 | 394 | |
395 | 395 | // class |
396 | - $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
396 | + $class = $class ? AUI_Component_Helper::esc_classes($class) : ''; |
|
397 | 397 | $output .= ' class="' . $class . '" '; |
398 | 398 | |
399 | 399 | // close |
@@ -401,8 +401,8 @@ discard block |
||
401 | 401 | |
402 | 402 | |
403 | 403 | // title, don't escape fully as can contain html |
404 | - if ( ! empty( $args['title'] ) ) { |
|
405 | - $output .= wp_kses_post( $args['title'] ); |
|
404 | + if (!empty($args['title'])) { |
|
405 | + $output .= wp_kses_post($args['title']); |
|
406 | 406 | } |
407 | 407 | |
408 | 408 | // close wrap |
@@ -422,7 +422,7 @@ discard block |
||
422 | 422 | * |
423 | 423 | * @return string |
424 | 424 | */ |
425 | - public static function wrap( $args = array() ) { |
|
425 | + public static function wrap($args = array()) { |
|
426 | 426 | $defaults = array( |
427 | 427 | 'type' => 'div', |
428 | 428 | 'class' => 'form-group', |
@@ -439,31 +439,31 @@ discard block |
||
439 | 439 | /** |
440 | 440 | * Parse incoming $args into an array and merge it with $defaults |
441 | 441 | */ |
442 | - $args = wp_parse_args( $args, $defaults ); |
|
442 | + $args = wp_parse_args($args, $defaults); |
|
443 | 443 | $output = ''; |
444 | - if ( $args['type'] ) { |
|
444 | + if ($args['type']) { |
|
445 | 445 | |
446 | 446 | // open |
447 | - $output .= '<' . sanitize_html_class( $args['type'] ); |
|
447 | + $output .= '<' . sanitize_html_class($args['type']); |
|
448 | 448 | |
449 | 449 | // element require |
450 | - if ( ! empty( $args['element_require'] ) ) { |
|
451 | - $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
450 | + if (!empty($args['element_require'])) { |
|
451 | + $output .= AUI_Component_Helper::element_require($args['element_require']); |
|
452 | 452 | $args['class'] .= " aui-conditional-field"; |
453 | 453 | } |
454 | 454 | |
455 | 455 | // argument_id |
456 | - if ( ! empty( $args['argument_id'] ) ) { |
|
457 | - $output .= ' data-argument="' . esc_attr( $args['argument_id'] ) . '"'; |
|
456 | + if (!empty($args['argument_id'])) { |
|
457 | + $output .= ' data-argument="' . esc_attr($args['argument_id']) . '"'; |
|
458 | 458 | } |
459 | 459 | |
460 | 460 | // class |
461 | - $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
461 | + $class = !empty($args['class']) ? AUI_Component_Helper::esc_classes($args['class']) : ''; |
|
462 | 462 | $output .= ' class="' . $class . '" '; |
463 | 463 | |
464 | 464 | // Attributes |
465 | - if ( ! empty( $args['wrap_attributes'] ) ) { |
|
466 | - $output .= AUI_Component_Helper::extra_attributes( $args['wrap_attributes'] ); |
|
465 | + if (!empty($args['wrap_attributes'])) { |
|
466 | + $output .= AUI_Component_Helper::extra_attributes($args['wrap_attributes']); |
|
467 | 467 | } |
468 | 468 | |
469 | 469 | // close wrap |
@@ -471,9 +471,9 @@ discard block |
||
471 | 471 | |
472 | 472 | |
473 | 473 | // Input group left |
474 | - if ( ! empty( $args['input_group_left'] ) ) { |
|
475 | - $position_class = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : ''; |
|
476 | - $input_group_left = strpos( $args['input_group_left'], '<' ) !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>'; |
|
474 | + if (!empty($args['input_group_left'])) { |
|
475 | + $position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : ''; |
|
476 | + $input_group_left = strpos($args['input_group_left'], '<') !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>'; |
|
477 | 477 | $output .= '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>'; |
478 | 478 | } |
479 | 479 | |
@@ -481,15 +481,15 @@ discard block |
||
481 | 481 | $output .= $args['content']; |
482 | 482 | |
483 | 483 | // Input group right |
484 | - if ( ! empty( $args['input_group_right'] ) ) { |
|
485 | - $position_class = ! empty( $args['input_group_right_inside'] ) ? 'position-absolute h-100' : ''; |
|
486 | - $input_group_right = strpos( $args['input_group_right'], '<' ) !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>'; |
|
484 | + if (!empty($args['input_group_right'])) { |
|
485 | + $position_class = !empty($args['input_group_right_inside']) ? 'position-absolute h-100' : ''; |
|
486 | + $input_group_right = strpos($args['input_group_right'], '<') !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>'; |
|
487 | 487 | $output .= '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>'; |
488 | 488 | } |
489 | 489 | |
490 | 490 | |
491 | 491 | // close wrap |
492 | - $output .= '</' . sanitize_html_class( $args['type'] ) . '>'; |
|
492 | + $output .= '</' . sanitize_html_class($args['type']) . '>'; |
|
493 | 493 | |
494 | 494 | |
495 | 495 | } else { |
@@ -506,7 +506,7 @@ discard block |
||
506 | 506 | * |
507 | 507 | * @return string The rendered component. |
508 | 508 | */ |
509 | - public static function textarea( $args = array() ) { |
|
509 | + public static function textarea($args = array()) { |
|
510 | 510 | $defaults = array( |
511 | 511 | 'name' => '', |
512 | 512 | 'class' => '', |
@@ -543,28 +543,28 @@ discard block |
||
543 | 543 | /** |
544 | 544 | * Parse incoming $args into an array and merge it with $defaults |
545 | 545 | */ |
546 | - $args = wp_parse_args( $args, $defaults ); |
|
546 | + $args = wp_parse_args($args, $defaults); |
|
547 | 547 | $output = ''; |
548 | 548 | |
549 | 549 | // hidden label option needs to be empty |
550 | 550 | $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
551 | 551 | |
552 | 552 | // floating labels don't work with wysiwyg so set it as top |
553 | - if ( $args['label_type'] == 'floating' && ! empty( $args['wysiwyg'] ) ) { |
|
553 | + if ($args['label_type'] == 'floating' && !empty($args['wysiwyg'])) { |
|
554 | 554 | $args['label_type'] = 'top'; |
555 | 555 | } |
556 | 556 | |
557 | 557 | $label_after = $args['label_after']; |
558 | 558 | |
559 | 559 | // floating labels need label after |
560 | - if ( $args['label_type'] == 'floating' && empty( $args['wysiwyg'] ) ) { |
|
560 | + if ($args['label_type'] == 'floating' && empty($args['wysiwyg'])) { |
|
561 | 561 | $label_after = true; |
562 | 562 | $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
563 | 563 | } |
564 | 564 | |
565 | 565 | // label |
566 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
567 | - } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
566 | + if (!empty($args['label']) && is_array($args['label'])) { |
|
567 | + } elseif (!empty($args['label']) && !$label_after) { |
|
568 | 568 | $label_args = array( |
569 | 569 | 'title' => $args['label'], |
570 | 570 | 'for' => $args['id'], |
@@ -572,34 +572,34 @@ discard block |
||
572 | 572 | 'label_type' => $args['label_type'], |
573 | 573 | 'label_col' => $args['label_col'] |
574 | 574 | ); |
575 | - $output .= self::label( $label_args ); |
|
575 | + $output .= self::label($label_args); |
|
576 | 576 | } |
577 | 577 | |
578 | 578 | // maybe horizontal label |
579 | - if ( $args['label_type'] == 'horizontal' ) { |
|
580 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
579 | + if ($args['label_type'] == 'horizontal') { |
|
580 | + $input_col = AUI_Component_Helper::get_column_class($args['label_col'], 'input'); |
|
581 | 581 | $output .= '<div class="' . $input_col . '">'; |
582 | 582 | } |
583 | 583 | |
584 | - if ( ! empty( $args['wysiwyg'] ) ) { |
|
584 | + if (!empty($args['wysiwyg'])) { |
|
585 | 585 | ob_start(); |
586 | 586 | $content = $args['value']; |
587 | - $editor_id = ! empty( $args['id'] ) ? sanitize_html_class( $args['id'] ) : 'wp_editor'; |
|
587 | + $editor_id = !empty($args['id']) ? sanitize_html_class($args['id']) : 'wp_editor'; |
|
588 | 588 | $settings = array( |
589 | - 'textarea_rows' => ! empty( absint( $args['rows'] ) ) ? absint( $args['rows'] ) : 4, |
|
589 | + 'textarea_rows' => !empty(absint($args['rows'])) ? absint($args['rows']) : 4, |
|
590 | 590 | 'quicktags' => false, |
591 | 591 | 'media_buttons' => false, |
592 | 592 | 'editor_class' => 'form-control', |
593 | - 'textarea_name' => ! empty( $args['name'] ) ? sanitize_html_class( $args['name'] ) : sanitize_html_class( $args['id'] ), |
|
593 | + 'textarea_name' => !empty($args['name']) ? sanitize_html_class($args['name']) : sanitize_html_class($args['id']), |
|
594 | 594 | 'teeny' => true, |
595 | 595 | ); |
596 | 596 | |
597 | 597 | // maybe set settings if array |
598 | - if ( is_array( $args['wysiwyg'] ) ) { |
|
599 | - $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
598 | + if (is_array($args['wysiwyg'])) { |
|
599 | + $settings = wp_parse_args($args['wysiwyg'], $settings); |
|
600 | 600 | } |
601 | 601 | |
602 | - wp_editor( $content, $editor_id, $settings ); |
|
602 | + wp_editor($content, $editor_id, $settings); |
|
603 | 603 | $output .= ob_get_clean(); |
604 | 604 | } else { |
605 | 605 | |
@@ -607,65 +607,65 @@ discard block |
||
607 | 607 | $output .= '<textarea '; |
608 | 608 | |
609 | 609 | // name |
610 | - if ( ! empty( $args['name'] ) ) { |
|
611 | - $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
610 | + if (!empty($args['name'])) { |
|
611 | + $output .= ' name="' . esc_attr($args['name']) . '" '; |
|
612 | 612 | } |
613 | 613 | |
614 | 614 | // id |
615 | - if ( ! empty( $args['id'] ) ) { |
|
616 | - $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
615 | + if (!empty($args['id'])) { |
|
616 | + $output .= ' id="' . sanitize_html_class($args['id']) . '" '; |
|
617 | 617 | } |
618 | 618 | |
619 | 619 | // placeholder |
620 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
621 | - $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
620 | + if (isset($args['placeholder']) && '' != $args['placeholder']) { |
|
621 | + $output .= ' placeholder="' . esc_attr($args['placeholder']) . '" '; |
|
622 | 622 | } |
623 | 623 | |
624 | 624 | // title |
625 | - if ( ! empty( $args['title'] ) ) { |
|
626 | - $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
625 | + if (!empty($args['title'])) { |
|
626 | + $output .= ' title="' . esc_attr($args['title']) . '" '; |
|
627 | 627 | } |
628 | 628 | |
629 | 629 | // validation text |
630 | - if ( ! empty( $args['validation_text'] ) ) { |
|
631 | - $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
630 | + if (!empty($args['validation_text'])) { |
|
631 | + $output .= ' oninvalid="setCustomValidity(\'' . esc_attr($args['validation_text']) . '\')" '; |
|
632 | 632 | $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
633 | 633 | } |
634 | 634 | |
635 | 635 | // validation_pattern |
636 | - if ( ! empty( $args['validation_pattern'] ) ) { |
|
637 | - $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
636 | + if (!empty($args['validation_pattern'])) { |
|
637 | + $output .= ' pattern="' . esc_attr($args['validation_pattern']) . '" '; |
|
638 | 638 | } |
639 | 639 | |
640 | 640 | // required |
641 | - if ( ! empty( $args['required'] ) ) { |
|
641 | + if (!empty($args['required'])) { |
|
642 | 642 | $output .= ' required '; |
643 | 643 | } |
644 | 644 | |
645 | 645 | // rows |
646 | - if ( ! empty( $args['rows'] ) ) { |
|
647 | - $output .= ' rows="' . absint( $args['rows'] ) . '" '; |
|
646 | + if (!empty($args['rows'])) { |
|
647 | + $output .= ' rows="' . absint($args['rows']) . '" '; |
|
648 | 648 | } |
649 | 649 | |
650 | 650 | |
651 | 651 | // class |
652 | - $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
652 | + $class = !empty($args['class']) ? $args['class'] : ''; |
|
653 | 653 | $output .= ' class="form-control ' . $class . '" '; |
654 | 654 | |
655 | 655 | // extra attributes |
656 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
657 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
656 | + if (!empty($args['extra_attributes'])) { |
|
657 | + $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
658 | 658 | } |
659 | 659 | |
660 | 660 | // close tag |
661 | 661 | $output .= ' >'; |
662 | 662 | |
663 | 663 | // value |
664 | - if ( ! empty( $args['value'] ) ) { |
|
665 | - if ( ! empty( $args['allow_tags'] ) ) { |
|
666 | - $output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML. |
|
664 | + if (!empty($args['value'])) { |
|
665 | + if (!empty($args['allow_tags'])) { |
|
666 | + $output .= AUI_Component_Helper::sanitize_html_field($args['value'], $args); // Sanitize HTML. |
|
667 | 667 | } else { |
668 | - $output .= AUI_Component_Helper::sanitize_textarea_field( $args['value'] ); |
|
668 | + $output .= AUI_Component_Helper::sanitize_textarea_field($args['value']); |
|
669 | 669 | } |
670 | 670 | } |
671 | 671 | |
@@ -674,23 +674,23 @@ discard block |
||
674 | 674 | |
675 | 675 | |
676 | 676 | // input group wraps |
677 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
678 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
679 | - if ( $args['input_group_left'] ) { |
|
680 | - $output = self::wrap( array( |
|
677 | + if ($args['input_group_left'] || $args['input_group_right']) { |
|
678 | + $w100 = strpos($args['class'], 'w-100') !== false ? ' w-100' : ''; |
|
679 | + if ($args['input_group_left']) { |
|
680 | + $output = self::wrap(array( |
|
681 | 681 | 'content' => $output, |
682 | 682 | 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
683 | 683 | 'input_group_left' => $args['input_group_left'], |
684 | 684 | 'input_group_left_inside' => $args['input_group_left_inside'] |
685 | - ) ); |
|
685 | + )); |
|
686 | 686 | } |
687 | - if ( $args['input_group_right'] ) { |
|
688 | - $output = self::wrap( array( |
|
687 | + if ($args['input_group_right']) { |
|
688 | + $output = self::wrap(array( |
|
689 | 689 | 'content' => $output, |
690 | 690 | 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
691 | 691 | 'input_group_right' => $args['input_group_right'], |
692 | 692 | 'input_group_right_inside' => $args['input_group_right_inside'] |
693 | - ) ); |
|
693 | + )); |
|
694 | 694 | } |
695 | 695 | |
696 | 696 | } |
@@ -698,7 +698,7 @@ discard block |
||
698 | 698 | |
699 | 699 | } |
700 | 700 | |
701 | - if ( ! empty( $args['label'] ) && $label_after ) { |
|
701 | + if (!empty($args['label']) && $label_after) { |
|
702 | 702 | $label_args = array( |
703 | 703 | 'title' => $args['label'], |
704 | 704 | 'for' => $args['id'], |
@@ -706,32 +706,32 @@ discard block |
||
706 | 706 | 'label_type' => $args['label_type'], |
707 | 707 | 'label_col' => $args['label_col'] |
708 | 708 | ); |
709 | - $output .= self::label( $label_args ); |
|
709 | + $output .= self::label($label_args); |
|
710 | 710 | } |
711 | 711 | |
712 | 712 | // help text |
713 | - if ( ! empty( $args['help_text'] ) ) { |
|
714 | - $output .= AUI_Component_Helper::help_text( $args['help_text'] ); |
|
713 | + if (!empty($args['help_text'])) { |
|
714 | + $output .= AUI_Component_Helper::help_text($args['help_text']); |
|
715 | 715 | } |
716 | 716 | |
717 | 717 | // maybe horizontal label |
718 | - if ( $args['label_type'] == 'horizontal' ) { |
|
718 | + if ($args['label_type'] == 'horizontal') { |
|
719 | 719 | $output .= '</div>'; |
720 | 720 | } |
721 | 721 | |
722 | 722 | |
723 | 723 | // wrap |
724 | - if ( ! $args['no_wrap'] ) { |
|
724 | + if (!$args['no_wrap']) { |
|
725 | 725 | $form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : 'form-group'; |
726 | 726 | $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
727 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
728 | - $output = self::wrap( array( |
|
727 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
728 | + $output = self::wrap(array( |
|
729 | 729 | 'content' => $output, |
730 | 730 | 'class' => $wrap_class, |
731 | 731 | 'element_require' => $args['element_require'], |
732 | 732 | 'argument_id' => $args['id'], |
733 | 733 | 'wrap_attributes' => $args['wrap_attributes'], |
734 | - ) ); |
|
734 | + )); |
|
735 | 735 | } |
736 | 736 | |
737 | 737 | |
@@ -745,7 +745,7 @@ discard block |
||
745 | 745 | * |
746 | 746 | * @return string The rendered component. |
747 | 747 | */ |
748 | - public static function select( $args = array() ) { |
|
748 | + public static function select($args = array()) { |
|
749 | 749 | $defaults = array( |
750 | 750 | 'class' => '', |
751 | 751 | 'wrap_class' => '', |
@@ -782,11 +782,11 @@ discard block |
||
782 | 782 | /** |
783 | 783 | * Parse incoming $args into an array and merge it with $defaults |
784 | 784 | */ |
785 | - $args = wp_parse_args( $args, $defaults ); |
|
785 | + $args = wp_parse_args($args, $defaults); |
|
786 | 786 | $output = ''; |
787 | 787 | |
788 | 788 | // for now lets hide floating labels |
789 | - if ( $args['label_type'] == 'floating' ) { |
|
789 | + if ($args['label_type'] == 'floating') { |
|
790 | 790 | $args['label_type'] = 'hidden'; |
791 | 791 | } |
792 | 792 | |
@@ -797,31 +797,31 @@ discard block |
||
797 | 797 | $label_after = $args['label_after']; |
798 | 798 | |
799 | 799 | // floating labels need label after |
800 | - if ( $args['label_type'] == 'floating' ) { |
|
800 | + if ($args['label_type'] == 'floating') { |
|
801 | 801 | $label_after = true; |
802 | 802 | $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
803 | 803 | } |
804 | 804 | |
805 | 805 | // Maybe setup select2 |
806 | 806 | $is_select2 = false; |
807 | - if ( ! empty( $args['select2'] ) ) { |
|
807 | + if (!empty($args['select2'])) { |
|
808 | 808 | $args['class'] .= ' aui-select2'; |
809 | 809 | $is_select2 = true; |
810 | - } elseif ( strpos( $args['class'], 'aui-select2' ) !== false ) { |
|
810 | + } elseif (strpos($args['class'], 'aui-select2') !== false) { |
|
811 | 811 | $is_select2 = true; |
812 | 812 | } |
813 | 813 | |
814 | 814 | // select2 tags |
815 | - if ( ! empty( $args['select2'] ) && $args['select2'] === 'tags' ) { // triple equals needed here for some reason |
|
815 | + if (!empty($args['select2']) && $args['select2'] === 'tags') { // triple equals needed here for some reason |
|
816 | 816 | $args['data-tags'] = 'true'; |
817 | 817 | $args['data-token-separators'] = "[',']"; |
818 | 818 | $args['multiple'] = true; |
819 | 819 | } |
820 | 820 | |
821 | 821 | // select2 placeholder |
822 | - if ( $is_select2 && isset( $args['placeholder'] ) && '' != $args['placeholder'] && empty( $args['data-placeholder'] ) ) { |
|
823 | - $args['data-placeholder'] = esc_attr( $args['placeholder'] ); |
|
824 | - $args['data-allow-clear'] = isset( $args['data-allow-clear'] ) ? (bool) $args['data-allow-clear'] : true; |
|
822 | + if ($is_select2 && isset($args['placeholder']) && '' != $args['placeholder'] && empty($args['data-placeholder'])) { |
|
823 | + $args['data-placeholder'] = esc_attr($args['placeholder']); |
|
824 | + $args['data-allow-clear'] = isset($args['data-allow-clear']) ? (bool) $args['data-allow-clear'] : true; |
|
825 | 825 | } |
826 | 826 | |
827 | 827 | |
@@ -833,61 +833,61 @@ discard block |
||
833 | 833 | // } |
834 | 834 | |
835 | 835 | // Set hidden input to save empty value for multiselect. |
836 | - if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) { |
|
837 | - $output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value=""/>'; |
|
836 | + if (!empty($args['multiple']) && !empty($args['name'])) { |
|
837 | + $output .= '<input type="hidden" ' . AUI_Component_Helper::name($args['name']) . ' value=""/>'; |
|
838 | 838 | } |
839 | 839 | |
840 | 840 | // open/type |
841 | 841 | $output .= '<select '; |
842 | 842 | |
843 | 843 | // style |
844 | - if ( $is_select2 && !($args['input_group_left'] || $args['input_group_right'])) { |
|
844 | + if ($is_select2 && !($args['input_group_left'] || $args['input_group_right'])) { |
|
845 | 845 | $output .= " style='width:100%;' "; |
846 | 846 | } |
847 | 847 | |
848 | 848 | // element require |
849 | - if ( ! empty( $args['element_require'] ) ) { |
|
850 | - $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
849 | + if (!empty($args['element_require'])) { |
|
850 | + $output .= AUI_Component_Helper::element_require($args['element_require']); |
|
851 | 851 | $args['class'] .= " aui-conditional-field"; |
852 | 852 | } |
853 | 853 | |
854 | 854 | // class |
855 | - $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
856 | - $output .= AUI_Component_Helper::class_attr( 'custom-select ' . $class ); |
|
855 | + $class = !empty($args['class']) ? $args['class'] : ''; |
|
856 | + $output .= AUI_Component_Helper::class_attr('custom-select ' . $class); |
|
857 | 857 | |
858 | 858 | // name |
859 | - if ( ! empty( $args['name'] ) ) { |
|
860 | - $output .= AUI_Component_Helper::name( $args['name'], $args['multiple'] ); |
|
859 | + if (!empty($args['name'])) { |
|
860 | + $output .= AUI_Component_Helper::name($args['name'], $args['multiple']); |
|
861 | 861 | } |
862 | 862 | |
863 | 863 | // id |
864 | - if ( ! empty( $args['id'] ) ) { |
|
865 | - $output .= AUI_Component_Helper::id( $args['id'] ); |
|
864 | + if (!empty($args['id'])) { |
|
865 | + $output .= AUI_Component_Helper::id($args['id']); |
|
866 | 866 | } |
867 | 867 | |
868 | 868 | // title |
869 | - if ( ! empty( $args['title'] ) ) { |
|
870 | - $output .= AUI_Component_Helper::title( $args['title'] ); |
|
869 | + if (!empty($args['title'])) { |
|
870 | + $output .= AUI_Component_Helper::title($args['title']); |
|
871 | 871 | } |
872 | 872 | |
873 | 873 | // data-attributes |
874 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
874 | + $output .= AUI_Component_Helper::data_attributes($args); |
|
875 | 875 | |
876 | 876 | // aria-attributes |
877 | - $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
877 | + $output .= AUI_Component_Helper::aria_attributes($args); |
|
878 | 878 | |
879 | 879 | // extra attributes |
880 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
881 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
880 | + if (!empty($args['extra_attributes'])) { |
|
881 | + $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
882 | 882 | } |
883 | 883 | |
884 | 884 | // required |
885 | - if ( ! empty( $args['required'] ) ) { |
|
885 | + if (!empty($args['required'])) { |
|
886 | 886 | $output .= ' required '; |
887 | 887 | } |
888 | 888 | |
889 | 889 | // multiple |
890 | - if ( ! empty( $args['multiple'] ) ) { |
|
890 | + if (!empty($args['multiple'])) { |
|
891 | 891 | $output .= ' multiple '; |
892 | 892 | } |
893 | 893 | |
@@ -895,50 +895,50 @@ discard block |
||
895 | 895 | $output .= ' >'; |
896 | 896 | |
897 | 897 | // placeholder |
898 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] && ! $is_select2 ) { |
|
899 | - $output .= '<option value="" disabled selected hidden>' . esc_attr( $args['placeholder'] ) . '</option>'; |
|
900 | - } elseif ( $is_select2 && ! empty( $args['placeholder'] ) ) { |
|
898 | + if (isset($args['placeholder']) && '' != $args['placeholder'] && !$is_select2) { |
|
899 | + $output .= '<option value="" disabled selected hidden>' . esc_attr($args['placeholder']) . '</option>'; |
|
900 | + } elseif ($is_select2 && !empty($args['placeholder'])) { |
|
901 | 901 | $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
902 | 902 | } |
903 | 903 | |
904 | 904 | // Options |
905 | - if ( ! empty( $args['options'] ) ) { |
|
905 | + if (!empty($args['options'])) { |
|
906 | 906 | |
907 | - if ( ! is_array( $args['options'] ) ) { |
|
907 | + if (!is_array($args['options'])) { |
|
908 | 908 | $output .= $args['options']; // not the preferred way but an option |
909 | 909 | } else { |
910 | - foreach ( $args['options'] as $val => $name ) { |
|
910 | + foreach ($args['options'] as $val => $name) { |
|
911 | 911 | $selected = ''; |
912 | - if ( is_array( $name ) ) { |
|
913 | - if ( isset( $name['optgroup'] ) && ( $name['optgroup'] == 'start' || $name['optgroup'] == 'end' ) ) { |
|
914 | - $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
912 | + if (is_array($name)) { |
|
913 | + if (isset($name['optgroup']) && ($name['optgroup'] == 'start' || $name['optgroup'] == 'end')) { |
|
914 | + $option_label = isset($name['label']) ? $name['label'] : ''; |
|
915 | 915 | |
916 | - $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>'; |
|
916 | + $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr($option_label) . '">' : '</optgroup>'; |
|
917 | 917 | } else { |
918 | - $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
919 | - $option_value = isset( $name['value'] ) ? $name['value'] : ''; |
|
920 | - $extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes( $name['extra_attributes'] ) : ''; |
|
921 | - if ( ! empty( $args['multiple'] ) && ! empty( $args['value'] ) && is_array( $args['value'] ) ) { |
|
922 | - $selected = in_array( $option_value, stripslashes_deep( $args['value'] ) ) ? "selected" : ""; |
|
923 | - } elseif ( ! empty( $args['value'] ) ) { |
|
924 | - $selected = selected( $option_value, stripslashes_deep( $args['value'] ), false ); |
|
925 | - } elseif ( empty( $args['value'] ) && $args['value'] === $option_value ) { |
|
926 | - $selected = selected( $option_value, $args['value'], false ); |
|
918 | + $option_label = isset($name['label']) ? $name['label'] : ''; |
|
919 | + $option_value = isset($name['value']) ? $name['value'] : ''; |
|
920 | + $extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes($name['extra_attributes']) : ''; |
|
921 | + if (!empty($args['multiple']) && !empty($args['value']) && is_array($args['value'])) { |
|
922 | + $selected = in_array($option_value, stripslashes_deep($args['value'])) ? "selected" : ""; |
|
923 | + } elseif (!empty($args['value'])) { |
|
924 | + $selected = selected($option_value, stripslashes_deep($args['value']), false); |
|
925 | + } elseif (empty($args['value']) && $args['value'] === $option_value) { |
|
926 | + $selected = selected($option_value, $args['value'], false); |
|
927 | 927 | } |
928 | 928 | |
929 | - $output .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . ' '.$extra_attributes .'>' . $option_label . '</option>'; |
|
929 | + $output .= '<option value="' . esc_attr($option_value) . '" ' . $selected . ' ' . $extra_attributes . '>' . $option_label . '</option>'; |
|
930 | 930 | } |
931 | 931 | } else { |
932 | - if ( ! empty( $args['value'] ) ) { |
|
933 | - if ( is_array( $args['value'] ) ) { |
|
934 | - $selected = in_array( $val, $args['value'] ) ? 'selected="selected"' : ''; |
|
935 | - } elseif ( ! empty( $args['value'] ) ) { |
|
936 | - $selected = selected( $args['value'], $val, false ); |
|
932 | + if (!empty($args['value'])) { |
|
933 | + if (is_array($args['value'])) { |
|
934 | + $selected = in_array($val, $args['value']) ? 'selected="selected"' : ''; |
|
935 | + } elseif (!empty($args['value'])) { |
|
936 | + $selected = selected($args['value'], $val, false); |
|
937 | 937 | } |
938 | - } elseif ( $args['value'] === $val ) { |
|
939 | - $selected = selected( $args['value'], $val, false ); |
|
938 | + } elseif ($args['value'] === $val) { |
|
939 | + $selected = selected($args['value'], $val, false); |
|
940 | 940 | } |
941 | - $output .= '<option value="' . esc_attr( $val ) . '" ' . $selected . '>' . esc_attr( $name ) . '</option>'; |
|
941 | + $output .= '<option value="' . esc_attr($val) . '" ' . $selected . '>' . esc_attr($name) . '</option>'; |
|
942 | 942 | } |
943 | 943 | } |
944 | 944 | } |
@@ -951,8 +951,8 @@ discard block |
||
951 | 951 | $label = ''; |
952 | 952 | $help_text = ''; |
953 | 953 | // label |
954 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
955 | - } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
954 | + if (!empty($args['label']) && is_array($args['label'])) { |
|
955 | + } elseif (!empty($args['label']) && !$label_after) { |
|
956 | 956 | $label_args = array( |
957 | 957 | 'title' => $args['label'], |
958 | 958 | 'for' => $args['id'], |
@@ -960,49 +960,49 @@ discard block |
||
960 | 960 | 'label_type' => $args['label_type'], |
961 | 961 | 'label_col' => $args['label_col'] |
962 | 962 | ); |
963 | - $label = self::label( $label_args ); |
|
963 | + $label = self::label($label_args); |
|
964 | 964 | } |
965 | 965 | |
966 | 966 | // help text |
967 | - if ( ! empty( $args['help_text'] ) ) { |
|
968 | - $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
967 | + if (!empty($args['help_text'])) { |
|
968 | + $help_text = AUI_Component_Helper::help_text($args['help_text']); |
|
969 | 969 | } |
970 | 970 | |
971 | 971 | // input group wraps |
972 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
973 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
974 | - if ( $args['input_group_left'] ) { |
|
975 | - $output = self::wrap( array( |
|
972 | + if ($args['input_group_left'] || $args['input_group_right']) { |
|
973 | + $w100 = strpos($args['class'], 'w-100') !== false ? ' w-100' : ''; |
|
974 | + if ($args['input_group_left']) { |
|
975 | + $output = self::wrap(array( |
|
976 | 976 | 'content' => $output, |
977 | 977 | 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
978 | 978 | 'input_group_left' => $args['input_group_left'], |
979 | 979 | 'input_group_left_inside' => $args['input_group_left_inside'] |
980 | - ) ); |
|
980 | + )); |
|
981 | 981 | } |
982 | - if ( $args['input_group_right'] ) { |
|
983 | - $output = self::wrap( array( |
|
982 | + if ($args['input_group_right']) { |
|
983 | + $output = self::wrap(array( |
|
984 | 984 | 'content' => $output, |
985 | 985 | 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
986 | 986 | 'input_group_right' => $args['input_group_right'], |
987 | 987 | 'input_group_right_inside' => $args['input_group_right_inside'] |
988 | - ) ); |
|
988 | + )); |
|
989 | 989 | } |
990 | 990 | |
991 | 991 | } |
992 | 992 | |
993 | - if ( ! $label_after ) { |
|
993 | + if (!$label_after) { |
|
994 | 994 | $output .= $help_text; |
995 | 995 | } |
996 | 996 | |
997 | 997 | |
998 | - if ( $args['label_type'] == 'horizontal' ) { |
|
999 | - $output = self::wrap( array( |
|
998 | + if ($args['label_type'] == 'horizontal') { |
|
999 | + $output = self::wrap(array( |
|
1000 | 1000 | 'content' => $output, |
1001 | - 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
1002 | - ) ); |
|
1001 | + 'class' => AUI_Component_Helper::get_column_class($args['label_col'], 'input') |
|
1002 | + )); |
|
1003 | 1003 | } |
1004 | 1004 | |
1005 | - if ( ! $label_after ) { |
|
1005 | + if (!$label_after) { |
|
1006 | 1006 | $output = $label . $output; |
1007 | 1007 | } |
1008 | 1008 | |
@@ -1013,16 +1013,16 @@ discard block |
||
1013 | 1013 | |
1014 | 1014 | |
1015 | 1015 | // wrap |
1016 | - if ( ! $args['no_wrap'] ) { |
|
1016 | + if (!$args['no_wrap']) { |
|
1017 | 1017 | $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group'; |
1018 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1019 | - $output = self::wrap( array( |
|
1018 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1019 | + $output = self::wrap(array( |
|
1020 | 1020 | 'content' => $output, |
1021 | 1021 | 'class' => $wrap_class, |
1022 | 1022 | 'element_require' => $args['element_require'], |
1023 | 1023 | 'argument_id' => $args['id'], |
1024 | 1024 | 'wrap_attributes' => $args['wrap_attributes'], |
1025 | - ) ); |
|
1025 | + )); |
|
1026 | 1026 | } |
1027 | 1027 | |
1028 | 1028 | |
@@ -1036,7 +1036,7 @@ discard block |
||
1036 | 1036 | * |
1037 | 1037 | * @return string The rendered component. |
1038 | 1038 | */ |
1039 | - public static function radio( $args = array() ) { |
|
1039 | + public static function radio($args = array()) { |
|
1040 | 1040 | $defaults = array( |
1041 | 1041 | 'class' => '', |
1042 | 1042 | 'wrap_class' => '', |
@@ -1066,10 +1066,10 @@ discard block |
||
1066 | 1066 | /** |
1067 | 1067 | * Parse incoming $args into an array and merge it with $defaults |
1068 | 1068 | */ |
1069 | - $args = wp_parse_args( $args, $defaults ); |
|
1069 | + $args = wp_parse_args($args, $defaults); |
|
1070 | 1070 | |
1071 | 1071 | // for now lets use horizontal for floating |
1072 | - if ( $args['label_type'] == 'floating' ) { |
|
1072 | + if ($args['label_type'] == 'floating') { |
|
1073 | 1073 | $args['label_type'] = 'horizontal'; |
1074 | 1074 | } |
1075 | 1075 | |
@@ -1084,47 +1084,47 @@ discard block |
||
1084 | 1084 | |
1085 | 1085 | |
1086 | 1086 | // label before |
1087 | - if ( ! empty( $args['label'] ) ) { |
|
1088 | - $output .= self::label( $label_args, 'radio' ); |
|
1087 | + if (!empty($args['label'])) { |
|
1088 | + $output .= self::label($label_args, 'radio'); |
|
1089 | 1089 | } |
1090 | 1090 | |
1091 | 1091 | // maybe horizontal label |
1092 | - if ( $args['label_type'] == 'horizontal' ) { |
|
1093 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
1092 | + if ($args['label_type'] == 'horizontal') { |
|
1093 | + $input_col = AUI_Component_Helper::get_column_class($args['label_col'], 'input'); |
|
1094 | 1094 | $output .= '<div class="' . $input_col . '">'; |
1095 | 1095 | } |
1096 | 1096 | |
1097 | - if ( ! empty( $args['options'] ) ) { |
|
1097 | + if (!empty($args['options'])) { |
|
1098 | 1098 | $count = 0; |
1099 | - foreach ( $args['options'] as $value => $label ) { |
|
1099 | + foreach ($args['options'] as $value => $label) { |
|
1100 | 1100 | $option_args = $args; |
1101 | 1101 | $option_args['value'] = $value; |
1102 | 1102 | $option_args['label'] = $label; |
1103 | 1103 | $option_args['checked'] = $value == $args['value'] ? true : false; |
1104 | - $output .= self::radio_option( $option_args, $count ); |
|
1105 | - $count ++; |
|
1104 | + $output .= self::radio_option($option_args, $count); |
|
1105 | + $count++; |
|
1106 | 1106 | } |
1107 | 1107 | } |
1108 | 1108 | |
1109 | 1109 | // help text |
1110 | - $help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : ''; |
|
1110 | + $help_text = !empty($args['help_text']) ? AUI_Component_Helper::help_text($args['help_text']) : ''; |
|
1111 | 1111 | $output .= $help_text; |
1112 | 1112 | |
1113 | 1113 | // maybe horizontal label |
1114 | - if ( $args['label_type'] == 'horizontal' ) { |
|
1114 | + if ($args['label_type'] == 'horizontal') { |
|
1115 | 1115 | $output .= '</div>'; |
1116 | 1116 | } |
1117 | 1117 | |
1118 | 1118 | // wrap |
1119 | 1119 | $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group'; |
1120 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1121 | - $output = self::wrap( array( |
|
1120 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1121 | + $output = self::wrap(array( |
|
1122 | 1122 | 'content' => $output, |
1123 | 1123 | 'class' => $wrap_class, |
1124 | 1124 | 'element_require' => $args['element_require'], |
1125 | 1125 | 'argument_id' => $args['id'], |
1126 | 1126 | 'wrap_attributes' => $args['wrap_attributes'], |
1127 | - ) ); |
|
1127 | + )); |
|
1128 | 1128 | |
1129 | 1129 | |
1130 | 1130 | return $output; |
@@ -1137,7 +1137,7 @@ discard block |
||
1137 | 1137 | * |
1138 | 1138 | * @return string The rendered component. |
1139 | 1139 | */ |
1140 | - public static function radio_option( $args = array(), $count = '' ) { |
|
1140 | + public static function radio_option($args = array(), $count = '') { |
|
1141 | 1141 | $defaults = array( |
1142 | 1142 | 'class' => '', |
1143 | 1143 | 'id' => '', |
@@ -1155,7 +1155,7 @@ discard block |
||
1155 | 1155 | /** |
1156 | 1156 | * Parse incoming $args into an array and merge it with $defaults |
1157 | 1157 | */ |
1158 | - $args = wp_parse_args( $args, $defaults ); |
|
1158 | + $args = wp_parse_args($args, $defaults); |
|
1159 | 1159 | |
1160 | 1160 | $output = ''; |
1161 | 1161 | |
@@ -1166,43 +1166,43 @@ discard block |
||
1166 | 1166 | $output .= ' class="form-check-input" '; |
1167 | 1167 | |
1168 | 1168 | // name |
1169 | - if ( ! empty( $args['name'] ) ) { |
|
1170 | - $output .= AUI_Component_Helper::name( $args['name'] ); |
|
1169 | + if (!empty($args['name'])) { |
|
1170 | + $output .= AUI_Component_Helper::name($args['name']); |
|
1171 | 1171 | } |
1172 | 1172 | |
1173 | 1173 | // id |
1174 | - if ( ! empty( $args['id'] ) ) { |
|
1175 | - $output .= AUI_Component_Helper::id( $args['id'] . $count ); |
|
1174 | + if (!empty($args['id'])) { |
|
1175 | + $output .= AUI_Component_Helper::id($args['id'] . $count); |
|
1176 | 1176 | } |
1177 | 1177 | |
1178 | 1178 | // title |
1179 | - if ( ! empty( $args['title'] ) ) { |
|
1180 | - $output .= AUI_Component_Helper::title( $args['title'] ); |
|
1179 | + if (!empty($args['title'])) { |
|
1180 | + $output .= AUI_Component_Helper::title($args['title']); |
|
1181 | 1181 | } |
1182 | 1182 | |
1183 | 1183 | // value |
1184 | - if ( isset( $args['value'] ) ) { |
|
1185 | - $output .= AUI_Component_Helper::value( $args['value'] ); |
|
1184 | + if (isset($args['value'])) { |
|
1185 | + $output .= AUI_Component_Helper::value($args['value']); |
|
1186 | 1186 | } |
1187 | 1187 | |
1188 | 1188 | // checked, for radio and checkboxes |
1189 | - if ( $args['checked'] ) { |
|
1189 | + if ($args['checked']) { |
|
1190 | 1190 | $output .= ' checked '; |
1191 | 1191 | } |
1192 | 1192 | |
1193 | 1193 | // data-attributes |
1194 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
1194 | + $output .= AUI_Component_Helper::data_attributes($args); |
|
1195 | 1195 | |
1196 | 1196 | // aria-attributes |
1197 | - $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
1197 | + $output .= AUI_Component_Helper::aria_attributes($args); |
|
1198 | 1198 | |
1199 | 1199 | // extra attributes |
1200 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
1201 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
1200 | + if (!empty($args['extra_attributes'])) { |
|
1201 | + $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
1202 | 1202 | } |
1203 | 1203 | |
1204 | 1204 | // required |
1205 | - if ( ! empty( $args['required'] ) ) { |
|
1205 | + if (!empty($args['required'])) { |
|
1206 | 1206 | $output .= ' required '; |
1207 | 1207 | } |
1208 | 1208 | |
@@ -1210,38 +1210,38 @@ discard block |
||
1210 | 1210 | $output .= ' >'; |
1211 | 1211 | |
1212 | 1212 | // label |
1213 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
1214 | - } elseif ( ! empty( $args['label'] ) ) { |
|
1215 | - $output .= self::label( array( |
|
1213 | + if (!empty($args['label']) && is_array($args['label'])) { |
|
1214 | + } elseif (!empty($args['label'])) { |
|
1215 | + $output .= self::label(array( |
|
1216 | 1216 | 'title' => $args['label'], |
1217 | 1217 | 'for' => $args['id'] . $count, |
1218 | 1218 | 'class' => 'form-check-label' |
1219 | - ), 'radio' ); |
|
1219 | + ), 'radio'); |
|
1220 | 1220 | } |
1221 | 1221 | |
1222 | 1222 | // wrap |
1223 | - if ( ! $args['no_wrap'] ) { |
|
1223 | + if (!$args['no_wrap']) { |
|
1224 | 1224 | $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
1225 | 1225 | |
1226 | 1226 | // Unique wrap class |
1227 | 1227 | $uniq_class = 'fwrap'; |
1228 | - if ( ! empty( $args['name'] ) ) { |
|
1228 | + if (!empty($args['name'])) { |
|
1229 | 1229 | $uniq_class .= '-' . $args['name']; |
1230 | - } else if ( ! empty( $args['id'] ) ) { |
|
1230 | + } else if (!empty($args['id'])) { |
|
1231 | 1231 | $uniq_class .= '-' . $args['id']; |
1232 | 1232 | } |
1233 | 1233 | |
1234 | - if ( isset( $args['value'] ) || $args['value'] !== "" ) { |
|
1234 | + if (isset($args['value']) || $args['value'] !== "") { |
|
1235 | 1235 | $uniq_class .= '-' . $args['value']; |
1236 | 1236 | } else { |
1237 | 1237 | $uniq_class .= '-' . $count; |
1238 | 1238 | } |
1239 | - $wrap_class .= ' ' . sanitize_html_class( $uniq_class ); |
|
1239 | + $wrap_class .= ' ' . sanitize_html_class($uniq_class); |
|
1240 | 1240 | |
1241 | - $output = self::wrap( array( |
|
1241 | + $output = self::wrap(array( |
|
1242 | 1242 | 'content' => $output, |
1243 | 1243 | 'class' => $wrap_class |
1244 | - ) ); |
|
1244 | + )); |
|
1245 | 1245 | } |
1246 | 1246 | |
1247 | 1247 | return $output; |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | if ( $args['size'] == 'lg' || $args['size'] == 'large' ) { |
96 | 96 | $size = 'lg'; |
97 | 97 | $args['class'] .= ' form-control-lg'; |
98 | - }elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) { |
|
98 | + } elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) { |
|
99 | 99 | $size = 'sm'; |
100 | 100 | $args['class'] .= ' form-control-sm'; |
101 | 101 | } |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | $help_text = ''; |
237 | 237 | //$label_args['class'] .= ' d-inline '; |
238 | 238 | $args['wrap_class'] .= ' align-items-center '; |
239 | - }else{ |
|
239 | + } else{ |
|
240 | 240 | |
241 | 241 | } |
242 | 242 |
@@ -16,202 +16,202 @@ |
||
16 | 16 | |
17 | 17 | // If this file is called directly, abort. |
18 | 18 | if ( ! defined( 'WPINC' ) ) { |
19 | - die; |
|
19 | + die; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | class AyeCode_UI_Plugin { |
23 | 23 | |
24 | - /** |
|
25 | - * AUI Plugin constructor. |
|
26 | - * |
|
27 | - * @since 1.0.0 |
|
28 | - */ |
|
29 | - public function __construct() { |
|
30 | - |
|
31 | - // load AUI |
|
32 | - require_once( dirname( __FILE__ ) . '/ayecode-ui-loader.php' ); |
|
33 | - |
|
34 | - // Maybe show example page |
|
35 | - add_action( 'template_redirect', array( $this,'maybe_show_examples' ) ); |
|
36 | - } |
|
37 | - |
|
38 | - public function maybe_show_examples(){ |
|
39 | - if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){ |
|
40 | - echo "<head>"; |
|
41 | - wp_head(); |
|
42 | - echo "</head>"; |
|
43 | - echo "<body class='bsui'>"; |
|
44 | - echo $this->get_examples(); |
|
45 | - wp_footer(); |
|
46 | - echo "</body>"; |
|
47 | - exit; |
|
48 | - } |
|
49 | - } |
|
50 | - |
|
51 | - public function get_examples(){ |
|
52 | - $output = ''; |
|
53 | - |
|
54 | - |
|
55 | - // open form |
|
56 | - $output .= "<form class='p-5 m-5 border rounded'>"; |
|
57 | - |
|
58 | - $output .= aui()->input( |
|
59 | - array( |
|
60 | - 'type' => 'datepicker', |
|
61 | - 'id' => 'wpinv_discount_start', |
|
62 | - 'size' => 'sm', |
|
63 | - 'name' => 'wpinv_discount_start', |
|
64 | - 'label' => __( 'Start Date', 'invoicing' ), |
|
65 | - 'placeholder' => 'YYYY-MM-DD 00:00', |
|
66 | - 'value' => '', |
|
67 | - 'extra_attributes' => array( |
|
68 | - 'data-enable-time' => 'true', |
|
69 | - 'data-time_24hr' => 'true', |
|
70 | - 'data-allow-input' => 'true', |
|
71 | - ), |
|
72 | - ), |
|
73 | - ); |
|
74 | - |
|
75 | - $output .= aui()->input( |
|
76 | - array( |
|
77 | - 'type' => 'datepicker', |
|
78 | - 'id' => 'wpinv_discount_start', |
|
79 | - //'size' => 'smx', |
|
80 | - 'name' => 'wpinv_discount_start', |
|
81 | - 'label' => __( 'Start Date', 'invoicing' ), |
|
82 | - 'placeholder' => 'YYYY-MM-DD 00:00', |
|
83 | - 'value' => '', |
|
84 | - 'extra_attributes' => array( |
|
85 | - 'data-enable-time' => 'true', |
|
86 | - 'data-time_24hr' => 'true', |
|
87 | - 'data-allow-input' => 'true', |
|
88 | - ), |
|
89 | - ), |
|
90 | - ); |
|
91 | - $output .= aui()->input( |
|
92 | - array( |
|
93 | - 'type' => 'datepicker', |
|
94 | - 'id' => 'wpinv_discount_start', |
|
95 | - 'size' => 'lg', |
|
96 | - 'name' => 'wpinv_discount_start', |
|
97 | - 'label' => __( 'Start Date', 'invoicing' ), |
|
98 | - 'placeholder' => 'YYYY-MM-DD 00:00', |
|
99 | - 'value' => '', |
|
100 | - 'extra_attributes' => array( |
|
101 | - 'data-enable-time' => 'true', |
|
102 | - 'data-time_24hr' => 'true', |
|
103 | - //'data-allow-input' => 'true', |
|
104 | - ), |
|
105 | - ) |
|
106 | - ); |
|
107 | - |
|
108 | - |
|
109 | - // input example |
|
110 | - $output .= aui()->input(array( |
|
111 | - 'type' => 'text', |
|
112 | - 'id' => 'text-example', |
|
113 | - 'size' => 'sm', |
|
114 | - //'clear_icon' => true, |
|
115 | - 'name' => 'text-example', |
|
116 | - 'placeholder' => 'text placeholder', |
|
117 | - 'title' => 'Text input example', |
|
118 | - 'value' => '', |
|
119 | - 'required' => false, |
|
120 | - 'help_text' => 'help text', |
|
121 | - 'label' => 'Text input example label', |
|
122 | - 'label_type' => 'top' |
|
123 | - )); |
|
124 | - |
|
125 | - $output .= aui()->input(array( |
|
126 | - 'type' => 'search', |
|
127 | - 'id' => 'text-example', |
|
128 | - 'size' => 'sm', |
|
129 | - //'clear_icon' => true, |
|
130 | - 'name' => 'text-example', |
|
131 | - 'placeholder' => 'text placeholder', |
|
132 | - 'title' => 'Text input example', |
|
133 | - 'value' => '', |
|
134 | - 'required' => false, |
|
135 | - 'help_text' => 'help text', |
|
136 | - 'label' => 'Text input example label', |
|
137 | - 'label_type' => 'top' |
|
138 | - )); |
|
139 | - |
|
140 | - // input example |
|
141 | - $output .= aui()->input(array( |
|
142 | - 'type' => 'url', |
|
143 | - 'id' => 'text-example2', |
|
144 | - 'name' => 'text-example', |
|
145 | - 'placeholder' => 'url placeholder', |
|
146 | - 'title' => 'Text input example', |
|
147 | - 'value' => '', |
|
148 | - 'required' => false, |
|
149 | - 'help_text' => 'help text', |
|
150 | - 'label' => 'Text input example label' |
|
151 | - )); |
|
152 | - |
|
153 | - // checkbox example |
|
154 | - $output .= aui()->input(array( |
|
155 | - 'type' => 'checkbox', |
|
156 | - 'id' => 'checkbox-example', |
|
157 | - 'name' => 'checkbox-example', |
|
158 | - 'placeholder' => 'checkbox-example', |
|
159 | - 'title' => 'Checkbox example', |
|
160 | - 'value' => '1', |
|
161 | - 'checked' => true, |
|
162 | - 'required' => false, |
|
163 | - 'help_text' => 'help text', |
|
164 | - 'label' => 'Checkbox checked' |
|
165 | - )); |
|
166 | - |
|
167 | - // checkbox example |
|
168 | - $output .= aui()->input(array( |
|
169 | - 'type' => 'checkbox', |
|
170 | - 'id' => 'checkbox-example2', |
|
171 | - 'name' => 'checkbox-example2', |
|
172 | - 'placeholder' => 'checkbox-example', |
|
173 | - 'title' => 'Checkbox example', |
|
174 | - 'value' => '1', |
|
175 | - 'checked' => false, |
|
176 | - 'required' => false, |
|
177 | - 'help_text' => 'help text', |
|
178 | - 'label' => 'Checkbox un-checked' |
|
179 | - )); |
|
180 | - |
|
181 | - // switch example |
|
182 | - $output .= aui()->input(array( |
|
183 | - 'type' => 'checkbox', |
|
184 | - 'id' => 'switch-example', |
|
185 | - 'name' => 'switch-example', |
|
186 | - 'placeholder' => 'checkbox-example', |
|
187 | - 'title' => 'Switch example', |
|
188 | - 'value' => '1', |
|
189 | - 'checked' => true, |
|
190 | - 'switch' => true, |
|
191 | - 'required' => false, |
|
192 | - 'help_text' => 'help text', |
|
193 | - 'label' => 'Switch on' |
|
194 | - )); |
|
195 | - |
|
196 | - // switch example |
|
197 | - $output .= aui()->input(array( |
|
198 | - 'type' => 'checkbox', |
|
199 | - 'id' => 'switch-example2', |
|
200 | - 'name' => 'switch-example2', |
|
201 | - 'placeholder' => 'checkbox-example', |
|
202 | - 'title' => 'Switch example', |
|
203 | - 'value' => '1', |
|
204 | - 'checked' => false, |
|
205 | - 'switch' => true, |
|
206 | - 'required' => false, |
|
207 | - 'help_text' => 'help text', |
|
208 | - 'label' => 'Switch off' |
|
209 | - )); |
|
210 | - |
|
211 | - // close form |
|
212 | - $output .= "</form>"; |
|
213 | - |
|
214 | - return $output; |
|
215 | - } |
|
24 | + /** |
|
25 | + * AUI Plugin constructor. |
|
26 | + * |
|
27 | + * @since 1.0.0 |
|
28 | + */ |
|
29 | + public function __construct() { |
|
30 | + |
|
31 | + // load AUI |
|
32 | + require_once( dirname( __FILE__ ) . '/ayecode-ui-loader.php' ); |
|
33 | + |
|
34 | + // Maybe show example page |
|
35 | + add_action( 'template_redirect', array( $this,'maybe_show_examples' ) ); |
|
36 | + } |
|
37 | + |
|
38 | + public function maybe_show_examples(){ |
|
39 | + if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){ |
|
40 | + echo "<head>"; |
|
41 | + wp_head(); |
|
42 | + echo "</head>"; |
|
43 | + echo "<body class='bsui'>"; |
|
44 | + echo $this->get_examples(); |
|
45 | + wp_footer(); |
|
46 | + echo "</body>"; |
|
47 | + exit; |
|
48 | + } |
|
49 | + } |
|
50 | + |
|
51 | + public function get_examples(){ |
|
52 | + $output = ''; |
|
53 | + |
|
54 | + |
|
55 | + // open form |
|
56 | + $output .= "<form class='p-5 m-5 border rounded'>"; |
|
57 | + |
|
58 | + $output .= aui()->input( |
|
59 | + array( |
|
60 | + 'type' => 'datepicker', |
|
61 | + 'id' => 'wpinv_discount_start', |
|
62 | + 'size' => 'sm', |
|
63 | + 'name' => 'wpinv_discount_start', |
|
64 | + 'label' => __( 'Start Date', 'invoicing' ), |
|
65 | + 'placeholder' => 'YYYY-MM-DD 00:00', |
|
66 | + 'value' => '', |
|
67 | + 'extra_attributes' => array( |
|
68 | + 'data-enable-time' => 'true', |
|
69 | + 'data-time_24hr' => 'true', |
|
70 | + 'data-allow-input' => 'true', |
|
71 | + ), |
|
72 | + ), |
|
73 | + ); |
|
74 | + |
|
75 | + $output .= aui()->input( |
|
76 | + array( |
|
77 | + 'type' => 'datepicker', |
|
78 | + 'id' => 'wpinv_discount_start', |
|
79 | + //'size' => 'smx', |
|
80 | + 'name' => 'wpinv_discount_start', |
|
81 | + 'label' => __( 'Start Date', 'invoicing' ), |
|
82 | + 'placeholder' => 'YYYY-MM-DD 00:00', |
|
83 | + 'value' => '', |
|
84 | + 'extra_attributes' => array( |
|
85 | + 'data-enable-time' => 'true', |
|
86 | + 'data-time_24hr' => 'true', |
|
87 | + 'data-allow-input' => 'true', |
|
88 | + ), |
|
89 | + ), |
|
90 | + ); |
|
91 | + $output .= aui()->input( |
|
92 | + array( |
|
93 | + 'type' => 'datepicker', |
|
94 | + 'id' => 'wpinv_discount_start', |
|
95 | + 'size' => 'lg', |
|
96 | + 'name' => 'wpinv_discount_start', |
|
97 | + 'label' => __( 'Start Date', 'invoicing' ), |
|
98 | + 'placeholder' => 'YYYY-MM-DD 00:00', |
|
99 | + 'value' => '', |
|
100 | + 'extra_attributes' => array( |
|
101 | + 'data-enable-time' => 'true', |
|
102 | + 'data-time_24hr' => 'true', |
|
103 | + //'data-allow-input' => 'true', |
|
104 | + ), |
|
105 | + ) |
|
106 | + ); |
|
107 | + |
|
108 | + |
|
109 | + // input example |
|
110 | + $output .= aui()->input(array( |
|
111 | + 'type' => 'text', |
|
112 | + 'id' => 'text-example', |
|
113 | + 'size' => 'sm', |
|
114 | + //'clear_icon' => true, |
|
115 | + 'name' => 'text-example', |
|
116 | + 'placeholder' => 'text placeholder', |
|
117 | + 'title' => 'Text input example', |
|
118 | + 'value' => '', |
|
119 | + 'required' => false, |
|
120 | + 'help_text' => 'help text', |
|
121 | + 'label' => 'Text input example label', |
|
122 | + 'label_type' => 'top' |
|
123 | + )); |
|
124 | + |
|
125 | + $output .= aui()->input(array( |
|
126 | + 'type' => 'search', |
|
127 | + 'id' => 'text-example', |
|
128 | + 'size' => 'sm', |
|
129 | + //'clear_icon' => true, |
|
130 | + 'name' => 'text-example', |
|
131 | + 'placeholder' => 'text placeholder', |
|
132 | + 'title' => 'Text input example', |
|
133 | + 'value' => '', |
|
134 | + 'required' => false, |
|
135 | + 'help_text' => 'help text', |
|
136 | + 'label' => 'Text input example label', |
|
137 | + 'label_type' => 'top' |
|
138 | + )); |
|
139 | + |
|
140 | + // input example |
|
141 | + $output .= aui()->input(array( |
|
142 | + 'type' => 'url', |
|
143 | + 'id' => 'text-example2', |
|
144 | + 'name' => 'text-example', |
|
145 | + 'placeholder' => 'url placeholder', |
|
146 | + 'title' => 'Text input example', |
|
147 | + 'value' => '', |
|
148 | + 'required' => false, |
|
149 | + 'help_text' => 'help text', |
|
150 | + 'label' => 'Text input example label' |
|
151 | + )); |
|
152 | + |
|
153 | + // checkbox example |
|
154 | + $output .= aui()->input(array( |
|
155 | + 'type' => 'checkbox', |
|
156 | + 'id' => 'checkbox-example', |
|
157 | + 'name' => 'checkbox-example', |
|
158 | + 'placeholder' => 'checkbox-example', |
|
159 | + 'title' => 'Checkbox example', |
|
160 | + 'value' => '1', |
|
161 | + 'checked' => true, |
|
162 | + 'required' => false, |
|
163 | + 'help_text' => 'help text', |
|
164 | + 'label' => 'Checkbox checked' |
|
165 | + )); |
|
166 | + |
|
167 | + // checkbox example |
|
168 | + $output .= aui()->input(array( |
|
169 | + 'type' => 'checkbox', |
|
170 | + 'id' => 'checkbox-example2', |
|
171 | + 'name' => 'checkbox-example2', |
|
172 | + 'placeholder' => 'checkbox-example', |
|
173 | + 'title' => 'Checkbox example', |
|
174 | + 'value' => '1', |
|
175 | + 'checked' => false, |
|
176 | + 'required' => false, |
|
177 | + 'help_text' => 'help text', |
|
178 | + 'label' => 'Checkbox un-checked' |
|
179 | + )); |
|
180 | + |
|
181 | + // switch example |
|
182 | + $output .= aui()->input(array( |
|
183 | + 'type' => 'checkbox', |
|
184 | + 'id' => 'switch-example', |
|
185 | + 'name' => 'switch-example', |
|
186 | + 'placeholder' => 'checkbox-example', |
|
187 | + 'title' => 'Switch example', |
|
188 | + 'value' => '1', |
|
189 | + 'checked' => true, |
|
190 | + 'switch' => true, |
|
191 | + 'required' => false, |
|
192 | + 'help_text' => 'help text', |
|
193 | + 'label' => 'Switch on' |
|
194 | + )); |
|
195 | + |
|
196 | + // switch example |
|
197 | + $output .= aui()->input(array( |
|
198 | + 'type' => 'checkbox', |
|
199 | + 'id' => 'switch-example2', |
|
200 | + 'name' => 'switch-example2', |
|
201 | + 'placeholder' => 'checkbox-example', |
|
202 | + 'title' => 'Switch example', |
|
203 | + 'value' => '1', |
|
204 | + 'checked' => false, |
|
205 | + 'switch' => true, |
|
206 | + 'required' => false, |
|
207 | + 'help_text' => 'help text', |
|
208 | + 'label' => 'Switch off' |
|
209 | + )); |
|
210 | + |
|
211 | + // close form |
|
212 | + $output .= "</form>"; |
|
213 | + |
|
214 | + return $output; |
|
215 | + } |
|
216 | 216 | } |
217 | 217 | new AyeCode_UI_Plugin(); |
218 | 218 | \ No newline at end of file |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | */ |
16 | 16 | |
17 | 17 | // If this file is called directly, abort. |
18 | -if ( ! defined( 'WPINC' ) ) { |
|
18 | +if (!defined('WPINC')) { |
|
19 | 19 | die; |
20 | 20 | } |
21 | 21 | |
@@ -29,14 +29,14 @@ discard block |
||
29 | 29 | public function __construct() { |
30 | 30 | |
31 | 31 | // load AUI |
32 | - require_once( dirname( __FILE__ ) . '/ayecode-ui-loader.php' ); |
|
32 | + require_once(dirname(__FILE__) . '/ayecode-ui-loader.php'); |
|
33 | 33 | |
34 | 34 | // Maybe show example page |
35 | - add_action( 'template_redirect', array( $this,'maybe_show_examples' ) ); |
|
35 | + add_action('template_redirect', array($this, 'maybe_show_examples')); |
|
36 | 36 | } |
37 | 37 | |
38 | - public function maybe_show_examples(){ |
|
39 | - if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){ |
|
38 | + public function maybe_show_examples() { |
|
39 | + if (current_user_can('manage_options') && isset($_REQUEST['preview-aui'])) { |
|
40 | 40 | echo "<head>"; |
41 | 41 | wp_head(); |
42 | 42 | echo "</head>"; |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | } |
49 | 49 | } |
50 | 50 | |
51 | - public function get_examples(){ |
|
51 | + public function get_examples() { |
|
52 | 52 | $output = ''; |
53 | 53 | |
54 | 54 | |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | 'id' => 'wpinv_discount_start', |
62 | 62 | 'size' => 'sm', |
63 | 63 | 'name' => 'wpinv_discount_start', |
64 | - 'label' => __( 'Start Date', 'invoicing' ), |
|
64 | + 'label' => __('Start Date', 'invoicing'), |
|
65 | 65 | 'placeholder' => 'YYYY-MM-DD 00:00', |
66 | 66 | 'value' => '', |
67 | 67 | 'extra_attributes' => array( |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | 'id' => 'wpinv_discount_start', |
79 | 79 | //'size' => 'smx', |
80 | 80 | 'name' => 'wpinv_discount_start', |
81 | - 'label' => __( 'Start Date', 'invoicing' ), |
|
81 | + 'label' => __('Start Date', 'invoicing'), |
|
82 | 82 | 'placeholder' => 'YYYY-MM-DD 00:00', |
83 | 83 | 'value' => '', |
84 | 84 | 'extra_attributes' => array( |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | 'id' => 'wpinv_discount_start', |
95 | 95 | 'size' => 'lg', |
96 | 96 | 'name' => 'wpinv_discount_start', |
97 | - 'label' => __( 'Start Date', 'invoicing' ), |
|
97 | + 'label' => __('Start Date', 'invoicing'), |
|
98 | 98 | 'placeholder' => 'YYYY-MM-DD 00:00', |
99 | 99 | 'value' => '', |
100 | 100 | 'extra_attributes' => array( |
@@ -12,473 +12,473 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Paypal_Gateway_IPN_Handler { |
14 | 14 | |
15 | - /** |
|
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
20 | - protected $id = 'paypal'; |
|
21 | - |
|
22 | - /** |
|
23 | - * Payment method object. |
|
24 | - * |
|
25 | - * @var GetPaid_Paypal_Gateway |
|
26 | - */ |
|
27 | - protected $gateway; |
|
28 | - |
|
29 | - /** |
|
30 | - * Class constructor. |
|
31 | - * |
|
32 | - * @param GetPaid_Paypal_Gateway $gateway |
|
33 | - */ |
|
34 | - public function __construct( $gateway ) { |
|
35 | - $this->gateway = $gateway; |
|
36 | - $this->verify_ipn(); |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * Processes ipns and marks payments as complete. |
|
41 | - * |
|
42 | - * @return void |
|
43 | - */ |
|
44 | - public function verify_ipn() { |
|
45 | - |
|
46 | - wpinv_error_log( 'GetPaid PayPal IPN Handler', false ); |
|
47 | - |
|
48 | - // Validate the IPN. |
|
49 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
50 | - wp_die( 'PayPal IPN Request Failure', 500 ); |
|
51 | - } |
|
52 | - |
|
53 | - // Process the IPN. |
|
54 | - $posted = wp_unslash( $_POST ); |
|
55 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
56 | - |
|
57 | - // Abort if it was not paid by our gateway. |
|
58 | - if ( $this->id != $invoice->get_gateway() ) { |
|
59 | - wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false ); |
|
60 | - wp_die( 'Invoice not paid via PayPal', 200 ); |
|
61 | - } |
|
62 | - |
|
63 | - $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
64 | - $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
65 | - |
|
66 | - wpinv_error_log( 'Payment status:' . $posted['payment_status'], false ); |
|
67 | - wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false ); |
|
68 | - |
|
69 | - if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
70 | - call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
71 | - wpinv_error_log( 'Done processing IPN', false ); |
|
72 | - wp_die( 'Processed', 200 ); |
|
73 | - } |
|
74 | - |
|
75 | - wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false ); |
|
76 | - wp_die( 'Unsupported IPN type', 200 ); |
|
77 | - |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Retrieves IPN Invoice. |
|
82 | - * |
|
83 | - * @param array $posted |
|
84 | - * @return WPInv_Invoice |
|
85 | - */ |
|
86 | - protected function get_ipn_invoice( $posted ) { |
|
87 | - |
|
88 | - wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false ); |
|
89 | - |
|
90 | - if ( ! empty( $posted['custom'] ) ) { |
|
91 | - $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
92 | - |
|
93 | - if ( $invoice->exists() ) { |
|
94 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false ); |
|
95 | - return $invoice; |
|
96 | - } |
|
97 | - } |
|
98 | - |
|
99 | - wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
100 | - wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Check PayPal IPN validity. |
|
105 | - */ |
|
106 | - protected function validate_ipn() { |
|
107 | - |
|
108 | - wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
109 | - |
|
110 | - // Retrieve the associated invoice. |
|
111 | - $posted = wp_unslash( $_POST ); |
|
112 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
113 | - |
|
114 | - if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
115 | - wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false ); |
|
116 | - } |
|
117 | - |
|
118 | - // Validate the IPN. |
|
119 | - $posted['cmd'] = '_notify-validate'; |
|
120 | - |
|
121 | - // Send back post vars to paypal. |
|
122 | - $params = array( |
|
123 | - 'body' => $posted, |
|
124 | - 'timeout' => 60, |
|
125 | - 'httpversion' => '1.1', |
|
126 | - 'compress' => false, |
|
127 | - 'decompress' => false, |
|
128 | - 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
129 | - ); |
|
130 | - |
|
131 | - // Post back to get a response. |
|
132 | - $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
133 | - |
|
134 | - // Check to see if the request was valid. |
|
135 | - if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
136 | - wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
137 | - return true; |
|
138 | - } |
|
139 | - |
|
140 | - if ( is_wp_error( $response ) ) { |
|
141 | - wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
142 | - return false; |
|
143 | - } |
|
144 | - |
|
145 | - wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
146 | - return false; |
|
147 | - |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Check currency from IPN matches the invoice. |
|
152 | - * |
|
153 | - * @param WPInv_Invoice $invoice Invoice object. |
|
154 | - * @param string $currency currency to validate. |
|
155 | - */ |
|
156 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
15 | + /** |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | + protected $id = 'paypal'; |
|
21 | + |
|
22 | + /** |
|
23 | + * Payment method object. |
|
24 | + * |
|
25 | + * @var GetPaid_Paypal_Gateway |
|
26 | + */ |
|
27 | + protected $gateway; |
|
28 | + |
|
29 | + /** |
|
30 | + * Class constructor. |
|
31 | + * |
|
32 | + * @param GetPaid_Paypal_Gateway $gateway |
|
33 | + */ |
|
34 | + public function __construct( $gateway ) { |
|
35 | + $this->gateway = $gateway; |
|
36 | + $this->verify_ipn(); |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * Processes ipns and marks payments as complete. |
|
41 | + * |
|
42 | + * @return void |
|
43 | + */ |
|
44 | + public function verify_ipn() { |
|
45 | + |
|
46 | + wpinv_error_log( 'GetPaid PayPal IPN Handler', false ); |
|
47 | + |
|
48 | + // Validate the IPN. |
|
49 | + if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
50 | + wp_die( 'PayPal IPN Request Failure', 500 ); |
|
51 | + } |
|
52 | + |
|
53 | + // Process the IPN. |
|
54 | + $posted = wp_unslash( $_POST ); |
|
55 | + $invoice = $this->get_ipn_invoice( $posted ); |
|
56 | + |
|
57 | + // Abort if it was not paid by our gateway. |
|
58 | + if ( $this->id != $invoice->get_gateway() ) { |
|
59 | + wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false ); |
|
60 | + wp_die( 'Invoice not paid via PayPal', 200 ); |
|
61 | + } |
|
62 | + |
|
63 | + $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
64 | + $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
65 | + |
|
66 | + wpinv_error_log( 'Payment status:' . $posted['payment_status'], false ); |
|
67 | + wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false ); |
|
68 | + |
|
69 | + if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
70 | + call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
71 | + wpinv_error_log( 'Done processing IPN', false ); |
|
72 | + wp_die( 'Processed', 200 ); |
|
73 | + } |
|
74 | + |
|
75 | + wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false ); |
|
76 | + wp_die( 'Unsupported IPN type', 200 ); |
|
77 | + |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Retrieves IPN Invoice. |
|
82 | + * |
|
83 | + * @param array $posted |
|
84 | + * @return WPInv_Invoice |
|
85 | + */ |
|
86 | + protected function get_ipn_invoice( $posted ) { |
|
87 | + |
|
88 | + wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false ); |
|
89 | + |
|
90 | + if ( ! empty( $posted['custom'] ) ) { |
|
91 | + $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
92 | + |
|
93 | + if ( $invoice->exists() ) { |
|
94 | + wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false ); |
|
95 | + return $invoice; |
|
96 | + } |
|
97 | + } |
|
98 | + |
|
99 | + wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
100 | + wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Check PayPal IPN validity. |
|
105 | + */ |
|
106 | + protected function validate_ipn() { |
|
107 | + |
|
108 | + wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
109 | + |
|
110 | + // Retrieve the associated invoice. |
|
111 | + $posted = wp_unslash( $_POST ); |
|
112 | + $invoice = $this->get_ipn_invoice( $posted ); |
|
113 | + |
|
114 | + if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
115 | + wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false ); |
|
116 | + } |
|
117 | + |
|
118 | + // Validate the IPN. |
|
119 | + $posted['cmd'] = '_notify-validate'; |
|
120 | + |
|
121 | + // Send back post vars to paypal. |
|
122 | + $params = array( |
|
123 | + 'body' => $posted, |
|
124 | + 'timeout' => 60, |
|
125 | + 'httpversion' => '1.1', |
|
126 | + 'compress' => false, |
|
127 | + 'decompress' => false, |
|
128 | + 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
129 | + ); |
|
130 | + |
|
131 | + // Post back to get a response. |
|
132 | + $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
133 | + |
|
134 | + // Check to see if the request was valid. |
|
135 | + if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
136 | + wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
137 | + return true; |
|
138 | + } |
|
139 | + |
|
140 | + if ( is_wp_error( $response ) ) { |
|
141 | + wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
142 | + return false; |
|
143 | + } |
|
144 | + |
|
145 | + wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
146 | + return false; |
|
147 | + |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Check currency from IPN matches the invoice. |
|
152 | + * |
|
153 | + * @param WPInv_Invoice $invoice Invoice object. |
|
154 | + * @param string $currency currency to validate. |
|
155 | + */ |
|
156 | + protected function validate_ipn_currency( $invoice, $currency ) { |
|
157 | 157 | |
158 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
158 | + if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
159 | 159 | |
160 | - /* translators: %s: currency code. */ |
|
161 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
160 | + /* translators: %s: currency code. */ |
|
161 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
162 | 162 | |
163 | - wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
164 | - } |
|
163 | + wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
164 | + } |
|
165 | 165 | |
166 | - wpinv_error_log( $currency, 'Validated IPN Currency', false ); |
|
167 | - } |
|
166 | + wpinv_error_log( $currency, 'Validated IPN Currency', false ); |
|
167 | + } |
|
168 | 168 | |
169 | - /** |
|
170 | - * Check payment amount from IPN matches the invoice. |
|
171 | - * |
|
172 | - * @param WPInv_Invoice $invoice Invoice object. |
|
173 | - * @param float $amount amount to validate. |
|
174 | - */ |
|
175 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
176 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
169 | + /** |
|
170 | + * Check payment amount from IPN matches the invoice. |
|
171 | + * |
|
172 | + * @param WPInv_Invoice $invoice Invoice object. |
|
173 | + * @param float $amount amount to validate. |
|
174 | + */ |
|
175 | + protected function validate_ipn_amount( $invoice, $amount ) { |
|
176 | + if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
177 | 177 | |
178 | - /* translators: %s: Amount. */ |
|
179 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
178 | + /* translators: %s: Amount. */ |
|
179 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
180 | 180 | |
181 | - wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
182 | - } |
|
181 | + wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
182 | + } |
|
183 | 183 | |
184 | - wpinv_error_log( $amount, 'Validated IPN Amount', false ); |
|
185 | - } |
|
184 | + wpinv_error_log( $amount, 'Validated IPN Amount', false ); |
|
185 | + } |
|
186 | 186 | |
187 | - /** |
|
188 | - * Verify receiver email from PayPal. |
|
189 | - * |
|
190 | - * @param WPInv_Invoice $invoice Invoice object. |
|
191 | - * @param string $receiver_email Email to validate. |
|
192 | - */ |
|
193 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
194 | - $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
187 | + /** |
|
188 | + * Verify receiver email from PayPal. |
|
189 | + * |
|
190 | + * @param WPInv_Invoice $invoice Invoice object. |
|
191 | + * @param string $receiver_email Email to validate. |
|
192 | + */ |
|
193 | + protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
194 | + $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
195 | 195 | |
196 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
197 | - wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
196 | + if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
197 | + wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
198 | 198 | |
199 | - /* translators: %s: email address . */ |
|
200 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
199 | + /* translators: %s: email address . */ |
|
200 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
201 | 201 | |
202 | - return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
203 | - } |
|
202 | + return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
203 | + } |
|
204 | 204 | |
205 | - wpinv_error_log( 'Validated PayPal Email', false ); |
|
206 | - } |
|
205 | + wpinv_error_log( 'Validated PayPal Email', false ); |
|
206 | + } |
|
207 | 207 | |
208 | - /** |
|
209 | - * Handles one time payments. |
|
210 | - * |
|
211 | - * @param WPInv_Invoice $invoice Invoice object. |
|
212 | - * @param array $posted Posted data. |
|
213 | - */ |
|
214 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
208 | + /** |
|
209 | + * Handles one time payments. |
|
210 | + * |
|
211 | + * @param WPInv_Invoice $invoice Invoice object. |
|
212 | + * @param array $posted Posted data. |
|
213 | + */ |
|
214 | + protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
215 | 215 | |
216 | - // Collect payment details |
|
217 | - $payment_status = strtolower( $posted['payment_status'] ); |
|
218 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
216 | + // Collect payment details |
|
217 | + $payment_status = strtolower( $posted['payment_status'] ); |
|
218 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
219 | 219 | |
220 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
221 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
220 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
221 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
222 | 222 | |
223 | - // Update the transaction id. |
|
224 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
225 | - $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
226 | - $invoice->save(); |
|
227 | - } |
|
223 | + // Update the transaction id. |
|
224 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
225 | + $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
226 | + $invoice->save(); |
|
227 | + } |
|
228 | 228 | |
229 | - $invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) ); |
|
229 | + $invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) ); |
|
230 | 230 | |
231 | - // Process a refund. |
|
232 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
231 | + // Process a refund. |
|
232 | + if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
233 | 233 | |
234 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
234 | + update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
235 | 235 | |
236 | - if ( ! $invoice->is_refunded() ) { |
|
237 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
238 | - } |
|
236 | + if ( ! $invoice->is_refunded() ) { |
|
237 | + $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
238 | + } |
|
239 | 239 | |
240 | - return wpinv_error_log( $posted['reason_code'], false ); |
|
241 | - } |
|
240 | + return wpinv_error_log( $posted['reason_code'], false ); |
|
241 | + } |
|
242 | 242 | |
243 | - // Process payments. |
|
244 | - if ( $payment_status == 'completed' ) { |
|
243 | + // Process payments. |
|
244 | + if ( $payment_status == 'completed' ) { |
|
245 | 245 | |
246 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
247 | - return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
248 | - } |
|
246 | + if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
247 | + return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
248 | + } |
|
249 | 249 | |
250 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
250 | + $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
251 | 251 | |
252 | - $note = ''; |
|
252 | + $note = ''; |
|
253 | 253 | |
254 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
255 | - $note = sprintf( __( 'PayPal Transaction Fee %s.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
256 | - } |
|
254 | + if ( ! empty( $posted['mc_fee'] ) ) { |
|
255 | + $note = sprintf( __( 'PayPal Transaction Fee %s.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
256 | + } |
|
257 | 257 | |
258 | - if ( ! empty( $posted['payer_status'] ) ) { |
|
259 | - $note = ' ' . sprintf( __( 'Buyer status %s.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
260 | - } |
|
258 | + if ( ! empty( $posted['payer_status'] ) ) { |
|
259 | + $note = ' ' . sprintf( __( 'Buyer status %s.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
260 | + } |
|
261 | 261 | |
262 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
263 | - return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
262 | + $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
263 | + return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
264 | 264 | |
265 | - } |
|
265 | + } |
|
266 | 266 | |
267 | - // Pending payments. |
|
268 | - if ( $payment_status == 'pending' ) { |
|
267 | + // Pending payments. |
|
268 | + if ( $payment_status == 'pending' ) { |
|
269 | 269 | |
270 | - /* translators: %s: pending reason. */ |
|
271 | - $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
270 | + /* translators: %s: pending reason. */ |
|
271 | + $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
272 | 272 | |
273 | - return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
274 | - } |
|
273 | + return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
274 | + } |
|
275 | 275 | |
276 | - /* translators: %s: payment status. */ |
|
277 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
276 | + /* translators: %s: payment status. */ |
|
277 | + $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
278 | 278 | |
279 | - } |
|
279 | + } |
|
280 | 280 | |
281 | - /** |
|
282 | - * Handles one time payments. |
|
283 | - * |
|
284 | - * @param WPInv_Invoice $invoice Invoice object. |
|
285 | - * @param array $posted Posted data. |
|
286 | - */ |
|
287 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
288 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
289 | - } |
|
281 | + /** |
|
282 | + * Handles one time payments. |
|
283 | + * |
|
284 | + * @param WPInv_Invoice $invoice Invoice object. |
|
285 | + * @param array $posted Posted data. |
|
286 | + */ |
|
287 | + protected function ipn_txn_cart( $invoice, $posted ) { |
|
288 | + $this->ipn_txn_web_accept( $invoice, $posted ); |
|
289 | + } |
|
290 | 290 | |
291 | - /** |
|
292 | - * Handles subscription sign ups. |
|
293 | - * |
|
294 | - * @param WPInv_Invoice $invoice Invoice object. |
|
295 | - * @param array $posted Posted data. |
|
296 | - */ |
|
297 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
291 | + /** |
|
292 | + * Handles subscription sign ups. |
|
293 | + * |
|
294 | + * @param WPInv_Invoice $invoice Invoice object. |
|
295 | + * @param array $posted Posted data. |
|
296 | + */ |
|
297 | + protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
298 | 298 | |
299 | - wpinv_error_log( 'Processing subscription signup', false ); |
|
299 | + wpinv_error_log( 'Processing subscription signup', false ); |
|
300 | 300 | |
301 | - // Make sure the invoice has a subscription. |
|
302 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
301 | + // Make sure the invoice has a subscription. |
|
302 | + $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
303 | 303 | |
304 | - if ( empty( $subscription ) ) { |
|
305 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
306 | - } |
|
304 | + if ( empty( $subscription ) ) { |
|
305 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
306 | + } |
|
307 | 307 | |
308 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
308 | + wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
309 | 309 | |
310 | - // Validate the IPN. |
|
311 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
312 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
313 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
310 | + // Validate the IPN. |
|
311 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
312 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
313 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
314 | 314 | |
315 | - // Activate the subscription. |
|
316 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
317 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
318 | - $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
319 | - $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
320 | - $subscription->activate(); |
|
315 | + // Activate the subscription. |
|
316 | + $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
317 | + $subscription->set_date_created( current_time( 'mysql' ) ); |
|
318 | + $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
319 | + $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
320 | + $subscription->activate(); |
|
321 | 321 | |
322 | - // Set the transaction id. |
|
323 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
324 | - $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
325 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
326 | - } |
|
322 | + // Set the transaction id. |
|
323 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
324 | + $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
325 | + $invoice->set_transaction_id( $posted['txn_id'] ); |
|
326 | + } |
|
327 | 327 | |
328 | - // Update the payment status. |
|
329 | - $invoice->mark_paid(); |
|
328 | + // Update the payment status. |
|
329 | + $invoice->mark_paid(); |
|
330 | 330 | |
331 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
331 | + $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
332 | 332 | |
333 | - wpinv_error_log( 'Subscription started.', false ); |
|
334 | - } |
|
333 | + wpinv_error_log( 'Subscription started.', false ); |
|
334 | + } |
|
335 | 335 | |
336 | - /** |
|
337 | - * Handles subscription renewals. |
|
338 | - * |
|
339 | - * @param WPInv_Invoice $invoice Invoice object. |
|
340 | - * @param array $posted Posted data. |
|
341 | - */ |
|
342 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
336 | + /** |
|
337 | + * Handles subscription renewals. |
|
338 | + * |
|
339 | + * @param WPInv_Invoice $invoice Invoice object. |
|
340 | + * @param array $posted Posted data. |
|
341 | + */ |
|
342 | + protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
343 | 343 | |
344 | - // Make sure the invoice has a subscription. |
|
345 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
344 | + // Make sure the invoice has a subscription. |
|
345 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
346 | 346 | |
347 | - if ( empty( $subscription ) ) { |
|
348 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
349 | - } |
|
347 | + if ( empty( $subscription ) ) { |
|
348 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
349 | + } |
|
350 | 350 | |
351 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
351 | + wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
352 | 352 | |
353 | - // PayPal sends a subscr_payment for the first payment too. |
|
354 | - $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
355 | - $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
356 | - $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
357 | - $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
358 | - $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
359 | - $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
353 | + // PayPal sends a subscr_payment for the first payment too. |
|
354 | + $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
355 | + $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
356 | + $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
357 | + $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
358 | + $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
359 | + $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
360 | 360 | |
361 | - foreach ( $dates as $date ) { |
|
361 | + foreach ( $dates as $date ) { |
|
362 | 362 | |
363 | - if ( $date !== $today_date && $date !== $payment_date ) { |
|
364 | - continue; |
|
365 | - } |
|
363 | + if ( $date !== $today_date && $date !== $payment_date ) { |
|
364 | + continue; |
|
365 | + } |
|
366 | 366 | |
367 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
368 | - $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
369 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
370 | - } |
|
367 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
368 | + $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
369 | + $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
370 | + } |
|
371 | 371 | |
372 | - return $invoice->mark_paid(); |
|
373 | - |
|
374 | - } |
|
372 | + return $invoice->mark_paid(); |
|
373 | + |
|
374 | + } |
|
375 | 375 | |
376 | - wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
377 | - |
|
378 | - // Abort if the payment is already recorded. |
|
379 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
380 | - return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false ); |
|
381 | - } |
|
382 | - |
|
383 | - $args = array( |
|
384 | - 'transaction_id' => $posted['txn_id'], |
|
385 | - 'gateway' => $this->id, |
|
386 | - ); |
|
387 | - |
|
388 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
376 | + wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
377 | + |
|
378 | + // Abort if the payment is already recorded. |
|
379 | + if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
380 | + return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false ); |
|
381 | + } |
|
382 | + |
|
383 | + $args = array( |
|
384 | + 'transaction_id' => $posted['txn_id'], |
|
385 | + 'gateway' => $this->id, |
|
386 | + ); |
|
387 | + |
|
388 | + $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
389 | 389 | |
390 | - if ( empty( $invoice ) ) { |
|
391 | - return; |
|
392 | - } |
|
390 | + if ( empty( $invoice ) ) { |
|
391 | + return; |
|
392 | + } |
|
393 | 393 | |
394 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
395 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
394 | + $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
395 | + $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
396 | 396 | |
397 | - $subscription->renew(); |
|
398 | - wpinv_error_log( 'Subscription renewed.', false ); |
|
397 | + $subscription->renew(); |
|
398 | + wpinv_error_log( 'Subscription renewed.', false ); |
|
399 | 399 | |
400 | - } |
|
400 | + } |
|
401 | 401 | |
402 | - /** |
|
403 | - * Handles subscription cancelations. |
|
404 | - * |
|
405 | - * @param WPInv_Invoice $invoice Invoice object. |
|
406 | - */ |
|
407 | - protected function ipn_txn_subscr_cancel( $invoice ) { |
|
402 | + /** |
|
403 | + * Handles subscription cancelations. |
|
404 | + * |
|
405 | + * @param WPInv_Invoice $invoice Invoice object. |
|
406 | + */ |
|
407 | + protected function ipn_txn_subscr_cancel( $invoice ) { |
|
408 | 408 | |
409 | - // Make sure the invoice has a subscription. |
|
410 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
411 | - |
|
412 | - if ( empty( $subscription ) ) { |
|
413 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
414 | - } |
|
415 | - |
|
416 | - wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
417 | - $subscription->cancel(); |
|
418 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
409 | + // Make sure the invoice has a subscription. |
|
410 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
411 | + |
|
412 | + if ( empty( $subscription ) ) { |
|
413 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
414 | + } |
|
415 | + |
|
416 | + wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
417 | + $subscription->cancel(); |
|
418 | + wpinv_error_log( 'Subscription cancelled.', false ); |
|
419 | 419 | |
420 | - } |
|
420 | + } |
|
421 | 421 | |
422 | - /** |
|
423 | - * Handles subscription completions. |
|
424 | - * |
|
425 | - * @param WPInv_Invoice $invoice Invoice object. |
|
426 | - * @param array $posted Posted data. |
|
427 | - */ |
|
428 | - protected function ipn_txn_subscr_eot( $invoice ) { |
|
422 | + /** |
|
423 | + * Handles subscription completions. |
|
424 | + * |
|
425 | + * @param WPInv_Invoice $invoice Invoice object. |
|
426 | + * @param array $posted Posted data. |
|
427 | + */ |
|
428 | + protected function ipn_txn_subscr_eot( $invoice ) { |
|
429 | 429 | |
430 | - // Make sure the invoice has a subscription. |
|
431 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
430 | + // Make sure the invoice has a subscription. |
|
431 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
432 | 432 | |
433 | - if ( empty( $subscription ) ) { |
|
434 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
435 | - } |
|
433 | + if ( empty( $subscription ) ) { |
|
434 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
435 | + } |
|
436 | 436 | |
437 | - wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
438 | - $subscription->complete(); |
|
439 | - wpinv_error_log( 'Subscription completed.', false ); |
|
437 | + wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
438 | + $subscription->complete(); |
|
439 | + wpinv_error_log( 'Subscription completed.', false ); |
|
440 | 440 | |
441 | - } |
|
441 | + } |
|
442 | 442 | |
443 | - /** |
|
444 | - * Handles subscription fails. |
|
445 | - * |
|
446 | - * @param WPInv_Invoice $invoice Invoice object. |
|
447 | - * @param array $posted Posted data. |
|
448 | - */ |
|
449 | - protected function ipn_txn_subscr_failed( $invoice ) { |
|
443 | + /** |
|
444 | + * Handles subscription fails. |
|
445 | + * |
|
446 | + * @param WPInv_Invoice $invoice Invoice object. |
|
447 | + * @param array $posted Posted data. |
|
448 | + */ |
|
449 | + protected function ipn_txn_subscr_failed( $invoice ) { |
|
450 | 450 | |
451 | - // Make sure the invoice has a subscription. |
|
452 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
451 | + // Make sure the invoice has a subscription. |
|
452 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
453 | 453 | |
454 | - if ( empty( $subscription ) ) { |
|
455 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
456 | - } |
|
454 | + if ( empty( $subscription ) ) { |
|
455 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
456 | + } |
|
457 | 457 | |
458 | - wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
459 | - $subscription->failing(); |
|
460 | - wpinv_error_log( 'Subscription marked as failing.', false ); |
|
458 | + wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
459 | + $subscription->failing(); |
|
460 | + wpinv_error_log( 'Subscription marked as failing.', false ); |
|
461 | 461 | |
462 | - } |
|
462 | + } |
|
463 | 463 | |
464 | - /** |
|
465 | - * Handles subscription suspensions. |
|
466 | - * |
|
467 | - * @param WPInv_Invoice $invoice Invoice object. |
|
468 | - * @param array $posted Posted data. |
|
469 | - */ |
|
470 | - protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
464 | + /** |
|
465 | + * Handles subscription suspensions. |
|
466 | + * |
|
467 | + * @param WPInv_Invoice $invoice Invoice object. |
|
468 | + * @param array $posted Posted data. |
|
469 | + */ |
|
470 | + protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
471 | 471 | |
472 | - // Make sure the invoice has a subscription. |
|
473 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
472 | + // Make sure the invoice has a subscription. |
|
473 | + $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
474 | 474 | |
475 | - if ( empty( $subscription ) ) { |
|
476 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
477 | - } |
|
478 | - |
|
479 | - wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
480 | - $subscription->cancel(); |
|
481 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
482 | - } |
|
475 | + if ( empty( $subscription ) ) { |
|
476 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
477 | + } |
|
478 | + |
|
479 | + wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
480 | + $subscription->cancel(); |
|
481 | + wpinv_error_log( 'Subscription cancelled.', false ); |
|
482 | + } |
|
483 | 483 | |
484 | 484 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Paypal Payment Gateway IPN handler class. |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * |
32 | 32 | * @param GetPaid_Paypal_Gateway $gateway |
33 | 33 | */ |
34 | - public function __construct( $gateway ) { |
|
34 | + public function __construct($gateway) { |
|
35 | 35 | $this->gateway = $gateway; |
36 | 36 | $this->verify_ipn(); |
37 | 37 | } |
@@ -43,37 +43,37 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function verify_ipn() { |
45 | 45 | |
46 | - wpinv_error_log( 'GetPaid PayPal IPN Handler', false ); |
|
46 | + wpinv_error_log('GetPaid PayPal IPN Handler', false); |
|
47 | 47 | |
48 | 48 | // Validate the IPN. |
49 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
50 | - wp_die( 'PayPal IPN Request Failure', 500 ); |
|
49 | + if (empty($_POST) || !$this->validate_ipn()) { |
|
50 | + wp_die('PayPal IPN Request Failure', 500); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | // Process the IPN. |
54 | - $posted = wp_unslash( $_POST ); |
|
55 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
54 | + $posted = wp_unslash($_POST); |
|
55 | + $invoice = $this->get_ipn_invoice($posted); |
|
56 | 56 | |
57 | 57 | // Abort if it was not paid by our gateway. |
58 | - if ( $this->id != $invoice->get_gateway() ) { |
|
59 | - wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false ); |
|
60 | - wp_die( 'Invoice not paid via PayPal', 200 ); |
|
58 | + if ($this->id != $invoice->get_gateway()) { |
|
59 | + wpinv_error_log('Aborting, Invoice was not paid via PayPal', false); |
|
60 | + wp_die('Invoice not paid via PayPal', 200); |
|
61 | 61 | } |
62 | 62 | |
63 | - $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
64 | - $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
63 | + $posted['payment_status'] = isset($posted['payment_status']) ? sanitize_key(strtolower($posted['payment_status'])) : ''; |
|
64 | + $posted['txn_type'] = sanitize_key(strtolower($posted['txn_type'])); |
|
65 | 65 | |
66 | - wpinv_error_log( 'Payment status:' . $posted['payment_status'], false ); |
|
67 | - wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false ); |
|
66 | + wpinv_error_log('Payment status:' . $posted['payment_status'], false); |
|
67 | + wpinv_error_log('IPN Type:' . $posted['txn_type'], false); |
|
68 | 68 | |
69 | - if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
70 | - call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
71 | - wpinv_error_log( 'Done processing IPN', false ); |
|
72 | - wp_die( 'Processed', 200 ); |
|
69 | + if (method_exists($this, 'ipn_txn_' . $posted['txn_type'])) { |
|
70 | + call_user_func(array($this, 'ipn_txn_' . $posted['txn_type']), $invoice, $posted); |
|
71 | + wpinv_error_log('Done processing IPN', false); |
|
72 | + wp_die('Processed', 200); |
|
73 | 73 | } |
74 | 74 | |
75 | - wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false ); |
|
76 | - wp_die( 'Unsupported IPN type', 200 ); |
|
75 | + wpinv_error_log('Aborting, Unsupported IPN type:' . $posted['txn_type'], false); |
|
76 | + wp_die('Unsupported IPN type', 200); |
|
77 | 77 | |
78 | 78 | } |
79 | 79 | |
@@ -83,21 +83,21 @@ discard block |
||
83 | 83 | * @param array $posted |
84 | 84 | * @return WPInv_Invoice |
85 | 85 | */ |
86 | - protected function get_ipn_invoice( $posted ) { |
|
86 | + protected function get_ipn_invoice($posted) { |
|
87 | 87 | |
88 | - wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false ); |
|
88 | + wpinv_error_log('Retrieving PayPal IPN Response Invoice', false); |
|
89 | 89 | |
90 | - if ( ! empty( $posted['custom'] ) ) { |
|
91 | - $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
90 | + if (!empty($posted['custom'])) { |
|
91 | + $invoice = new WPInv_Invoice($posted['custom']); |
|
92 | 92 | |
93 | - if ( $invoice->exists() ) { |
|
94 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false ); |
|
93 | + if ($invoice->exists()) { |
|
94 | + wpinv_error_log('Found invoice #' . $invoice->get_number(), false); |
|
95 | 95 | return $invoice; |
96 | 96 | } |
97 | 97 | } |
98 | 98 | |
99 | - wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
100 | - wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
99 | + wpinv_error_log('Could not retrieve the associated invoice.', false); |
|
100 | + wp_die('Could not retrieve the associated invoice.', 200); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -105,14 +105,14 @@ discard block |
||
105 | 105 | */ |
106 | 106 | protected function validate_ipn() { |
107 | 107 | |
108 | - wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
108 | + wpinv_error_log('Validating PayPal IPN response', false); |
|
109 | 109 | |
110 | 110 | // Retrieve the associated invoice. |
111 | - $posted = wp_unslash( $_POST ); |
|
112 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
111 | + $posted = wp_unslash($_POST); |
|
112 | + $invoice = $this->get_ipn_invoice($posted); |
|
113 | 113 | |
114 | - if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
115 | - wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false ); |
|
114 | + if ($this->gateway->is_sandbox($invoice)) { |
|
115 | + wpinv_error_log($posted, 'Invoice was processed in sandbox hence logging the posted data', false); |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | // Validate the IPN. |
@@ -129,20 +129,20 @@ discard block |
||
129 | 129 | ); |
130 | 130 | |
131 | 131 | // Post back to get a response. |
132 | - $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
132 | + $response = wp_safe_remote_post($this->gateway->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params); |
|
133 | 133 | |
134 | 134 | // Check to see if the request was valid. |
135 | - if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
136 | - wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
135 | + if (!is_wp_error($response) && $response['response']['code'] < 300 && strstr($response['body'], 'VERIFIED')) { |
|
136 | + wpinv_error_log('Received valid response from PayPal IPN: ' . $response['body'], false); |
|
137 | 137 | return true; |
138 | 138 | } |
139 | 139 | |
140 | - if ( is_wp_error( $response ) ) { |
|
141 | - wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
140 | + if (is_wp_error($response)) { |
|
141 | + wpinv_error_log($response->get_error_message(), 'Received invalid response from PayPal IPN'); |
|
142 | 142 | return false; |
143 | 143 | } |
144 | 144 | |
145 | - wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
145 | + wpinv_error_log($response['body'], 'Received invalid response from PayPal IPN'); |
|
146 | 146 | return false; |
147 | 147 | |
148 | 148 | } |
@@ -153,17 +153,17 @@ discard block |
||
153 | 153 | * @param WPInv_Invoice $invoice Invoice object. |
154 | 154 | * @param string $currency currency to validate. |
155 | 155 | */ |
156 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
156 | + protected function validate_ipn_currency($invoice, $currency) { |
|
157 | 157 | |
158 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
158 | + if (strtolower($invoice->get_currency()) !== strtolower($currency)) { |
|
159 | 159 | |
160 | 160 | /* translators: %s: currency code. */ |
161 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
161 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal currencies do not match (code %s).', 'invoicing'), $currency)); |
|
162 | 162 | |
163 | - wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
163 | + wpinv_error_log("Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true); |
|
164 | 164 | } |
165 | 165 | |
166 | - wpinv_error_log( $currency, 'Validated IPN Currency', false ); |
|
166 | + wpinv_error_log($currency, 'Validated IPN Currency', false); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
@@ -172,16 +172,16 @@ discard block |
||
172 | 172 | * @param WPInv_Invoice $invoice Invoice object. |
173 | 173 | * @param float $amount amount to validate. |
174 | 174 | */ |
175 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
176 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
175 | + protected function validate_ipn_amount($invoice, $amount) { |
|
176 | + if (number_format($invoice->get_total(), 2, '.', '') !== number_format($amount, 2, '.', '')) { |
|
177 | 177 | |
178 | 178 | /* translators: %s: Amount. */ |
179 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
179 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal amounts do not match (gross %s).', 'invoicing'), $amount)); |
|
180 | 180 | |
181 | - wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
181 | + wpinv_error_log("Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true); |
|
182 | 182 | } |
183 | 183 | |
184 | - wpinv_error_log( $amount, 'Validated IPN Amount', false ); |
|
184 | + wpinv_error_log($amount, 'Validated IPN Amount', false); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | /** |
@@ -190,19 +190,19 @@ discard block |
||
190 | 190 | * @param WPInv_Invoice $invoice Invoice object. |
191 | 191 | * @param string $receiver_email Email to validate. |
192 | 192 | */ |
193 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
194 | - $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
193 | + protected function validate_ipn_receiver_email($invoice, $receiver_email) { |
|
194 | + $paypal_email = wpinv_get_option('paypal_email'); |
|
195 | 195 | |
196 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
197 | - wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
196 | + if (strcasecmp(trim($receiver_email), trim($paypal_email)) !== 0) { |
|
197 | + wpinv_record_gateway_error('IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}"); |
|
198 | 198 | |
199 | 199 | /* translators: %s: email address . */ |
200 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
200 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal IPN response from a different email address (%s).', 'invoicing'), $receiver_email)); |
|
201 | 201 | |
202 | - return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
202 | + return wpinv_error_log("IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true); |
|
203 | 203 | } |
204 | 204 | |
205 | - wpinv_error_log( 'Validated PayPal Email', false ); |
|
205 | + wpinv_error_log('Validated PayPal Email', false); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | /** |
@@ -211,70 +211,70 @@ discard block |
||
211 | 211 | * @param WPInv_Invoice $invoice Invoice object. |
212 | 212 | * @param array $posted Posted data. |
213 | 213 | */ |
214 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
214 | + protected function ipn_txn_web_accept($invoice, $posted) { |
|
215 | 215 | |
216 | 216 | // Collect payment details |
217 | - $payment_status = strtolower( $posted['payment_status'] ); |
|
218 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
217 | + $payment_status = strtolower($posted['payment_status']); |
|
218 | + $business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']); |
|
219 | 219 | |
220 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
221 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
220 | + $this->validate_ipn_receiver_email($invoice, $business_email); |
|
221 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
222 | 222 | |
223 | 223 | // Update the transaction id. |
224 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
225 | - $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
224 | + if (!empty($posted['txn_id'])) { |
|
225 | + $invoice->set_transaction_id(wpinv_clean($posted['txn_id'])); |
|
226 | 226 | $invoice->save(); |
227 | 227 | } |
228 | 228 | |
229 | - $invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) ); |
|
229 | + $invoice->add_system_note(__('Processing invoice IPN', 'invoicing')); |
|
230 | 230 | |
231 | 231 | // Process a refund. |
232 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
232 | + if ($payment_status == 'refunded' || $payment_status == 'reversed') { |
|
233 | 233 | |
234 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
234 | + update_post_meta($invoice->get_id(), 'refunded_remotely', 1); |
|
235 | 235 | |
236 | - if ( ! $invoice->is_refunded() ) { |
|
237 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
236 | + if (!$invoice->is_refunded()) { |
|
237 | + $invoice->update_status('wpi-refunded', $posted['reason_code']); |
|
238 | 238 | } |
239 | 239 | |
240 | - return wpinv_error_log( $posted['reason_code'], false ); |
|
240 | + return wpinv_error_log($posted['reason_code'], false); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | // Process payments. |
244 | - if ( $payment_status == 'completed' ) { |
|
244 | + if ($payment_status == 'completed') { |
|
245 | 245 | |
246 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
247 | - return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
246 | + if ($invoice->is_paid() && 'wpi_processing' != $invoice->get_status()) { |
|
247 | + return wpinv_error_log('Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false); |
|
248 | 248 | } |
249 | 249 | |
250 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
250 | + $this->validate_ipn_amount($invoice, $posted['mc_gross']); |
|
251 | 251 | |
252 | 252 | $note = ''; |
253 | 253 | |
254 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
255 | - $note = sprintf( __( 'PayPal Transaction Fee %s.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
254 | + if (!empty($posted['mc_fee'])) { |
|
255 | + $note = sprintf(__('PayPal Transaction Fee %s.', 'invoicing'), sanitize_text_field($posted['mc_fee'])); |
|
256 | 256 | } |
257 | 257 | |
258 | - if ( ! empty( $posted['payer_status'] ) ) { |
|
259 | - $note = ' ' . sprintf( __( 'Buyer status %s.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
258 | + if (!empty($posted['payer_status'])) { |
|
259 | + $note = ' ' . sprintf(__('Buyer status %s.', 'invoicing'), sanitize_text_field($posted['payer_status'])); |
|
260 | 260 | } |
261 | 261 | |
262 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
263 | - return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
262 | + $invoice->mark_paid((!empty($posted['txn_id']) ? sanitize_text_field($posted['txn_id']) : ''), trim($note)); |
|
263 | + return wpinv_error_log('Invoice marked as paid.', false); |
|
264 | 264 | |
265 | 265 | } |
266 | 266 | |
267 | 267 | // Pending payments. |
268 | - if ( $payment_status == 'pending' ) { |
|
268 | + if ($payment_status == 'pending') { |
|
269 | 269 | |
270 | 270 | /* translators: %s: pending reason. */ |
271 | - $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
271 | + $invoice->update_status('wpi-onhold', sprintf(__('Payment pending (%s).', 'invoicing'), $posted['pending_reason'])); |
|
272 | 272 | |
273 | - return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
273 | + return wpinv_error_log('Invoice marked as "payment held".', false); |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | /* translators: %s: payment status. */ |
277 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
277 | + $invoice->update_status('wpi-failed', sprintf(__('Payment %s via IPN.', 'invoicing'), sanitize_text_field($posted['payment_status']))); |
|
278 | 278 | |
279 | 279 | } |
280 | 280 | |
@@ -284,8 +284,8 @@ discard block |
||
284 | 284 | * @param WPInv_Invoice $invoice Invoice object. |
285 | 285 | * @param array $posted Posted data. |
286 | 286 | */ |
287 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
288 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
287 | + protected function ipn_txn_cart($invoice, $posted) { |
|
288 | + $this->ipn_txn_web_accept($invoice, $posted); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | /** |
@@ -294,43 +294,43 @@ discard block |
||
294 | 294 | * @param WPInv_Invoice $invoice Invoice object. |
295 | 295 | * @param array $posted Posted data. |
296 | 296 | */ |
297 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
297 | + protected function ipn_txn_subscr_signup($invoice, $posted) { |
|
298 | 298 | |
299 | - wpinv_error_log( 'Processing subscription signup', false ); |
|
299 | + wpinv_error_log('Processing subscription signup', false); |
|
300 | 300 | |
301 | 301 | // Make sure the invoice has a subscription. |
302 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
302 | + $subscription = getpaid_get_invoice_subscription($invoice); |
|
303 | 303 | |
304 | - if ( empty( $subscription ) ) { |
|
305 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
304 | + if (empty($subscription)) { |
|
305 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
306 | 306 | } |
307 | 307 | |
308 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
308 | + wpinv_error_log('Found subscription #' . $subscription->get_id(), false); |
|
309 | 309 | |
310 | 310 | // Validate the IPN. |
311 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
312 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
313 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
311 | + $business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']); |
|
312 | + $this->validate_ipn_receiver_email($invoice, $business_email); |
|
313 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
314 | 314 | |
315 | 315 | // Activate the subscription. |
316 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
317 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
318 | - $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
319 | - $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
316 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
317 | + $subscription->set_date_created(current_time('mysql')); |
|
318 | + $subscription->set_expiration(date('Y-m-d H:i:s', (current_time('timestamp') + $duration))); |
|
319 | + $subscription->set_profile_id(sanitize_text_field($posted['subscr_id'])); |
|
320 | 320 | $subscription->activate(); |
321 | 321 | |
322 | 322 | // Set the transaction id. |
323 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
324 | - $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
325 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
323 | + if (!empty($posted['txn_id'])) { |
|
324 | + $invoice->add_note(sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true); |
|
325 | + $invoice->set_transaction_id($posted['txn_id']); |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | // Update the payment status. |
329 | 329 | $invoice->mark_paid(); |
330 | 330 | |
331 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
331 | + $invoice->add_note(sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
332 | 332 | |
333 | - wpinv_error_log( 'Subscription started.', false ); |
|
333 | + wpinv_error_log('Subscription started.', false); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | /** |
@@ -339,45 +339,45 @@ discard block |
||
339 | 339 | * @param WPInv_Invoice $invoice Invoice object. |
340 | 340 | * @param array $posted Posted data. |
341 | 341 | */ |
342 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
342 | + protected function ipn_txn_subscr_payment($invoice, $posted) { |
|
343 | 343 | |
344 | 344 | // Make sure the invoice has a subscription. |
345 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
345 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
346 | 346 | |
347 | - if ( empty( $subscription ) ) { |
|
348 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
347 | + if (empty($subscription)) { |
|
348 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
349 | 349 | } |
350 | 350 | |
351 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
351 | + wpinv_error_log('Found subscription #' . $subscription->get_id(), false); |
|
352 | 352 | |
353 | 353 | // PayPal sends a subscr_payment for the first payment too. |
354 | - $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
355 | - $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
356 | - $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
357 | - $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
358 | - $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
359 | - $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
354 | + $date_completed = getpaid_format_date($invoice->get_date_completed()); |
|
355 | + $date_created = getpaid_format_date($invoice->get_date_created()); |
|
356 | + $today_date = getpaid_format_date(current_time('mysql')); |
|
357 | + $payment_date = getpaid_format_date($posted['payment_date']); |
|
358 | + $subscribe_date = getpaid_format_date($subscription->get_date_created()); |
|
359 | + $dates = array_filter(compact('date_completed', 'date_created', 'subscribe_date')); |
|
360 | 360 | |
361 | - foreach ( $dates as $date ) { |
|
361 | + foreach ($dates as $date) { |
|
362 | 362 | |
363 | - if ( $date !== $today_date && $date !== $payment_date ) { |
|
363 | + if ($date !== $today_date && $date !== $payment_date) { |
|
364 | 364 | continue; |
365 | 365 | } |
366 | 366 | |
367 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
368 | - $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
369 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
367 | + if (!empty($posted['txn_id'])) { |
|
368 | + $invoice->set_transaction_id(sanitize_text_field($posted['txn_id'])); |
|
369 | + $invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), sanitize_text_field($posted['txn_id'])), false, false, true); |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | return $invoice->mark_paid(); |
373 | 373 | |
374 | 374 | } |
375 | 375 | |
376 | - wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
376 | + wpinv_error_log('Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false); |
|
377 | 377 | |
378 | 378 | // Abort if the payment is already recorded. |
379 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
380 | - return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false ); |
|
379 | + if (wpinv_get_id_by_transaction_id($posted['txn_id'])) { |
|
380 | + return wpinv_error_log('Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false); |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | $args = array( |
@@ -385,17 +385,17 @@ discard block |
||
385 | 385 | 'gateway' => $this->id, |
386 | 386 | ); |
387 | 387 | |
388 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
388 | + $invoice = wpinv_get_invoice($subscription->add_payment($args)); |
|
389 | 389 | |
390 | - if ( empty( $invoice ) ) { |
|
390 | + if (empty($invoice)) { |
|
391 | 391 | return; |
392 | 392 | } |
393 | 393 | |
394 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ), $posted['txn_id'] ), false, false, true ); |
|
395 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ), $posted['subscr_id'] ), false, false, true ); |
|
394 | + $invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true); |
|
395 | + $invoice->add_note(wp_sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
396 | 396 | |
397 | 397 | $subscription->renew(); |
398 | - wpinv_error_log( 'Subscription renewed.', false ); |
|
398 | + wpinv_error_log('Subscription renewed.', false); |
|
399 | 399 | |
400 | 400 | } |
401 | 401 | |
@@ -404,18 +404,18 @@ discard block |
||
404 | 404 | * |
405 | 405 | * @param WPInv_Invoice $invoice Invoice object. |
406 | 406 | */ |
407 | - protected function ipn_txn_subscr_cancel( $invoice ) { |
|
407 | + protected function ipn_txn_subscr_cancel($invoice) { |
|
408 | 408 | |
409 | 409 | // Make sure the invoice has a subscription. |
410 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
410 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
411 | 411 | |
412 | - if ( empty( $subscription ) ) { |
|
413 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
412 | + if (empty($subscription)) { |
|
413 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
414 | 414 | } |
415 | 415 | |
416 | - wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
416 | + wpinv_error_log('Processing subscription cancellation for the invoice ' . $invoice->get_id(), false); |
|
417 | 417 | $subscription->cancel(); |
418 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
418 | + wpinv_error_log('Subscription cancelled.', false); |
|
419 | 419 | |
420 | 420 | } |
421 | 421 | |
@@ -425,18 +425,18 @@ discard block |
||
425 | 425 | * @param WPInv_Invoice $invoice Invoice object. |
426 | 426 | * @param array $posted Posted data. |
427 | 427 | */ |
428 | - protected function ipn_txn_subscr_eot( $invoice ) { |
|
428 | + protected function ipn_txn_subscr_eot($invoice) { |
|
429 | 429 | |
430 | 430 | // Make sure the invoice has a subscription. |
431 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
431 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
432 | 432 | |
433 | - if ( empty( $subscription ) ) { |
|
434 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
433 | + if (empty($subscription)) { |
|
434 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
435 | 435 | } |
436 | 436 | |
437 | - wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
437 | + wpinv_error_log('Processing subscription end of life for the invoice ' . $invoice->get_id(), false); |
|
438 | 438 | $subscription->complete(); |
439 | - wpinv_error_log( 'Subscription completed.', false ); |
|
439 | + wpinv_error_log('Subscription completed.', false); |
|
440 | 440 | |
441 | 441 | } |
442 | 442 | |
@@ -446,18 +446,18 @@ discard block |
||
446 | 446 | * @param WPInv_Invoice $invoice Invoice object. |
447 | 447 | * @param array $posted Posted data. |
448 | 448 | */ |
449 | - protected function ipn_txn_subscr_failed( $invoice ) { |
|
449 | + protected function ipn_txn_subscr_failed($invoice) { |
|
450 | 450 | |
451 | 451 | // Make sure the invoice has a subscription. |
452 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
452 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
453 | 453 | |
454 | - if ( empty( $subscription ) ) { |
|
455 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
454 | + if (empty($subscription)) { |
|
455 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
456 | 456 | } |
457 | 457 | |
458 | - wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
458 | + wpinv_error_log('Processing subscription payment failure for the invoice ' . $invoice->get_id(), false); |
|
459 | 459 | $subscription->failing(); |
460 | - wpinv_error_log( 'Subscription marked as failing.', false ); |
|
460 | + wpinv_error_log('Subscription marked as failing.', false); |
|
461 | 461 | |
462 | 462 | } |
463 | 463 | |
@@ -467,18 +467,18 @@ discard block |
||
467 | 467 | * @param WPInv_Invoice $invoice Invoice object. |
468 | 468 | * @param array $posted Posted data. |
469 | 469 | */ |
470 | - protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
470 | + protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment($invoice) { |
|
471 | 471 | |
472 | 472 | // Make sure the invoice has a subscription. |
473 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
473 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
474 | 474 | |
475 | - if ( empty( $subscription ) ) { |
|
476 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
475 | + if (empty($subscription)) { |
|
476 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
477 | 477 | } |
478 | 478 | |
479 | - wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
479 | + wpinv_error_log('Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false); |
|
480 | 480 | $subscription->cancel(); |
481 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
481 | + wpinv_error_log('Subscription cancelled.', false); |
|
482 | 482 | } |
483 | 483 | |
484 | 484 | } |
@@ -19,16 +19,16 @@ discard block |
||
19 | 19 | |
20 | 20 | // Define constants. |
21 | 21 | if ( ! defined( 'WPINV_PLUGIN_FILE' ) ) { |
22 | - define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
22 | + define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | if ( ! defined( 'WPINV_VERSION' ) ) { |
26 | - define( 'WPINV_VERSION', '2.6.14' ); |
|
26 | + define( 'WPINV_VERSION', '2.6.14' ); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | // Include the main Invoicing class. |
30 | 30 | if ( ! class_exists( 'WPInv_Plugin', false ) ) { |
31 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php'; |
|
31 | + require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php'; |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | $GLOBALS['invoicing'] = new WPInv_Plugin(); |
44 | 44 | } |
45 | 45 | |
46 | - return $GLOBALS['invoicing']; |
|
46 | + return $GLOBALS['invoicing']; |
|
47 | 47 | } |
48 | 48 | |
49 | 49 | /** |
@@ -15,20 +15,20 @@ discard block |
||
15 | 15 | * @package GetPaid |
16 | 16 | */ |
17 | 17 | |
18 | -defined( 'ABSPATH' ) || exit; |
|
18 | +defined('ABSPATH') || exit; |
|
19 | 19 | |
20 | 20 | // Define constants. |
21 | -if ( ! defined( 'WPINV_PLUGIN_FILE' ) ) { |
|
22 | - define( 'WPINV_PLUGIN_FILE', __FILE__ ); |
|
21 | +if (!defined('WPINV_PLUGIN_FILE')) { |
|
22 | + define('WPINV_PLUGIN_FILE', __FILE__); |
|
23 | 23 | } |
24 | 24 | |
25 | -if ( ! defined( 'WPINV_VERSION' ) ) { |
|
26 | - define( 'WPINV_VERSION', '2.6.14' ); |
|
25 | +if (!defined('WPINV_VERSION')) { |
|
26 | + define('WPINV_VERSION', '2.6.14'); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | // Include the main Invoicing class. |
30 | -if ( ! class_exists( 'WPInv_Plugin', false ) ) { |
|
31 | - require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/class-wpinv.php'; |
|
30 | +if (!class_exists('WPInv_Plugin', false)) { |
|
31 | + require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/class-wpinv.php'; |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | */ |
40 | 40 | function getpaid() { |
41 | 41 | |
42 | - if ( empty( $GLOBALS['invoicing'] ) ) { |
|
42 | + if (empty($GLOBALS['invoicing'])) { |
|
43 | 43 | $GLOBALS['invoicing'] = new WPInv_Plugin(); |
44 | 44 | } |
45 | 45 | |
@@ -52,9 +52,9 @@ discard block |
||
52 | 52 | * @since 2.0.8 |
53 | 53 | */ |
54 | 54 | function getpaid_deactivation_hook() { |
55 | - update_option( 'wpinv_flush_permalinks', 1 ); |
|
55 | + update_option('wpinv_flush_permalinks', 1); |
|
56 | 56 | } |
57 | -register_deactivation_hook( __FILE__, 'getpaid_deactivation_hook' ); |
|
57 | +register_deactivation_hook(__FILE__, 'getpaid_deactivation_hook'); |
|
58 | 58 | |
59 | 59 | /** |
60 | 60 | * @deprecated |
@@ -64,4 +64,4 @@ discard block |
||
64 | 64 | } |
65 | 65 | |
66 | 66 | // Kickstart the plugin. |
67 | -add_action( 'plugins_loaded', 'getpaid', -100 ); |
|
67 | +add_action('plugins_loaded', 'getpaid', -100); |
@@ -13,7 +13,7 @@ discard block |
||
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,308 +21,308 @@ discard block |
||
21 | 21 | */ |
22 | 22 | if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) { |
23 | 23 | |
24 | - /** |
|
25 | - * A Class to be able to change settings for Font Awesome. |
|
26 | - * |
|
27 | - * Class WP_Font_Awesome_Settings |
|
28 | - * @since 1.0.10 Now able to pass wp.org theme check. |
|
29 | - * @since 1.0.11 Font Awesome Pro now supported. |
|
30 | - * @since 1.0.11 Font Awesome Kits now supported. |
|
31 | - * @since 1.0.13 RTL language support added. |
|
32 | - * @since 1.0.14 Warning added for v6 pro requires kit and will now not work if official FA plugin installed. |
|
33 | - * @ver 1.0.14 |
|
34 | - * @todo decide how to implement textdomain |
|
35 | - */ |
|
36 | - class WP_Font_Awesome_Settings { |
|
37 | - |
|
38 | - /** |
|
39 | - * Class version version. |
|
40 | - * |
|
41 | - * @var string |
|
42 | - */ |
|
43 | - public $version = '1.0.14'; |
|
44 | - |
|
45 | - /** |
|
46 | - * Class textdomain. |
|
47 | - * |
|
48 | - * @var string |
|
49 | - */ |
|
50 | - public $textdomain = 'font-awesome-settings'; |
|
51 | - |
|
52 | - /** |
|
53 | - * Latest version of Font Awesome at time of publish published. |
|
54 | - * |
|
55 | - * @var string |
|
56 | - */ |
|
57 | - public $latest = "5.8.2"; |
|
58 | - |
|
59 | - /** |
|
60 | - * The title. |
|
61 | - * |
|
62 | - * @var string |
|
63 | - */ |
|
64 | - public $name = 'Font Awesome'; |
|
65 | - |
|
66 | - /** |
|
67 | - * Holds the settings values. |
|
68 | - * |
|
69 | - * @var array |
|
70 | - */ |
|
71 | - private $settings; |
|
72 | - |
|
73 | - /** |
|
74 | - * WP_Font_Awesome_Settings instance. |
|
75 | - * |
|
76 | - * @access private |
|
77 | - * @since 1.0.0 |
|
78 | - * @var WP_Font_Awesome_Settings There can be only one! |
|
79 | - */ |
|
80 | - private static $instance = null; |
|
81 | - |
|
82 | - /** |
|
83 | - * Main WP_Font_Awesome_Settings Instance. |
|
84 | - * |
|
85 | - * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded. |
|
86 | - * |
|
87 | - * @since 1.0.0 |
|
88 | - * @static |
|
89 | - * @return WP_Font_Awesome_Settings - Main instance. |
|
90 | - */ |
|
91 | - public static function instance() { |
|
92 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
93 | - self::$instance = new WP_Font_Awesome_Settings; |
|
94 | - |
|
95 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
96 | - |
|
97 | - if ( is_admin() ) { |
|
98 | - add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
99 | - add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
100 | - add_action( 'admin_notices', array( self::$instance, 'admin_notices' ) ); |
|
101 | - } |
|
102 | - |
|
103 | - do_action( 'wp_font_awesome_settings_loaded' ); |
|
104 | - } |
|
105 | - |
|
106 | - return self::$instance; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Initiate the settings and add the required action hooks. |
|
111 | - * |
|
112 | - * @since 1.0.8 Settings name wrong - FIXED |
|
113 | - */ |
|
114 | - public function init() { |
|
115 | - $this->settings = $this->get_settings(); |
|
116 | - |
|
117 | - // check if the official plugin is active and use that instead if so. |
|
118 | - if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
119 | - |
|
120 | - if ( $this->settings['type'] == 'CSS' ) { |
|
121 | - |
|
122 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
123 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
124 | - } |
|
125 | - |
|
126 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
127 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
128 | - } |
|
129 | - |
|
130 | - } else { |
|
131 | - |
|
132 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
133 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
134 | - } |
|
135 | - |
|
136 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
137 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
138 | - } |
|
139 | - } |
|
140 | - |
|
141 | - // remove font awesome if set to do so |
|
142 | - if ( $this->settings['dequeue'] == '1' ) { |
|
143 | - add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
144 | - } |
|
145 | - } |
|
146 | - |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * Adds the Font Awesome styles. |
|
151 | - */ |
|
152 | - public function enqueue_style() { |
|
153 | - // build url |
|
154 | - $url = $this->get_url(); |
|
155 | - |
|
156 | - wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
157 | - wp_register_style( 'font-awesome', $url, array(), null ); |
|
158 | - wp_enqueue_style( 'font-awesome' ); |
|
159 | - |
|
160 | - // RTL language support CSS. |
|
161 | - if ( is_rtl() ) { |
|
162 | - wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() ); |
|
163 | - } |
|
164 | - |
|
165 | - if ( $this->settings['shims'] ) { |
|
166 | - $url = $this->get_url( true ); |
|
167 | - wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
168 | - wp_register_style( 'font-awesome-shims', $url, array(), null ); |
|
169 | - wp_enqueue_style( 'font-awesome-shims' ); |
|
170 | - } |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * Adds the Font Awesome JS. |
|
175 | - */ |
|
176 | - public function enqueue_scripts() { |
|
177 | - // build url |
|
178 | - $url = $this->get_url(); |
|
179 | - |
|
180 | - $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
|
181 | - call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
182 | - wp_register_script( 'font-awesome', $url, array(), null ); |
|
183 | - wp_enqueue_script( 'font-awesome' ); |
|
184 | - |
|
185 | - if ( $this->settings['shims'] ) { |
|
186 | - $url = $this->get_url( true ); |
|
187 | - call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
188 | - wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
189 | - wp_enqueue_script( 'font-awesome-shims' ); |
|
190 | - } |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Get the url of the Font Awesome files. |
|
195 | - * |
|
196 | - * @param bool $shims If this is a shim file or not. |
|
197 | - * |
|
198 | - * @return string The url to the file. |
|
199 | - */ |
|
200 | - public function get_url( $shims = false ) { |
|
201 | - $script = $shims ? 'v4-shims' : 'all'; |
|
202 | - $sub = $this->settings['pro'] ? 'pro' : 'use'; |
|
203 | - $type = $this->settings['type']; |
|
204 | - $version = $this->settings['version']; |
|
205 | - $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : ''; |
|
206 | - $url = ''; |
|
207 | - |
|
208 | - if ( $type == 'KIT' && $kit_url ) { |
|
209 | - if ( $shims ) { |
|
210 | - // if its a kit then we don't add shims here |
|
211 | - return ''; |
|
212 | - } |
|
213 | - $url .= $kit_url; // CDN |
|
214 | - $url .= "?wpfas=true"; // set our var so our version is not removed |
|
215 | - } else { |
|
216 | - $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
|
217 | - $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
218 | - $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
|
219 | - $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
|
220 | - $url .= "?wpfas=true"; // set our var so our version is not removed |
|
221 | - } |
|
222 | - |
|
223 | - return $url; |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * Try and remove any other versions of Font Awesome added by other plugins/themes. |
|
228 | - * |
|
229 | - * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version. |
|
230 | - * |
|
231 | - * @param $url |
|
232 | - * @param $original_url |
|
233 | - * @param $_context |
|
234 | - * |
|
235 | - * @return string The filtered url. |
|
236 | - */ |
|
237 | - public function remove_font_awesome( $url, $original_url, $_context ) { |
|
238 | - |
|
239 | - if ( $_context == 'display' |
|
240 | - && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
241 | - && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
242 | - ) {// it's a font-awesome-url (probably) |
|
243 | - |
|
244 | - if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
245 | - if ( $this->settings['type'] == 'JS' ) { |
|
246 | - if ( $this->settings['js-pseudo'] ) { |
|
247 | - $url .= "' data-search-pseudo-elements defer='defer"; |
|
248 | - } else { |
|
249 | - $url .= "' defer='defer"; |
|
250 | - } |
|
251 | - } |
|
252 | - } else { |
|
253 | - $url = ''; // removing the url removes the file |
|
254 | - } |
|
255 | - |
|
256 | - } |
|
257 | - |
|
258 | - return $url; |
|
259 | - } |
|
260 | - |
|
261 | - /** |
|
262 | - * Register the database settings with WordPress. |
|
263 | - */ |
|
264 | - public function register_settings() { |
|
265 | - register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
266 | - } |
|
267 | - |
|
268 | - /** |
|
269 | - * Add the WordPress settings menu item. |
|
270 | - * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
271 | - */ |
|
272 | - public function menu_item() { |
|
273 | - $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
274 | - call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
275 | - $this, |
|
276 | - 'settings_page' |
|
277 | - ) ); |
|
278 | - } |
|
279 | - |
|
280 | - /** |
|
281 | - * Get the current Font Awesome output settings. |
|
282 | - * |
|
283 | - * @return array The array of settings. |
|
284 | - */ |
|
285 | - public function get_settings() { |
|
286 | - |
|
287 | - $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
288 | - |
|
289 | - $defaults = array( |
|
290 | - 'type' => 'CSS', // type to use, CSS or JS or KIT |
|
291 | - 'version' => '', // latest |
|
292 | - 'enqueue' => '', // front and backend |
|
293 | - 'shims' => '0', // default OFF now in 2020 |
|
294 | - 'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive) |
|
295 | - 'dequeue' => '0', // if we should try to remove other versions added by other plugins/themes |
|
296 | - 'pro' => '0', // if pro CDN url should be used |
|
297 | - 'kit-url' => '', // the kit url |
|
298 | - ); |
|
299 | - |
|
300 | - $settings = wp_parse_args( $db_settings, $defaults ); |
|
301 | - |
|
302 | - /** |
|
303 | - * Filter the Font Awesome settings. |
|
304 | - * |
|
305 | - * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
306 | - */ |
|
307 | - return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
308 | - } |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * The settings page html output. |
|
313 | - */ |
|
314 | - public function settings_page() { |
|
315 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
316 | - wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) ); |
|
317 | - } |
|
318 | - |
|
319 | - // a hidden way to force the update of the version number via api instead of waiting the 48 hours |
|
320 | - if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
321 | - $this->get_latest_version( $force_api = true ); |
|
322 | - } |
|
323 | - |
|
324 | - if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
325 | - ?> |
|
24 | + /** |
|
25 | + * A Class to be able to change settings for Font Awesome. |
|
26 | + * |
|
27 | + * Class WP_Font_Awesome_Settings |
|
28 | + * @since 1.0.10 Now able to pass wp.org theme check. |
|
29 | + * @since 1.0.11 Font Awesome Pro now supported. |
|
30 | + * @since 1.0.11 Font Awesome Kits now supported. |
|
31 | + * @since 1.0.13 RTL language support added. |
|
32 | + * @since 1.0.14 Warning added for v6 pro requires kit and will now not work if official FA plugin installed. |
|
33 | + * @ver 1.0.14 |
|
34 | + * @todo decide how to implement textdomain |
|
35 | + */ |
|
36 | + class WP_Font_Awesome_Settings { |
|
37 | + |
|
38 | + /** |
|
39 | + * Class version version. |
|
40 | + * |
|
41 | + * @var string |
|
42 | + */ |
|
43 | + public $version = '1.0.14'; |
|
44 | + |
|
45 | + /** |
|
46 | + * Class textdomain. |
|
47 | + * |
|
48 | + * @var string |
|
49 | + */ |
|
50 | + public $textdomain = 'font-awesome-settings'; |
|
51 | + |
|
52 | + /** |
|
53 | + * Latest version of Font Awesome at time of publish published. |
|
54 | + * |
|
55 | + * @var string |
|
56 | + */ |
|
57 | + public $latest = "5.8.2"; |
|
58 | + |
|
59 | + /** |
|
60 | + * The title. |
|
61 | + * |
|
62 | + * @var string |
|
63 | + */ |
|
64 | + public $name = 'Font Awesome'; |
|
65 | + |
|
66 | + /** |
|
67 | + * Holds the settings values. |
|
68 | + * |
|
69 | + * @var array |
|
70 | + */ |
|
71 | + private $settings; |
|
72 | + |
|
73 | + /** |
|
74 | + * WP_Font_Awesome_Settings instance. |
|
75 | + * |
|
76 | + * @access private |
|
77 | + * @since 1.0.0 |
|
78 | + * @var WP_Font_Awesome_Settings There can be only one! |
|
79 | + */ |
|
80 | + private static $instance = null; |
|
81 | + |
|
82 | + /** |
|
83 | + * Main WP_Font_Awesome_Settings Instance. |
|
84 | + * |
|
85 | + * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded. |
|
86 | + * |
|
87 | + * @since 1.0.0 |
|
88 | + * @static |
|
89 | + * @return WP_Font_Awesome_Settings - Main instance. |
|
90 | + */ |
|
91 | + public static function instance() { |
|
92 | + if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
93 | + self::$instance = new WP_Font_Awesome_Settings; |
|
94 | + |
|
95 | + add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
96 | + |
|
97 | + if ( is_admin() ) { |
|
98 | + add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
99 | + add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
100 | + add_action( 'admin_notices', array( self::$instance, 'admin_notices' ) ); |
|
101 | + } |
|
102 | + |
|
103 | + do_action( 'wp_font_awesome_settings_loaded' ); |
|
104 | + } |
|
105 | + |
|
106 | + return self::$instance; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Initiate the settings and add the required action hooks. |
|
111 | + * |
|
112 | + * @since 1.0.8 Settings name wrong - FIXED |
|
113 | + */ |
|
114 | + public function init() { |
|
115 | + $this->settings = $this->get_settings(); |
|
116 | + |
|
117 | + // check if the official plugin is active and use that instead if so. |
|
118 | + if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
119 | + |
|
120 | + if ( $this->settings['type'] == 'CSS' ) { |
|
121 | + |
|
122 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
123 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
124 | + } |
|
125 | + |
|
126 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
127 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
128 | + } |
|
129 | + |
|
130 | + } else { |
|
131 | + |
|
132 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
133 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
134 | + } |
|
135 | + |
|
136 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
137 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
138 | + } |
|
139 | + } |
|
140 | + |
|
141 | + // remove font awesome if set to do so |
|
142 | + if ( $this->settings['dequeue'] == '1' ) { |
|
143 | + add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
144 | + } |
|
145 | + } |
|
146 | + |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Adds the Font Awesome styles. |
|
151 | + */ |
|
152 | + public function enqueue_style() { |
|
153 | + // build url |
|
154 | + $url = $this->get_url(); |
|
155 | + |
|
156 | + wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
157 | + wp_register_style( 'font-awesome', $url, array(), null ); |
|
158 | + wp_enqueue_style( 'font-awesome' ); |
|
159 | + |
|
160 | + // RTL language support CSS. |
|
161 | + if ( is_rtl() ) { |
|
162 | + wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() ); |
|
163 | + } |
|
164 | + |
|
165 | + if ( $this->settings['shims'] ) { |
|
166 | + $url = $this->get_url( true ); |
|
167 | + wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
168 | + wp_register_style( 'font-awesome-shims', $url, array(), null ); |
|
169 | + wp_enqueue_style( 'font-awesome-shims' ); |
|
170 | + } |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * Adds the Font Awesome JS. |
|
175 | + */ |
|
176 | + public function enqueue_scripts() { |
|
177 | + // build url |
|
178 | + $url = $this->get_url(); |
|
179 | + |
|
180 | + $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
|
181 | + call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
182 | + wp_register_script( 'font-awesome', $url, array(), null ); |
|
183 | + wp_enqueue_script( 'font-awesome' ); |
|
184 | + |
|
185 | + if ( $this->settings['shims'] ) { |
|
186 | + $url = $this->get_url( true ); |
|
187 | + call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
188 | + wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
189 | + wp_enqueue_script( 'font-awesome-shims' ); |
|
190 | + } |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * Get the url of the Font Awesome files. |
|
195 | + * |
|
196 | + * @param bool $shims If this is a shim file or not. |
|
197 | + * |
|
198 | + * @return string The url to the file. |
|
199 | + */ |
|
200 | + public function get_url( $shims = false ) { |
|
201 | + $script = $shims ? 'v4-shims' : 'all'; |
|
202 | + $sub = $this->settings['pro'] ? 'pro' : 'use'; |
|
203 | + $type = $this->settings['type']; |
|
204 | + $version = $this->settings['version']; |
|
205 | + $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : ''; |
|
206 | + $url = ''; |
|
207 | + |
|
208 | + if ( $type == 'KIT' && $kit_url ) { |
|
209 | + if ( $shims ) { |
|
210 | + // if its a kit then we don't add shims here |
|
211 | + return ''; |
|
212 | + } |
|
213 | + $url .= $kit_url; // CDN |
|
214 | + $url .= "?wpfas=true"; // set our var so our version is not removed |
|
215 | + } else { |
|
216 | + $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
|
217 | + $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
218 | + $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
|
219 | + $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
|
220 | + $url .= "?wpfas=true"; // set our var so our version is not removed |
|
221 | + } |
|
222 | + |
|
223 | + return $url; |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * Try and remove any other versions of Font Awesome added by other plugins/themes. |
|
228 | + * |
|
229 | + * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version. |
|
230 | + * |
|
231 | + * @param $url |
|
232 | + * @param $original_url |
|
233 | + * @param $_context |
|
234 | + * |
|
235 | + * @return string The filtered url. |
|
236 | + */ |
|
237 | + public function remove_font_awesome( $url, $original_url, $_context ) { |
|
238 | + |
|
239 | + if ( $_context == 'display' |
|
240 | + && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
241 | + && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
242 | + ) {// it's a font-awesome-url (probably) |
|
243 | + |
|
244 | + if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
245 | + if ( $this->settings['type'] == 'JS' ) { |
|
246 | + if ( $this->settings['js-pseudo'] ) { |
|
247 | + $url .= "' data-search-pseudo-elements defer='defer"; |
|
248 | + } else { |
|
249 | + $url .= "' defer='defer"; |
|
250 | + } |
|
251 | + } |
|
252 | + } else { |
|
253 | + $url = ''; // removing the url removes the file |
|
254 | + } |
|
255 | + |
|
256 | + } |
|
257 | + |
|
258 | + return $url; |
|
259 | + } |
|
260 | + |
|
261 | + /** |
|
262 | + * Register the database settings with WordPress. |
|
263 | + */ |
|
264 | + public function register_settings() { |
|
265 | + register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
266 | + } |
|
267 | + |
|
268 | + /** |
|
269 | + * Add the WordPress settings menu item. |
|
270 | + * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
271 | + */ |
|
272 | + public function menu_item() { |
|
273 | + $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
274 | + call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
275 | + $this, |
|
276 | + 'settings_page' |
|
277 | + ) ); |
|
278 | + } |
|
279 | + |
|
280 | + /** |
|
281 | + * Get the current Font Awesome output settings. |
|
282 | + * |
|
283 | + * @return array The array of settings. |
|
284 | + */ |
|
285 | + public function get_settings() { |
|
286 | + |
|
287 | + $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
288 | + |
|
289 | + $defaults = array( |
|
290 | + 'type' => 'CSS', // type to use, CSS or JS or KIT |
|
291 | + 'version' => '', // latest |
|
292 | + 'enqueue' => '', // front and backend |
|
293 | + 'shims' => '0', // default OFF now in 2020 |
|
294 | + 'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive) |
|
295 | + 'dequeue' => '0', // if we should try to remove other versions added by other plugins/themes |
|
296 | + 'pro' => '0', // if pro CDN url should be used |
|
297 | + 'kit-url' => '', // the kit url |
|
298 | + ); |
|
299 | + |
|
300 | + $settings = wp_parse_args( $db_settings, $defaults ); |
|
301 | + |
|
302 | + /** |
|
303 | + * Filter the Font Awesome settings. |
|
304 | + * |
|
305 | + * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
306 | + */ |
|
307 | + return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
308 | + } |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * The settings page html output. |
|
313 | + */ |
|
314 | + public function settings_page() { |
|
315 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
316 | + wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) ); |
|
317 | + } |
|
318 | + |
|
319 | + // a hidden way to force the update of the version number via api instead of waiting the 48 hours |
|
320 | + if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
321 | + $this->get_latest_version( $force_api = true ); |
|
322 | + } |
|
323 | + |
|
324 | + if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
325 | + ?> |
|
326 | 326 | <style> |
327 | 327 | .wpfas-kit-show { |
328 | 328 | display: none; |
@@ -340,10 +340,10 @@ discard block |
||
340 | 340 | <h1><?php echo $this->name; ?></h1> |
341 | 341 | <form method="post" action="options.php" class="fas-settings-form"> |
342 | 342 | <?php |
343 | - settings_fields( 'wp-font-awesome-settings' ); |
|
344 | - do_settings_sections( 'wp-font-awesome-settings' ); |
|
345 | - $kit_set = $this->settings['type'] == 'KIT' ? 'wpfas-kit-set' : ''; |
|
346 | - ?> |
|
343 | + settings_fields( 'wp-font-awesome-settings' ); |
|
344 | + do_settings_sections( 'wp-font-awesome-settings' ); |
|
345 | + $kit_set = $this->settings['type'] == 'KIT' ? 'wpfas-kit-set' : ''; |
|
346 | + ?> |
|
347 | 347 | <table class="form-table wpfas-table-settings <?php echo esc_attr( $kit_set ); ?>"> |
348 | 348 | <tr valign="top"> |
349 | 349 | <th scope="row"><label |
@@ -369,12 +369,12 @@ discard block |
||
369 | 369 | value="<?php echo esc_attr( $this->settings['kit-url'] ); ?>" |
370 | 370 | placeholder="<?php echo 'https://kit.font';echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/> |
371 | 371 | <span><?php |
372 | - echo sprintf( |
|
373 | - __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ), |
|
374 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>', |
|
375 | - '</a>' |
|
376 | - ); |
|
377 | - ?></span> |
|
372 | + echo sprintf( |
|
373 | + __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ), |
|
374 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>', |
|
375 | + '</a>' |
|
376 | + ); |
|
377 | + ?></span> |
|
378 | 378 | </td> |
379 | 379 | </tr> |
380 | 380 | |
@@ -443,14 +443,14 @@ discard block |
||
443 | 443 | <input type="checkbox" name="wp-font-awesome-settings[pro]" |
444 | 444 | value="1" <?php checked( $this->settings['pro'], '1' ); ?> id="wpfas-pro"/> |
445 | 445 | <span><?php |
446 | - echo sprintf( |
|
447 | - __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ), |
|
448 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/referral?a=c9b89e1418">', |
|
449 | - ' <i class="fas fa-external-link-alt"></i></a>', |
|
450 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn">', |
|
451 | - ' <i class="fas fa-external-link-alt"></i></a>' |
|
452 | - ); |
|
453 | - ?></span> |
|
446 | + echo sprintf( |
|
447 | + __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ), |
|
448 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/referral?a=c9b89e1418">', |
|
449 | + ' <i class="fas fa-external-link-alt"></i></a>', |
|
450 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn">', |
|
451 | + ' <i class="fas fa-external-link-alt"></i></a>' |
|
452 | + ); |
|
453 | + ?></span> |
|
454 | 454 | </td> |
455 | 455 | </tr> |
456 | 456 | |
@@ -494,8 +494,8 @@ discard block |
||
494 | 494 | </table> |
495 | 495 | <div class="fas-buttons"> |
496 | 496 | <?php |
497 | - submit_button(); |
|
498 | - ?> |
|
497 | + submit_button(); |
|
498 | + ?> |
|
499 | 499 | <p class="submit"><a href="https://fontawesome.com/referral?a=c9b89e1418" class="button button-secondary"><?php _e('Get 14,000+ more icons with Font Awesome Pro','font-awesome-settings'); ?> <i class="fas fa-external-link-alt"></i></a></p> |
500 | 500 | |
501 | 501 | </div> |
@@ -519,126 +519,126 @@ discard block |
||
519 | 519 | } |
520 | 520 | </style> |
521 | 521 | <?php |
522 | - } |
|
523 | - } |
|
524 | - |
|
525 | - /** |
|
526 | - * Check a version number is valid and if so return it or else return an empty string. |
|
527 | - * |
|
528 | - * @param $version string The version number to check. |
|
529 | - * |
|
530 | - * @since 1.0.6 |
|
531 | - * |
|
532 | - * @return string Either a valid version number or an empty string. |
|
533 | - */ |
|
534 | - public function validate_version_number( $version ) { |
|
535 | - |
|
536 | - if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
537 | - // valid |
|
538 | - } else { |
|
539 | - $version = '';// not validated |
|
540 | - } |
|
541 | - |
|
542 | - return $version; |
|
543 | - } |
|
544 | - |
|
545 | - |
|
546 | - /** |
|
547 | - * Get the latest version of Font Awesome. |
|
548 | - * |
|
549 | - * We check for a cached version and if none we will check for a live version via API and then cache it for 48 hours. |
|
550 | - * |
|
551 | - * @since 1.0.7 |
|
552 | - * @return mixed|string The latest version number found. |
|
553 | - */ |
|
554 | - public function get_latest_version( $force_api = false ) { |
|
555 | - $latest_version = $this->latest; |
|
556 | - |
|
557 | - $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
558 | - |
|
559 | - if ( $cache === false || $force_api ) { // its not set |
|
560 | - $api_ver = $this->get_latest_version_from_api(); |
|
561 | - if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
562 | - $latest_version = $api_ver; |
|
563 | - set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
564 | - } |
|
565 | - } elseif ( $this->validate_version_number( $cache ) ) { |
|
566 | - if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
567 | - $latest_version = $cache; |
|
568 | - } |
|
569 | - } |
|
570 | - |
|
571 | - return $latest_version; |
|
572 | - } |
|
573 | - |
|
574 | - /** |
|
575 | - * Get the latest Font Awesome version from the github API. |
|
576 | - * |
|
577 | - * @since 1.0.7 |
|
578 | - * @return string The latest version number or `0` on API fail. |
|
579 | - */ |
|
580 | - public function get_latest_version_from_api() { |
|
581 | - $version = "0"; |
|
582 | - $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
583 | - if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
584 | - $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
585 | - if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
586 | - $version = $api_response['tag_name']; |
|
587 | - } |
|
588 | - } |
|
589 | - |
|
590 | - return $version; |
|
591 | - } |
|
592 | - |
|
593 | - /** |
|
594 | - * Inline CSS for RTL language support. |
|
595 | - * |
|
596 | - * @since 1.0.13 |
|
597 | - * @return string Inline CSS. |
|
598 | - */ |
|
599 | - public function rtl_inline_css() { |
|
600 | - $inline_css = '[dir=rtl] .fa-address,[dir=rtl] .fa-address-card,[dir=rtl] .fa-adjust,[dir=rtl] .fa-alarm-clock,[dir=rtl] .fa-align-left,[dir=rtl] .fa-align-right,[dir=rtl] .fa-analytics,[dir=rtl] .fa-angle-double-left,[dir=rtl] .fa-angle-double-right,[dir=rtl] .fa-angle-left,[dir=rtl] .fa-angle-right,[dir=rtl] .fa-arrow-alt-circle-left,[dir=rtl] .fa-arrow-alt-circle-right,[dir=rtl] .fa-arrow-alt-from-left,[dir=rtl] .fa-arrow-alt-from-right,[dir=rtl] .fa-arrow-alt-left,[dir=rtl] .fa-arrow-alt-right,[dir=rtl] .fa-arrow-alt-square-left,[dir=rtl] .fa-arrow-alt-square-right,[dir=rtl] .fa-arrow-alt-to-left,[dir=rtl] .fa-arrow-alt-to-right,[dir=rtl] .fa-arrow-circle-left,[dir=rtl] .fa-arrow-circle-right,[dir=rtl] .fa-arrow-from-left,[dir=rtl] .fa-arrow-from-right,[dir=rtl] .fa-arrow-left,[dir=rtl] .fa-arrow-right,[dir=rtl] .fa-arrow-square-left,[dir=rtl] .fa-arrow-square-right,[dir=rtl] .fa-arrow-to-left,[dir=rtl] .fa-arrow-to-right,[dir=rtl] .fa-balance-scale-left,[dir=rtl] .fa-balance-scale-right,[dir=rtl] .fa-bed,[dir=rtl] .fa-bed-bunk,[dir=rtl] .fa-bed-empty,[dir=rtl] .fa-border-left,[dir=rtl] .fa-border-right,[dir=rtl] .fa-calendar-check,[dir=rtl] .fa-caret-circle-left,[dir=rtl] .fa-caret-circle-right,[dir=rtl] .fa-caret-left,[dir=rtl] .fa-caret-right,[dir=rtl] .fa-caret-square-left,[dir=rtl] .fa-caret-square-right,[dir=rtl] .fa-cart-arrow-down,[dir=rtl] .fa-cart-plus,[dir=rtl] .fa-chart-area,[dir=rtl] .fa-chart-bar,[dir=rtl] .fa-chart-line,[dir=rtl] .fa-chart-line-down,[dir=rtl] .fa-chart-network,[dir=rtl] .fa-chart-pie,[dir=rtl] .fa-chart-pie-alt,[dir=rtl] .fa-chart-scatter,[dir=rtl] .fa-check-circle,[dir=rtl] .fa-check-square,[dir=rtl] .fa-chevron-circle-left,[dir=rtl] .fa-chevron-circle-right,[dir=rtl] .fa-chevron-double-left,[dir=rtl] .fa-chevron-double-right,[dir=rtl] .fa-chevron-left,[dir=rtl] .fa-chevron-right,[dir=rtl] .fa-chevron-square-left,[dir=rtl] .fa-chevron-square-right,[dir=rtl] .fa-clock,[dir=rtl] .fa-file,[dir=rtl] .fa-file-alt,[dir=rtl] .fa-file-archive,[dir=rtl] .fa-file-audio,[dir=rtl] .fa-file-chart-line,[dir=rtl] .fa-file-chart-pie,[dir=rtl] .fa-file-code,[dir=rtl] .fa-file-excel,[dir=rtl] .fa-file-image,[dir=rtl] .fa-file-pdf,[dir=rtl] .fa-file-powerpoint,[dir=rtl] .fa-file-video,[dir=rtl] .fa-file-word,[dir=rtl] .fa-flag,[dir=rtl] .fa-folder,[dir=rtl] .fa-folder-open,[dir=rtl] .fa-hand-lizard,[dir=rtl] .fa-hand-point-down,[dir=rtl] .fa-hand-point-left,[dir=rtl] .fa-hand-point-right,[dir=rtl] .fa-hand-point-up,[dir=rtl] .fa-hand-scissors,[dir=rtl] .fa-image,[dir=rtl] .fa-long-arrow-alt-left,[dir=rtl] .fa-long-arrow-alt-right,[dir=rtl] .fa-long-arrow-left,[dir=rtl] .fa-long-arrow-right,[dir=rtl] .fa-luggage-cart,[dir=rtl] .fa-moon,[dir=rtl] .fa-pencil,[dir=rtl] .fa-pencil-alt,[dir=rtl] .fa-play-circle,[dir=rtl] .fa-project-diagram,[dir=rtl] .fa-quote-left,[dir=rtl] .fa-quote-right,[dir=rtl] .fa-shopping-cart,[dir=rtl] .fa-thumbs-down,[dir=rtl] .fa-thumbs-up,[dir=rtl] .fa-user-chart{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);transform:scale(-1,1)}[dir=rtl] .fa-spin{animation-direction:reverse}'; |
|
601 | - |
|
602 | - return $inline_css; |
|
603 | - } |
|
604 | - |
|
605 | - /** |
|
606 | - * Show any warnings as an admin notice. |
|
607 | - * |
|
608 | - * @return void |
|
609 | - */ |
|
610 | - public function admin_notices(){ |
|
611 | - $settings = $this->settings; |
|
612 | - |
|
613 | - if ( defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
614 | - |
|
615 | - if ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wp-font-awesome-settings' ) { |
|
616 | - ?> |
|
522 | + } |
|
523 | + } |
|
524 | + |
|
525 | + /** |
|
526 | + * Check a version number is valid and if so return it or else return an empty string. |
|
527 | + * |
|
528 | + * @param $version string The version number to check. |
|
529 | + * |
|
530 | + * @since 1.0.6 |
|
531 | + * |
|
532 | + * @return string Either a valid version number or an empty string. |
|
533 | + */ |
|
534 | + public function validate_version_number( $version ) { |
|
535 | + |
|
536 | + if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
537 | + // valid |
|
538 | + } else { |
|
539 | + $version = '';// not validated |
|
540 | + } |
|
541 | + |
|
542 | + return $version; |
|
543 | + } |
|
544 | + |
|
545 | + |
|
546 | + /** |
|
547 | + * Get the latest version of Font Awesome. |
|
548 | + * |
|
549 | + * We check for a cached version and if none we will check for a live version via API and then cache it for 48 hours. |
|
550 | + * |
|
551 | + * @since 1.0.7 |
|
552 | + * @return mixed|string The latest version number found. |
|
553 | + */ |
|
554 | + public function get_latest_version( $force_api = false ) { |
|
555 | + $latest_version = $this->latest; |
|
556 | + |
|
557 | + $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
558 | + |
|
559 | + if ( $cache === false || $force_api ) { // its not set |
|
560 | + $api_ver = $this->get_latest_version_from_api(); |
|
561 | + if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
562 | + $latest_version = $api_ver; |
|
563 | + set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
564 | + } |
|
565 | + } elseif ( $this->validate_version_number( $cache ) ) { |
|
566 | + if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
567 | + $latest_version = $cache; |
|
568 | + } |
|
569 | + } |
|
570 | + |
|
571 | + return $latest_version; |
|
572 | + } |
|
573 | + |
|
574 | + /** |
|
575 | + * Get the latest Font Awesome version from the github API. |
|
576 | + * |
|
577 | + * @since 1.0.7 |
|
578 | + * @return string The latest version number or `0` on API fail. |
|
579 | + */ |
|
580 | + public function get_latest_version_from_api() { |
|
581 | + $version = "0"; |
|
582 | + $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
583 | + if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
584 | + $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
585 | + if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
586 | + $version = $api_response['tag_name']; |
|
587 | + } |
|
588 | + } |
|
589 | + |
|
590 | + return $version; |
|
591 | + } |
|
592 | + |
|
593 | + /** |
|
594 | + * Inline CSS for RTL language support. |
|
595 | + * |
|
596 | + * @since 1.0.13 |
|
597 | + * @return string Inline CSS. |
|
598 | + */ |
|
599 | + public function rtl_inline_css() { |
|
600 | + $inline_css = '[dir=rtl] .fa-address,[dir=rtl] .fa-address-card,[dir=rtl] .fa-adjust,[dir=rtl] .fa-alarm-clock,[dir=rtl] .fa-align-left,[dir=rtl] .fa-align-right,[dir=rtl] .fa-analytics,[dir=rtl] .fa-angle-double-left,[dir=rtl] .fa-angle-double-right,[dir=rtl] .fa-angle-left,[dir=rtl] .fa-angle-right,[dir=rtl] .fa-arrow-alt-circle-left,[dir=rtl] .fa-arrow-alt-circle-right,[dir=rtl] .fa-arrow-alt-from-left,[dir=rtl] .fa-arrow-alt-from-right,[dir=rtl] .fa-arrow-alt-left,[dir=rtl] .fa-arrow-alt-right,[dir=rtl] .fa-arrow-alt-square-left,[dir=rtl] .fa-arrow-alt-square-right,[dir=rtl] .fa-arrow-alt-to-left,[dir=rtl] .fa-arrow-alt-to-right,[dir=rtl] .fa-arrow-circle-left,[dir=rtl] .fa-arrow-circle-right,[dir=rtl] .fa-arrow-from-left,[dir=rtl] .fa-arrow-from-right,[dir=rtl] .fa-arrow-left,[dir=rtl] .fa-arrow-right,[dir=rtl] .fa-arrow-square-left,[dir=rtl] .fa-arrow-square-right,[dir=rtl] .fa-arrow-to-left,[dir=rtl] .fa-arrow-to-right,[dir=rtl] .fa-balance-scale-left,[dir=rtl] .fa-balance-scale-right,[dir=rtl] .fa-bed,[dir=rtl] .fa-bed-bunk,[dir=rtl] .fa-bed-empty,[dir=rtl] .fa-border-left,[dir=rtl] .fa-border-right,[dir=rtl] .fa-calendar-check,[dir=rtl] .fa-caret-circle-left,[dir=rtl] .fa-caret-circle-right,[dir=rtl] .fa-caret-left,[dir=rtl] .fa-caret-right,[dir=rtl] .fa-caret-square-left,[dir=rtl] .fa-caret-square-right,[dir=rtl] .fa-cart-arrow-down,[dir=rtl] .fa-cart-plus,[dir=rtl] .fa-chart-area,[dir=rtl] .fa-chart-bar,[dir=rtl] .fa-chart-line,[dir=rtl] .fa-chart-line-down,[dir=rtl] .fa-chart-network,[dir=rtl] .fa-chart-pie,[dir=rtl] .fa-chart-pie-alt,[dir=rtl] .fa-chart-scatter,[dir=rtl] .fa-check-circle,[dir=rtl] .fa-check-square,[dir=rtl] .fa-chevron-circle-left,[dir=rtl] .fa-chevron-circle-right,[dir=rtl] .fa-chevron-double-left,[dir=rtl] .fa-chevron-double-right,[dir=rtl] .fa-chevron-left,[dir=rtl] .fa-chevron-right,[dir=rtl] .fa-chevron-square-left,[dir=rtl] .fa-chevron-square-right,[dir=rtl] .fa-clock,[dir=rtl] .fa-file,[dir=rtl] .fa-file-alt,[dir=rtl] .fa-file-archive,[dir=rtl] .fa-file-audio,[dir=rtl] .fa-file-chart-line,[dir=rtl] .fa-file-chart-pie,[dir=rtl] .fa-file-code,[dir=rtl] .fa-file-excel,[dir=rtl] .fa-file-image,[dir=rtl] .fa-file-pdf,[dir=rtl] .fa-file-powerpoint,[dir=rtl] .fa-file-video,[dir=rtl] .fa-file-word,[dir=rtl] .fa-flag,[dir=rtl] .fa-folder,[dir=rtl] .fa-folder-open,[dir=rtl] .fa-hand-lizard,[dir=rtl] .fa-hand-point-down,[dir=rtl] .fa-hand-point-left,[dir=rtl] .fa-hand-point-right,[dir=rtl] .fa-hand-point-up,[dir=rtl] .fa-hand-scissors,[dir=rtl] .fa-image,[dir=rtl] .fa-long-arrow-alt-left,[dir=rtl] .fa-long-arrow-alt-right,[dir=rtl] .fa-long-arrow-left,[dir=rtl] .fa-long-arrow-right,[dir=rtl] .fa-luggage-cart,[dir=rtl] .fa-moon,[dir=rtl] .fa-pencil,[dir=rtl] .fa-pencil-alt,[dir=rtl] .fa-play-circle,[dir=rtl] .fa-project-diagram,[dir=rtl] .fa-quote-left,[dir=rtl] .fa-quote-right,[dir=rtl] .fa-shopping-cart,[dir=rtl] .fa-thumbs-down,[dir=rtl] .fa-thumbs-up,[dir=rtl] .fa-user-chart{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);transform:scale(-1,1)}[dir=rtl] .fa-spin{animation-direction:reverse}'; |
|
601 | + |
|
602 | + return $inline_css; |
|
603 | + } |
|
604 | + |
|
605 | + /** |
|
606 | + * Show any warnings as an admin notice. |
|
607 | + * |
|
608 | + * @return void |
|
609 | + */ |
|
610 | + public function admin_notices(){ |
|
611 | + $settings = $this->settings; |
|
612 | + |
|
613 | + if ( defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
614 | + |
|
615 | + if ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wp-font-awesome-settings' ) { |
|
616 | + ?> |
|
617 | 617 | <div class="notice notice-error is-dismissible"> |
618 | 618 | <p><?php _e( 'The Official Font Awesome Plugin is active, please adjust your settings there.', 'font-awesome-settings' ); ?></p> |
619 | 619 | </div> |
620 | 620 | <?php |
621 | - } |
|
621 | + } |
|
622 | 622 | |
623 | - }else{ |
|
624 | - if ( ! empty( $settings ) ) { |
|
625 | - if ( $settings['type'] != 'KIT' && $settings['pro'] && ( $settings['version'] == '' || version_compare( $settings['version'], '6', '>=' ) ) ) { |
|
626 | - $link = admin_url('options-general.php?page=wp-font-awesome-settings'); |
|
627 | - ?> |
|
623 | + }else{ |
|
624 | + if ( ! empty( $settings ) ) { |
|
625 | + if ( $settings['type'] != 'KIT' && $settings['pro'] && ( $settings['version'] == '' || version_compare( $settings['version'], '6', '>=' ) ) ) { |
|
626 | + $link = admin_url('options-general.php?page=wp-font-awesome-settings'); |
|
627 | + ?> |
|
628 | 628 | <div class="notice notice-error is-dismissible"> |
629 | 629 | <p><?php echo sprintf( __( 'Font Awesome Pro v6 requires the use of a kit, please setup your kit in %ssettings.%s', 'font-awesome-settings' ),"<a href='". esc_url_raw( $link )."'>","</a>" ); ?></p> |
630 | 630 | </div> |
631 | 631 | <?php |
632 | - } |
|
633 | - } |
|
634 | - } |
|
632 | + } |
|
633 | + } |
|
634 | + } |
|
635 | 635 | |
636 | - } |
|
636 | + } |
|
637 | 637 | |
638 | - } |
|
638 | + } |
|
639 | 639 | |
640 | - /** |
|
641 | - * Run the class if found. |
|
642 | - */ |
|
643 | - WP_Font_Awesome_Settings::instance(); |
|
640 | + /** |
|
641 | + * Run the class if found. |
|
642 | + */ |
|
643 | + WP_Font_Awesome_Settings::instance(); |
|
644 | 644 | } |
645 | 645 | \ No newline at end of file |
@@ -12,14 +12,14 @@ discard block |
||
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( 'WP_Font_Awesome_Settings' ) ) { |
|
22 | +if (!class_exists('WP_Font_Awesome_Settings')) { |
|
23 | 23 | |
24 | 24 | /** |
25 | 25 | * A Class to be able to change settings for Font Awesome. |
@@ -89,18 +89,18 @@ discard block |
||
89 | 89 | * @return WP_Font_Awesome_Settings - Main instance. |
90 | 90 | */ |
91 | 91 | public static function instance() { |
92 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
92 | + if (!isset(self::$instance) && !(self::$instance instanceof WP_Font_Awesome_Settings)) { |
|
93 | 93 | self::$instance = new WP_Font_Awesome_Settings; |
94 | 94 | |
95 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
95 | + add_action('init', array(self::$instance, 'init')); // set settings |
|
96 | 96 | |
97 | - if ( is_admin() ) { |
|
98 | - add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
99 | - add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
100 | - add_action( 'admin_notices', array( self::$instance, 'admin_notices' ) ); |
|
97 | + if (is_admin()) { |
|
98 | + add_action('admin_menu', array(self::$instance, 'menu_item')); |
|
99 | + add_action('admin_init', array(self::$instance, 'register_settings')); |
|
100 | + add_action('admin_notices', array(self::$instance, 'admin_notices')); |
|
101 | 101 | } |
102 | 102 | |
103 | - do_action( 'wp_font_awesome_settings_loaded' ); |
|
103 | + do_action('wp_font_awesome_settings_loaded'); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | return self::$instance; |
@@ -115,32 +115,32 @@ discard block |
||
115 | 115 | $this->settings = $this->get_settings(); |
116 | 116 | |
117 | 117 | // check if the official plugin is active and use that instead if so. |
118 | - if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
118 | + if (!defined('FONTAWESOME_PLUGIN_FILE')) { |
|
119 | 119 | |
120 | - if ( $this->settings['type'] == 'CSS' ) { |
|
120 | + if ($this->settings['type'] == 'CSS') { |
|
121 | 121 | |
122 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
123 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
122 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend') { |
|
123 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_style'), 5000); |
|
124 | 124 | } |
125 | 125 | |
126 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
127 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
126 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend') { |
|
127 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_style'), 5000); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | } else { |
131 | 131 | |
132 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
133 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
132 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend') { |
|
133 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 5000); |
|
134 | 134 | } |
135 | 135 | |
136 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
137 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
136 | + if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend') { |
|
137 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'), 5000); |
|
138 | 138 | } |
139 | 139 | } |
140 | 140 | |
141 | 141 | // remove font awesome if set to do so |
142 | - if ( $this->settings['dequeue'] == '1' ) { |
|
143 | - add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
142 | + if ($this->settings['dequeue'] == '1') { |
|
143 | + add_action('clean_url', array($this, 'remove_font_awesome'), 5000, 3); |
|
144 | 144 | } |
145 | 145 | } |
146 | 146 | |
@@ -153,20 +153,20 @@ discard block |
||
153 | 153 | // build url |
154 | 154 | $url = $this->get_url(); |
155 | 155 | |
156 | - wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
157 | - wp_register_style( 'font-awesome', $url, array(), null ); |
|
158 | - wp_enqueue_style( 'font-awesome' ); |
|
156 | + wp_deregister_style('font-awesome'); // deregister in case its already there |
|
157 | + wp_register_style('font-awesome', $url, array(), null); |
|
158 | + wp_enqueue_style('font-awesome'); |
|
159 | 159 | |
160 | 160 | // RTL language support CSS. |
161 | - if ( is_rtl() ) { |
|
162 | - wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() ); |
|
161 | + if (is_rtl()) { |
|
162 | + wp_add_inline_style('font-awesome', $this->rtl_inline_css()); |
|
163 | 163 | } |
164 | 164 | |
165 | - if ( $this->settings['shims'] ) { |
|
166 | - $url = $this->get_url( true ); |
|
167 | - wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
168 | - wp_register_style( 'font-awesome-shims', $url, array(), null ); |
|
169 | - wp_enqueue_style( 'font-awesome-shims' ); |
|
165 | + if ($this->settings['shims']) { |
|
166 | + $url = $this->get_url(true); |
|
167 | + wp_deregister_style('font-awesome-shims'); // deregister in case its already there |
|
168 | + wp_register_style('font-awesome-shims', $url, array(), null); |
|
169 | + wp_enqueue_style('font-awesome-shims'); |
|
170 | 170 | } |
171 | 171 | } |
172 | 172 | |
@@ -178,15 +178,15 @@ discard block |
||
178 | 178 | $url = $this->get_url(); |
179 | 179 | |
180 | 180 | $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
181 | - call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
182 | - wp_register_script( 'font-awesome', $url, array(), null ); |
|
183 | - wp_enqueue_script( 'font-awesome' ); |
|
184 | - |
|
185 | - if ( $this->settings['shims'] ) { |
|
186 | - $url = $this->get_url( true ); |
|
187 | - call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
188 | - wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
189 | - wp_enqueue_script( 'font-awesome-shims' ); |
|
181 | + call_user_func($deregister_function, 'font-awesome'); // deregister in case its already there |
|
182 | + wp_register_script('font-awesome', $url, array(), null); |
|
183 | + wp_enqueue_script('font-awesome'); |
|
184 | + |
|
185 | + if ($this->settings['shims']) { |
|
186 | + $url = $this->get_url(true); |
|
187 | + call_user_func($deregister_function, 'font-awesome-shims'); // deregister in case its already there |
|
188 | + wp_register_script('font-awesome-shims', $url, array(), null); |
|
189 | + wp_enqueue_script('font-awesome-shims'); |
|
190 | 190 | } |
191 | 191 | } |
192 | 192 | |
@@ -197,16 +197,16 @@ discard block |
||
197 | 197 | * |
198 | 198 | * @return string The url to the file. |
199 | 199 | */ |
200 | - public function get_url( $shims = false ) { |
|
200 | + public function get_url($shims = false) { |
|
201 | 201 | $script = $shims ? 'v4-shims' : 'all'; |
202 | 202 | $sub = $this->settings['pro'] ? 'pro' : 'use'; |
203 | 203 | $type = $this->settings['type']; |
204 | 204 | $version = $this->settings['version']; |
205 | - $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : ''; |
|
205 | + $kit_url = $this->settings['kit-url'] ? esc_url($this->settings['kit-url']) : ''; |
|
206 | 206 | $url = ''; |
207 | 207 | |
208 | - if ( $type == 'KIT' && $kit_url ) { |
|
209 | - if ( $shims ) { |
|
208 | + if ($type == 'KIT' && $kit_url) { |
|
209 | + if ($shims) { |
|
210 | 210 | // if its a kit then we don't add shims here |
211 | 211 | return ''; |
212 | 212 | } |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | $url .= "?wpfas=true"; // set our var so our version is not removed |
215 | 215 | } else { |
216 | 216 | $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
217 | - $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
217 | + $url .= !empty($version) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
218 | 218 | $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
219 | 219 | $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
220 | 220 | $url .= "?wpfas=true"; // set our var so our version is not removed |
@@ -234,16 +234,16 @@ discard block |
||
234 | 234 | * |
235 | 235 | * @return string The filtered url. |
236 | 236 | */ |
237 | - public function remove_font_awesome( $url, $original_url, $_context ) { |
|
237 | + public function remove_font_awesome($url, $original_url, $_context) { |
|
238 | 238 | |
239 | - if ( $_context == 'display' |
|
240 | - && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
241 | - && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
239 | + if ($_context == 'display' |
|
240 | + && (strstr($url, "fontawesome") !== false || strstr($url, "font-awesome") !== false) |
|
241 | + && (strstr($url, ".js") !== false || strstr($url, ".css") !== false) |
|
242 | 242 | ) {// it's a font-awesome-url (probably) |
243 | 243 | |
244 | - if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
245 | - if ( $this->settings['type'] == 'JS' ) { |
|
246 | - if ( $this->settings['js-pseudo'] ) { |
|
244 | + if (strstr($url, "wpfas=true") !== false) { |
|
245 | + if ($this->settings['type'] == 'JS') { |
|
246 | + if ($this->settings['js-pseudo']) { |
|
247 | 247 | $url .= "' data-search-pseudo-elements defer='defer"; |
248 | 248 | } else { |
249 | 249 | $url .= "' defer='defer"; |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | * Register the database settings with WordPress. |
263 | 263 | */ |
264 | 264 | public function register_settings() { |
265 | - register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
265 | + register_setting('wp-font-awesome-settings', 'wp-font-awesome-settings'); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | /** |
@@ -271,10 +271,10 @@ discard block |
||
271 | 271 | */ |
272 | 272 | public function menu_item() { |
273 | 273 | $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
274 | - call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
274 | + call_user_func($menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
275 | 275 | $this, |
276 | 276 | 'settings_page' |
277 | - ) ); |
|
277 | + )); |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | /** |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | */ |
285 | 285 | public function get_settings() { |
286 | 286 | |
287 | - $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
287 | + $db_settings = get_option('wp-font-awesome-settings'); |
|
288 | 288 | |
289 | 289 | $defaults = array( |
290 | 290 | 'type' => 'CSS', // type to use, CSS or JS or KIT |
@@ -297,14 +297,14 @@ discard block |
||
297 | 297 | 'kit-url' => '', // the kit url |
298 | 298 | ); |
299 | 299 | |
300 | - $settings = wp_parse_args( $db_settings, $defaults ); |
|
300 | + $settings = wp_parse_args($db_settings, $defaults); |
|
301 | 301 | |
302 | 302 | /** |
303 | 303 | * Filter the Font Awesome settings. |
304 | 304 | * |
305 | 305 | * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
306 | 306 | */ |
307 | - return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
307 | + return $this->settings = apply_filters('wp-font-awesome-settings', $settings, $db_settings, $defaults); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | |
@@ -312,16 +312,16 @@ discard block |
||
312 | 312 | * The settings page html output. |
313 | 313 | */ |
314 | 314 | public function settings_page() { |
315 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
316 | - wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) ); |
|
315 | + if (!current_user_can('manage_options')) { |
|
316 | + wp_die(__('You do not have sufficient permissions to access this page.', 'font-awesome-settings')); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | // a hidden way to force the update of the version number via api instead of waiting the 48 hours |
320 | - if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
321 | - $this->get_latest_version( $force_api = true ); |
|
320 | + if (isset($_REQUEST['force-version-check'])) { |
|
321 | + $this->get_latest_version($force_api = true); |
|
322 | 322 | } |
323 | 323 | |
324 | - if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
324 | + if (!defined('FONTAWESOME_PLUGIN_FILE')) { |
|
325 | 325 | ?> |
326 | 326 | <style> |
327 | 327 | .wpfas-kit-show { |
@@ -340,37 +340,37 @@ discard block |
||
340 | 340 | <h1><?php echo $this->name; ?></h1> |
341 | 341 | <form method="post" action="options.php" class="fas-settings-form"> |
342 | 342 | <?php |
343 | - settings_fields( 'wp-font-awesome-settings' ); |
|
344 | - do_settings_sections( 'wp-font-awesome-settings' ); |
|
343 | + settings_fields('wp-font-awesome-settings'); |
|
344 | + do_settings_sections('wp-font-awesome-settings'); |
|
345 | 345 | $kit_set = $this->settings['type'] == 'KIT' ? 'wpfas-kit-set' : ''; |
346 | 346 | ?> |
347 | - <table class="form-table wpfas-table-settings <?php echo esc_attr( $kit_set ); ?>"> |
|
347 | + <table class="form-table wpfas-table-settings <?php echo esc_attr($kit_set); ?>"> |
|
348 | 348 | <tr valign="top"> |
349 | 349 | <th scope="row"><label |
350 | - for="wpfas-type"><?php _e( 'Type', 'font-awesome-settings' ); ?></label></th> |
|
350 | + for="wpfas-type"><?php _e('Type', 'font-awesome-settings'); ?></label></th> |
|
351 | 351 | <td> |
352 | 352 | <select name="wp-font-awesome-settings[type]" id="wpfas-type" |
353 | 353 | onchange="if(this.value=='KIT'){jQuery('.wpfas-table-settings').addClass('wpfas-kit-set');}else{jQuery('.wpfas-table-settings').removeClass('wpfas-kit-set');}"> |
354 | 354 | <option |
355 | - value="CSS" <?php selected( $this->settings['type'], 'CSS' ); ?>><?php _e( 'CSS (default)', 'font-awesome-settings' ); ?></option> |
|
356 | - <option value="JS" <?php selected( $this->settings['type'], 'JS' ); ?>>JS</option> |
|
355 | + value="CSS" <?php selected($this->settings['type'], 'CSS'); ?>><?php _e('CSS (default)', 'font-awesome-settings'); ?></option> |
|
356 | + <option value="JS" <?php selected($this->settings['type'], 'JS'); ?>>JS</option> |
|
357 | 357 | <option |
358 | - value="KIT" <?php selected( $this->settings['type'], 'KIT' ); ?>><?php _e( 'Kits (settings managed on fontawesome.com)', 'font-awesome-settings' ); ?></option> |
|
358 | + value="KIT" <?php selected($this->settings['type'], 'KIT'); ?>><?php _e('Kits (settings managed on fontawesome.com)', 'font-awesome-settings'); ?></option> |
|
359 | 359 | </select> |
360 | 360 | </td> |
361 | 361 | </tr> |
362 | 362 | |
363 | 363 | <tr valign="top" class="wpfas-kit-show"> |
364 | 364 | <th scope="row"><label |
365 | - for="wpfas-kit-url"><?php _e( 'Kit URL', 'font-awesome-settings' ); ?></label></th> |
|
365 | + for="wpfas-kit-url"><?php _e('Kit URL', 'font-awesome-settings'); ?></label></th> |
|
366 | 366 | <td> |
367 | 367 | <input class="regular-text" id="wpfas-kit-url" type="url" |
368 | 368 | name="wp-font-awesome-settings[kit-url]" |
369 | - value="<?php echo esc_attr( $this->settings['kit-url'] ); ?>" |
|
370 | - placeholder="<?php echo 'https://kit.font';echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/> |
|
369 | + value="<?php echo esc_attr($this->settings['kit-url']); ?>" |
|
370 | + placeholder="<?php echo 'https://kit.font'; echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/> |
|
371 | 371 | <span><?php |
372 | 372 | echo sprintf( |
373 | - __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ), |
|
373 | + __('Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings'), |
|
374 | 374 | '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>', |
375 | 375 | '</a>' |
376 | 376 | ); |
@@ -380,40 +380,40 @@ discard block |
||
380 | 380 | |
381 | 381 | <tr valign="top" class="wpfas-kit-hide"> |
382 | 382 | <th scope="row"><label |
383 | - for="wpfas-version"><?php _e( 'Version', 'font-awesome-settings' ); ?></label></th> |
|
383 | + for="wpfas-version"><?php _e('Version', 'font-awesome-settings'); ?></label></th> |
|
384 | 384 | <td> |
385 | 385 | <select name="wp-font-awesome-settings[version]" id="wpfas-version"> |
386 | 386 | <option |
387 | - value="" <?php selected( $this->settings['version'], '' ); ?>><?php echo sprintf( __( 'Latest - %s (default)', 'font-awesome-settings' ), $this->get_latest_version() ); ?> |
|
387 | + value="" <?php selected($this->settings['version'], ''); ?>><?php echo sprintf(__('Latest - %s (default)', 'font-awesome-settings'), $this->get_latest_version()); ?> |
|
388 | 388 | </option> |
389 | - <option value="6.1.0" <?php selected( $this->settings['version'], '6.1.0' ); ?>> |
|
389 | + <option value="6.1.0" <?php selected($this->settings['version'], '6.1.0'); ?>> |
|
390 | 390 | 6.1.0 |
391 | 391 | </option> |
392 | - <option value="6.0.0" <?php selected( $this->settings['version'], '6.0.0' ); ?>> |
|
392 | + <option value="6.0.0" <?php selected($this->settings['version'], '6.0.0'); ?>> |
|
393 | 393 | 6.0.0 |
394 | 394 | </option> |
395 | - <option value="5.15.4" <?php selected( $this->settings['version'], '5.15.4' ); ?>> |
|
395 | + <option value="5.15.4" <?php selected($this->settings['version'], '5.15.4'); ?>> |
|
396 | 396 | 5.15.4 |
397 | 397 | </option> |
398 | - <option value="5.6.0" <?php selected( $this->settings['version'], '5.6.0' ); ?>> |
|
398 | + <option value="5.6.0" <?php selected($this->settings['version'], '5.6.0'); ?>> |
|
399 | 399 | 5.6.0 |
400 | 400 | </option> |
401 | - <option value="5.5.0" <?php selected( $this->settings['version'], '5.5.0' ); ?>> |
|
401 | + <option value="5.5.0" <?php selected($this->settings['version'], '5.5.0'); ?>> |
|
402 | 402 | 5.5.0 |
403 | 403 | </option> |
404 | - <option value="5.4.0" <?php selected( $this->settings['version'], '5.4.0' ); ?>> |
|
404 | + <option value="5.4.0" <?php selected($this->settings['version'], '5.4.0'); ?>> |
|
405 | 405 | 5.4.0 |
406 | 406 | </option> |
407 | - <option value="5.3.0" <?php selected( $this->settings['version'], '5.3.0' ); ?>> |
|
407 | + <option value="5.3.0" <?php selected($this->settings['version'], '5.3.0'); ?>> |
|
408 | 408 | 5.3.0 |
409 | 409 | </option> |
410 | - <option value="5.2.0" <?php selected( $this->settings['version'], '5.2.0' ); ?>> |
|
410 | + <option value="5.2.0" <?php selected($this->settings['version'], '5.2.0'); ?>> |
|
411 | 411 | 5.2.0 |
412 | 412 | </option> |
413 | - <option value="5.1.0" <?php selected( $this->settings['version'], '5.1.0' ); ?>> |
|
413 | + <option value="5.1.0" <?php selected($this->settings['version'], '5.1.0'); ?>> |
|
414 | 414 | 5.1.0 |
415 | 415 | </option> |
416 | - <option value="4.7.0" <?php selected( $this->settings['version'], '4.7.0' ); ?>> |
|
416 | + <option value="4.7.0" <?php selected($this->settings['version'], '4.7.0'); ?>> |
|
417 | 417 | 4.7.1 (CSS only) |
418 | 418 | </option> |
419 | 419 | </select> |
@@ -422,29 +422,29 @@ discard block |
||
422 | 422 | |
423 | 423 | <tr valign="top"> |
424 | 424 | <th scope="row"><label |
425 | - for="wpfas-enqueue"><?php _e( 'Enqueue', 'font-awesome-settings' ); ?></label></th> |
|
425 | + for="wpfas-enqueue"><?php _e('Enqueue', 'font-awesome-settings'); ?></label></th> |
|
426 | 426 | <td> |
427 | 427 | <select name="wp-font-awesome-settings[enqueue]" id="wpfas-enqueue"> |
428 | 428 | <option |
429 | - value="" <?php selected( $this->settings['enqueue'], '' ); ?>><?php _e( 'Frontend + Backend (default)', 'font-awesome-settings' ); ?></option> |
|
429 | + value="" <?php selected($this->settings['enqueue'], ''); ?>><?php _e('Frontend + Backend (default)', 'font-awesome-settings'); ?></option> |
|
430 | 430 | <option |
431 | - value="frontend" <?php selected( $this->settings['enqueue'], 'frontend' ); ?>><?php _e( 'Frontend', 'font-awesome-settings' ); ?></option> |
|
431 | + value="frontend" <?php selected($this->settings['enqueue'], 'frontend'); ?>><?php _e('Frontend', 'font-awesome-settings'); ?></option> |
|
432 | 432 | <option |
433 | - value="backend" <?php selected( $this->settings['enqueue'], 'backend' ); ?>><?php _e( 'Backend', 'font-awesome-settings' ); ?></option> |
|
433 | + value="backend" <?php selected($this->settings['enqueue'], 'backend'); ?>><?php _e('Backend', 'font-awesome-settings'); ?></option> |
|
434 | 434 | </select> |
435 | 435 | </td> |
436 | 436 | </tr> |
437 | 437 | |
438 | 438 | <tr valign="top" class="wpfas-kit-hide"> |
439 | 439 | <th scope="row"><label |
440 | - for="wpfas-pro"><?php _e( 'Enable pro', 'font-awesome-settings' ); ?></label></th> |
|
440 | + for="wpfas-pro"><?php _e('Enable pro', 'font-awesome-settings'); ?></label></th> |
|
441 | 441 | <td> |
442 | 442 | <input type="hidden" name="wp-font-awesome-settings[pro]" value="0"/> |
443 | 443 | <input type="checkbox" name="wp-font-awesome-settings[pro]" |
444 | - value="1" <?php checked( $this->settings['pro'], '1' ); ?> id="wpfas-pro"/> |
|
444 | + value="1" <?php checked($this->settings['pro'], '1'); ?> id="wpfas-pro"/> |
|
445 | 445 | <span><?php |
446 | 446 | echo sprintf( |
447 | - __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ), |
|
447 | + __('Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings'), |
|
448 | 448 | '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/referral?a=c9b89e1418">', |
449 | 449 | ' <i class="fas fa-external-link-alt"></i></a>', |
450 | 450 | '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn">', |
@@ -456,38 +456,38 @@ discard block |
||
456 | 456 | |
457 | 457 | <tr valign="top" class="wpfas-kit-hide"> |
458 | 458 | <th scope="row"><label |
459 | - for="wpfas-shims"><?php _e( 'Enable v4 shims compatibility', 'font-awesome-settings' ); ?></label> |
|
459 | + for="wpfas-shims"><?php _e('Enable v4 shims compatibility', 'font-awesome-settings'); ?></label> |
|
460 | 460 | </th> |
461 | 461 | <td> |
462 | 462 | <input type="hidden" name="wp-font-awesome-settings[shims]" value="0"/> |
463 | 463 | <input type="checkbox" name="wp-font-awesome-settings[shims]" |
464 | - value="1" <?php checked( $this->settings['shims'], '1' ); ?> id="wpfas-shims"/> |
|
465 | - <span><?php _e( 'This enables v4 classes to work with v5, sort of like a band-aid until everyone has updated everything to v5.', 'font-awesome-settings' ); ?></span> |
|
464 | + value="1" <?php checked($this->settings['shims'], '1'); ?> id="wpfas-shims"/> |
|
465 | + <span><?php _e('This enables v4 classes to work with v5, sort of like a band-aid until everyone has updated everything to v5.', 'font-awesome-settings'); ?></span> |
|
466 | 466 | </td> |
467 | 467 | </tr> |
468 | 468 | |
469 | 469 | <tr valign="top" class="wpfas-kit-hide"> |
470 | 470 | <th scope="row"><label |
471 | - for="wpfas-js-pseudo"><?php _e( 'Enable JS pseudo elements (not recommended)', 'font-awesome-settings' ); ?></label> |
|
471 | + for="wpfas-js-pseudo"><?php _e('Enable JS pseudo elements (not recommended)', 'font-awesome-settings'); ?></label> |
|
472 | 472 | </th> |
473 | 473 | <td> |
474 | 474 | <input type="hidden" name="wp-font-awesome-settings[js-pseudo]" value="0"/> |
475 | 475 | <input type="checkbox" name="wp-font-awesome-settings[js-pseudo]" |
476 | - value="1" <?php checked( $this->settings['js-pseudo'], '1' ); ?> |
|
476 | + value="1" <?php checked($this->settings['js-pseudo'], '1'); ?> |
|
477 | 477 | id="wpfas-js-pseudo"/> |
478 | - <span><?php _e( 'Used only with the JS version, this will make pseudo-elements work but can be CPU intensive on some sites.', 'font-awesome-settings' ); ?></span> |
|
478 | + <span><?php _e('Used only with the JS version, this will make pseudo-elements work but can be CPU intensive on some sites.', 'font-awesome-settings'); ?></span> |
|
479 | 479 | </td> |
480 | 480 | </tr> |
481 | 481 | |
482 | 482 | <tr valign="top"> |
483 | 483 | <th scope="row"><label |
484 | - for="wpfas-dequeue"><?php _e( 'Dequeue', 'font-awesome-settings' ); ?></label></th> |
|
484 | + for="wpfas-dequeue"><?php _e('Dequeue', 'font-awesome-settings'); ?></label></th> |
|
485 | 485 | <td> |
486 | 486 | <input type="hidden" name="wp-font-awesome-settings[dequeue]" value="0"/> |
487 | 487 | <input type="checkbox" name="wp-font-awesome-settings[dequeue]" |
488 | - value="1" <?php checked( $this->settings['dequeue'], '1' ); ?> |
|
488 | + value="1" <?php checked($this->settings['dequeue'], '1'); ?> |
|
489 | 489 | id="wpfas-dequeue"/> |
490 | - <span><?php _e( 'This will try to dequeue any other Font Awesome versions loaded by other sources if they are added with `font-awesome` or `fontawesome` in the name.', 'font-awesome-settings' ); ?></span> |
|
490 | + <span><?php _e('This will try to dequeue any other Font Awesome versions loaded by other sources if they are added with `font-awesome` or `fontawesome` in the name.', 'font-awesome-settings'); ?></span> |
|
491 | 491 | </td> |
492 | 492 | </tr> |
493 | 493 | |
@@ -496,12 +496,12 @@ discard block |
||
496 | 496 | <?php |
497 | 497 | submit_button(); |
498 | 498 | ?> |
499 | - <p class="submit"><a href="https://fontawesome.com/referral?a=c9b89e1418" class="button button-secondary"><?php _e('Get 14,000+ more icons with Font Awesome Pro','font-awesome-settings'); ?> <i class="fas fa-external-link-alt"></i></a></p> |
|
499 | + <p class="submit"><a href="https://fontawesome.com/referral?a=c9b89e1418" class="button button-secondary"><?php _e('Get 14,000+ more icons with Font Awesome Pro', 'font-awesome-settings'); ?> <i class="fas fa-external-link-alt"></i></a></p> |
|
500 | 500 | |
501 | 501 | </div> |
502 | 502 | </form> |
503 | 503 | |
504 | - <div id="wpfas-version"><?php echo sprintf(__( 'Version: %s (affiliate links provided)', 'font-awesome-settings' ), $this->version ); ?></div> |
|
504 | + <div id="wpfas-version"><?php echo sprintf(__('Version: %s (affiliate links provided)', 'font-awesome-settings'), $this->version); ?></div> |
|
505 | 505 | </div> |
506 | 506 | |
507 | 507 | <style> |
@@ -531,12 +531,12 @@ discard block |
||
531 | 531 | * |
532 | 532 | * @return string Either a valid version number or an empty string. |
533 | 533 | */ |
534 | - public function validate_version_number( $version ) { |
|
534 | + public function validate_version_number($version) { |
|
535 | 535 | |
536 | - if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
536 | + if (version_compare($version, '0.0.1', '>=') >= 0) { |
|
537 | 537 | // valid |
538 | 538 | } else { |
539 | - $version = '';// not validated |
|
539 | + $version = ''; // not validated |
|
540 | 540 | } |
541 | 541 | |
542 | 542 | return $version; |
@@ -551,19 +551,19 @@ discard block |
||
551 | 551 | * @since 1.0.7 |
552 | 552 | * @return mixed|string The latest version number found. |
553 | 553 | */ |
554 | - public function get_latest_version( $force_api = false ) { |
|
554 | + public function get_latest_version($force_api = false) { |
|
555 | 555 | $latest_version = $this->latest; |
556 | 556 | |
557 | - $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
557 | + $cache = get_transient('wp-font-awesome-settings-version'); |
|
558 | 558 | |
559 | - if ( $cache === false || $force_api ) { // its not set |
|
559 | + if ($cache === false || $force_api) { // its not set |
|
560 | 560 | $api_ver = $this->get_latest_version_from_api(); |
561 | - if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
561 | + if (version_compare($api_ver, $this->latest, '>=') >= 0) { |
|
562 | 562 | $latest_version = $api_ver; |
563 | - set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
563 | + set_transient('wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS); |
|
564 | 564 | } |
565 | - } elseif ( $this->validate_version_number( $cache ) ) { |
|
566 | - if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
565 | + } elseif ($this->validate_version_number($cache)) { |
|
566 | + if (version_compare($cache, $this->latest, '>=') >= 0) { |
|
567 | 567 | $latest_version = $cache; |
568 | 568 | } |
569 | 569 | } |
@@ -579,10 +579,10 @@ discard block |
||
579 | 579 | */ |
580 | 580 | public function get_latest_version_from_api() { |
581 | 581 | $version = "0"; |
582 | - $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
583 | - if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
584 | - $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
585 | - if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
582 | + $response = wp_remote_get("https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest"); |
|
583 | + if (!is_wp_error($response) && is_array($response)) { |
|
584 | + $api_response = json_decode(wp_remote_retrieve_body($response), true); |
|
585 | + if (isset($api_response['tag_name']) && version_compare($api_response['tag_name'], $this->latest, '>=') >= 0 && empty($api_response['prerelease'])) { |
|
586 | 586 | $version = $api_response['tag_name']; |
587 | 587 | } |
588 | 588 | } |
@@ -607,26 +607,26 @@ discard block |
||
607 | 607 | * |
608 | 608 | * @return void |
609 | 609 | */ |
610 | - public function admin_notices(){ |
|
610 | + public function admin_notices() { |
|
611 | 611 | $settings = $this->settings; |
612 | 612 | |
613 | - if ( defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
613 | + if (defined('FONTAWESOME_PLUGIN_FILE')) { |
|
614 | 614 | |
615 | - if ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wp-font-awesome-settings' ) { |
|
615 | + if (!empty($_REQUEST['page']) && $_REQUEST['page'] == 'wp-font-awesome-settings') { |
|
616 | 616 | ?> |
617 | 617 | <div class="notice notice-error is-dismissible"> |
618 | - <p><?php _e( 'The Official Font Awesome Plugin is active, please adjust your settings there.', 'font-awesome-settings' ); ?></p> |
|
618 | + <p><?php _e('The Official Font Awesome Plugin is active, please adjust your settings there.', 'font-awesome-settings'); ?></p> |
|
619 | 619 | </div> |
620 | 620 | <?php |
621 | 621 | } |
622 | 622 | |
623 | - }else{ |
|
624 | - if ( ! empty( $settings ) ) { |
|
625 | - if ( $settings['type'] != 'KIT' && $settings['pro'] && ( $settings['version'] == '' || version_compare( $settings['version'], '6', '>=' ) ) ) { |
|
623 | + } else { |
|
624 | + if (!empty($settings)) { |
|
625 | + if ($settings['type'] != 'KIT' && $settings['pro'] && ($settings['version'] == '' || version_compare($settings['version'], '6', '>='))) { |
|
626 | 626 | $link = admin_url('options-general.php?page=wp-font-awesome-settings'); |
627 | 627 | ?> |
628 | 628 | <div class="notice notice-error is-dismissible"> |
629 | - <p><?php echo sprintf( __( 'Font Awesome Pro v6 requires the use of a kit, please setup your kit in %ssettings.%s', 'font-awesome-settings' ),"<a href='". esc_url_raw( $link )."'>","</a>" ); ?></p> |
|
629 | + <p><?php echo sprintf(__('Font Awesome Pro v6 requires the use of a kit, please setup your kit in %ssettings.%s', 'font-awesome-settings'), "<a href='" . esc_url_raw($link) . "'>", "</a>"); ?></p> |
|
630 | 630 | </div> |
631 | 631 | <?php |
632 | 632 | } |
@@ -620,7 +620,7 @@ |
||
620 | 620 | <?php |
621 | 621 | } |
622 | 622 | |
623 | - }else{ |
|
623 | + } else{ |
|
624 | 624 | if ( ! empty( $settings ) ) { |
625 | 625 | if ( $settings['type'] != 'KIT' && $settings['pro'] && ( $settings['version'] == '' || version_compare( $settings['version'], '6', '>=' ) ) ) { |
626 | 626 | $link = admin_url('options-general.php?page=wp-font-awesome-settings'); |