@@ -2,129 +2,129 @@ discard block |
||
2 | 2 | |
3 | 3 | class FrmFieldsController { |
4 | 4 | |
5 | - public static function load_field() { |
|
5 | + public static function load_field() { |
|
6 | 6 | FrmAppHelper::permission_check('frm_edit_forms'); |
7 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
7 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
8 | 8 | |
9 | - $fields = $_POST['field']; |
|
10 | - if ( empty( $fields ) ) { |
|
11 | - wp_die(); |
|
12 | - } |
|
9 | + $fields = $_POST['field']; |
|
10 | + if ( empty( $fields ) ) { |
|
11 | + wp_die(); |
|
12 | + } |
|
13 | 13 | |
14 | - $_GET['page'] = 'formidable'; |
|
15 | - $fields = stripslashes_deep( $fields ); |
|
14 | + $_GET['page'] = 'formidable'; |
|
15 | + $fields = stripslashes_deep( $fields ); |
|
16 | 16 | |
17 | - $ajax = true; |
|
17 | + $ajax = true; |
|
18 | 18 | $values = array( 'id' => FrmAppHelper::get_post_param( 'form_id', '', 'absint' ) ); |
19 | - $path = FrmAppHelper::plugin_path(); |
|
20 | - $field_html = array(); |
|
21 | - |
|
22 | - foreach ( $fields as $field ) { |
|
23 | - $field = htmlspecialchars_decode( nl2br( $field ) ); |
|
24 | - $field = json_decode( $field, true ); |
|
25 | - if ( ! isset( $field['id'] ) ) { |
|
26 | - // this field may have already been loaded |
|
27 | - continue; |
|
28 | - } |
|
19 | + $path = FrmAppHelper::plugin_path(); |
|
20 | + $field_html = array(); |
|
21 | + |
|
22 | + foreach ( $fields as $field ) { |
|
23 | + $field = htmlspecialchars_decode( nl2br( $field ) ); |
|
24 | + $field = json_decode( $field, true ); |
|
25 | + if ( ! isset( $field['id'] ) ) { |
|
26 | + // this field may have already been loaded |
|
27 | + continue; |
|
28 | + } |
|
29 | 29 | |
30 | - $field_id = absint( $field['id'] ); |
|
30 | + $field_id = absint( $field['id'] ); |
|
31 | 31 | |
32 | - if ( ! isset( $field['value'] ) ) { |
|
33 | - $field['value'] = ''; |
|
34 | - } |
|
32 | + if ( ! isset( $field['value'] ) ) { |
|
33 | + $field['value'] = ''; |
|
34 | + } |
|
35 | 35 | |
36 | 36 | $field_name = 'item_meta[' . $field_id . ']'; |
37 | - $html_id = FrmFieldsHelper::get_html_id($field); |
|
37 | + $html_id = FrmFieldsHelper::get_html_id($field); |
|
38 | 38 | |
39 | - ob_start(); |
|
39 | + ob_start(); |
|
40 | 40 | include( $path . '/classes/views/frm-forms/add_field.php' ); |
41 | - $field_html[ $field_id ] = ob_get_contents(); |
|
42 | - ob_end_clean(); |
|
43 | - } |
|
41 | + $field_html[ $field_id ] = ob_get_contents(); |
|
42 | + ob_end_clean(); |
|
43 | + } |
|
44 | 44 | |
45 | - unset($path); |
|
45 | + unset($path); |
|
46 | 46 | |
47 | - echo json_encode($field_html); |
|
47 | + echo json_encode($field_html); |
|
48 | 48 | |
49 | - wp_die(); |
|
50 | - } |
|
49 | + wp_die(); |
|
50 | + } |
|
51 | 51 | |
52 | 52 | /** |
53 | 53 | * Create a new field with ajax |
54 | 54 | */ |
55 | - public static function create() { |
|
55 | + public static function create() { |
|
56 | 56 | FrmAppHelper::permission_check('frm_edit_forms'); |
57 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
57 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
58 | 58 | |
59 | 59 | $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' ); |
60 | 60 | $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' ); |
61 | 61 | |
62 | 62 | $field = self::include_new_field( $field_type, $form_id ); |
63 | 63 | |
64 | - // this hook will allow for multiple fields to be added at once |
|
65 | - do_action('frm_after_field_created', $field, $form_id); |
|
64 | + // this hook will allow for multiple fields to be added at once |
|
65 | + do_action('frm_after_field_created', $field, $form_id); |
|
66 | 66 | |
67 | - wp_die(); |
|
68 | - } |
|
67 | + wp_die(); |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Set up and create a new field |
|
72 | - * |
|
73 | - * @param string $field_type |
|
74 | - * @param integer $form_id |
|
75 | - * @return array|bool |
|
76 | - */ |
|
70 | + /** |
|
71 | + * Set up and create a new field |
|
72 | + * |
|
73 | + * @param string $field_type |
|
74 | + * @param integer $form_id |
|
75 | + * @return array|bool |
|
76 | + */ |
|
77 | 77 | public static function include_new_field( $field_type, $form_id ) { |
78 | - $values = array(); |
|
79 | - if ( FrmAppHelper::pro_is_installed() ) { |
|
80 | - $values['post_type'] = FrmProFormsHelper::post_type($form_id); |
|
81 | - } |
|
78 | + $values = array(); |
|
79 | + if ( FrmAppHelper::pro_is_installed() ) { |
|
80 | + $values['post_type'] = FrmProFormsHelper::post_type($form_id); |
|
81 | + } |
|
82 | 82 | |
83 | 83 | $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id ); |
84 | - $field_values = apply_filters( 'frm_before_field_created', $field_values ); |
|
84 | + $field_values = apply_filters( 'frm_before_field_created', $field_values ); |
|
85 | 85 | |
86 | - $field_id = FrmField::create( $field_values ); |
|
86 | + $field_id = FrmField::create( $field_values ); |
|
87 | 87 | |
88 | - if ( ! $field_id ) { |
|
89 | - return false; |
|
90 | - } |
|
88 | + if ( ! $field_id ) { |
|
89 | + return false; |
|
90 | + } |
|
91 | 91 | |
92 | - $field = self::include_single_field($field_id, $values, $form_id); |
|
92 | + $field = self::include_single_field($field_id, $values, $form_id); |
|
93 | 93 | |
94 | - return $field; |
|
95 | - } |
|
94 | + return $field; |
|
95 | + } |
|
96 | 96 | |
97 | 97 | public static function edit_name( $field = 'name', $id = '' ) { |
98 | 98 | FrmAppHelper::permission_check('frm_edit_forms'); |
99 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
99 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
100 | 100 | |
101 | - if ( empty($field) ) { |
|
102 | - $field = 'name'; |
|
103 | - } |
|
101 | + if ( empty($field) ) { |
|
102 | + $field = 'name'; |
|
103 | + } |
|
104 | 104 | |
105 | - if ( empty($id) ) { |
|
105 | + if ( empty($id) ) { |
|
106 | 106 | $id = FrmAppHelper::get_post_param( 'element_id', '', 'sanitize_title' ); |
107 | 107 | $id = str_replace( 'field_label_', '', $id ); |
108 | - } |
|
108 | + } |
|
109 | 109 | |
110 | 110 | $value = FrmAppHelper::get_post_param( 'update_value', '', 'wp_kses_post' ); |
111 | 111 | $value = trim( $value ); |
112 | - if ( trim(strip_tags($value)) == '' ) { |
|
113 | - // set blank value if there is no content |
|
114 | - $value = ''; |
|
115 | - } |
|
112 | + if ( trim(strip_tags($value)) == '' ) { |
|
113 | + // set blank value if there is no content |
|
114 | + $value = ''; |
|
115 | + } |
|
116 | 116 | |
117 | 117 | FrmField::update( $id, array( $field => $value ) ); |
118 | 118 | |
119 | 119 | do_action( 'frm_after_update_field_' . $field, compact( 'id', 'value' ) ); |
120 | 120 | |
121 | 121 | echo stripslashes( wp_kses_post( $value ) ); |
122 | - wp_die(); |
|
123 | - } |
|
122 | + wp_die(); |
|
123 | + } |
|
124 | 124 | |
125 | - public static function update_ajax_option() { |
|
125 | + public static function update_ajax_option() { |
|
126 | 126 | FrmAppHelper::permission_check('frm_edit_forms'); |
127 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
127 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
128 | 128 | |
129 | 129 | $field_id = FrmAppHelper::get_post_param( 'field', 0, 'absint' ); |
130 | 130 | if ( ! $field_id ) { |
@@ -139,388 +139,388 @@ discard block |
||
139 | 139 | unset($new_val); |
140 | 140 | } |
141 | 141 | |
142 | - FrmField::update( $field_id, array( |
|
143 | - 'field_options' => $field->field_options, |
|
142 | + FrmField::update( $field_id, array( |
|
143 | + 'field_options' => $field->field_options, |
|
144 | 144 | 'form_id' => $field->form_id, |
145 | - ) ); |
|
146 | - wp_die(); |
|
147 | - } |
|
145 | + ) ); |
|
146 | + wp_die(); |
|
147 | + } |
|
148 | 148 | |
149 | - public static function duplicate() { |
|
149 | + public static function duplicate() { |
|
150 | 150 | FrmAppHelper::permission_check('frm_edit_forms'); |
151 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
151 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
152 | 152 | |
153 | - global $wpdb; |
|
153 | + global $wpdb; |
|
154 | 154 | |
155 | 155 | $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); |
156 | 156 | $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' ); |
157 | 157 | |
158 | 158 | $copy_field = FrmField::getOne( $field_id ); |
159 | - if ( ! $copy_field ) { |
|
160 | - wp_die(); |
|
161 | - } |
|
159 | + if ( ! $copy_field ) { |
|
160 | + wp_die(); |
|
161 | + } |
|
162 | 162 | |
163 | 163 | do_action( 'frm_duplicate_field', $copy_field, $form_id ); |
164 | 164 | do_action( 'frm_duplicate_field_' . $copy_field->type, $copy_field, $form_id ); |
165 | 165 | |
166 | 166 | $values = array(); |
167 | - FrmFieldsHelper::fill_field( $values, $copy_field, $form_id ); |
|
167 | + FrmFieldsHelper::fill_field( $values, $copy_field, $form_id ); |
|
168 | 168 | |
169 | 169 | $field_count = FrmDb::get_count( $wpdb->prefix . 'frm_fields fi LEFT JOIN ' . $wpdb->prefix . 'frm_forms fr ON (fi.form_id = fr.id)', array( 'or' => 1, 'fr.id' => $form_id, 'fr.parent_form_id' => $form_id ) ); |
170 | 170 | |
171 | - $values['field_order'] = $field_count + 1; |
|
171 | + $values['field_order'] = $field_count + 1; |
|
172 | 172 | |
173 | - $values = apply_filters( 'frm_prepare_single_field_for_duplication', $values ); |
|
173 | + $values = apply_filters( 'frm_prepare_single_field_for_duplication', $values ); |
|
174 | 174 | |
175 | - if ( ! $field_id = FrmField::create($values) ) { |
|
176 | - wp_die(); |
|
177 | - } |
|
175 | + if ( ! $field_id = FrmField::create($values) ) { |
|
176 | + wp_die(); |
|
177 | + } |
|
178 | 178 | |
179 | - self::include_single_field($field_id, $values); |
|
179 | + self::include_single_field($field_id, $values); |
|
180 | 180 | |
181 | - wp_die(); |
|
182 | - } |
|
181 | + wp_die(); |
|
182 | + } |
|
183 | 183 | |
184 | - /** |
|
185 | - * Load a single field in the form builder along with all needed variables |
|
186 | - */ |
|
187 | - public static function include_single_field( $field_id, $values, $form_id = 0 ) { |
|
188 | - $field = FrmFieldsHelper::setup_edit_vars(FrmField::getOne($field_id)); |
|
184 | + /** |
|
185 | + * Load a single field in the form builder along with all needed variables |
|
186 | + */ |
|
187 | + public static function include_single_field( $field_id, $values, $form_id = 0 ) { |
|
188 | + $field = FrmFieldsHelper::setup_edit_vars(FrmField::getOne($field_id)); |
|
189 | 189 | $field_name = 'item_meta[' . $field_id . ']'; |
190 | - $html_id = FrmFieldsHelper::get_html_id($field); |
|
191 | - $id = $form_id ? $form_id : $field['form_id']; |
|
192 | - if ( $field['type'] == 'html' ) { |
|
193 | - $field['stop_filter'] = true; |
|
194 | - } |
|
190 | + $html_id = FrmFieldsHelper::get_html_id($field); |
|
191 | + $id = $form_id ? $form_id : $field['form_id']; |
|
192 | + if ( $field['type'] == 'html' ) { |
|
193 | + $field['stop_filter'] = true; |
|
194 | + } |
|
195 | 195 | |
196 | 196 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-forms/add_field.php' ); |
197 | 197 | |
198 | - return $field; |
|
199 | - } |
|
198 | + return $field; |
|
199 | + } |
|
200 | 200 | |
201 | - public static function destroy() { |
|
201 | + public static function destroy() { |
|
202 | 202 | FrmAppHelper::permission_check('frm_edit_forms'); |
203 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
203 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
204 | 204 | |
205 | 205 | $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); |
206 | 206 | FrmField::destroy( $field_id ); |
207 | - wp_die(); |
|
208 | - } |
|
207 | + wp_die(); |
|
208 | + } |
|
209 | 209 | |
210 | - /* Field Options */ |
|
210 | + /* Field Options */ |
|
211 | 211 | |
212 | - //Add Single Option or Other Option |
|
213 | - public static function add_option() { |
|
212 | + //Add Single Option or Other Option |
|
213 | + public static function add_option() { |
|
214 | 214 | FrmAppHelper::permission_check('frm_edit_forms'); |
215 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
215 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
216 | 216 | |
217 | 217 | $id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); |
218 | 218 | $opt_type = FrmAppHelper::get_post_param( 'opt_type', '', 'sanitize_text_field' ); |
219 | 219 | $opt_key = FrmAppHelper::get_post_param( 'opt_key', 0, 'absint' ); |
220 | 220 | |
221 | - $field = FrmField::getOne($id); |
|
221 | + $field = FrmField::getOne($id); |
|
222 | 222 | |
223 | - if ( 'other' == $opt_type ) { |
|
223 | + if ( 'other' == $opt_type ) { |
|
224 | 224 | $opt = __( 'Other', 'formidable' ); |
225 | - $other_val = ''; |
|
226 | - $opt_key = 'other_' . $opt_key; |
|
227 | - } else { |
|
225 | + $other_val = ''; |
|
226 | + $opt_key = 'other_' . $opt_key; |
|
227 | + } else { |
|
228 | 228 | $opt = __( 'New Option', 'formidable' ); |
229 | - } |
|
230 | - $field_val = $opt; |
|
229 | + } |
|
230 | + $field_val = $opt; |
|
231 | 231 | |
232 | - $field_data = $field; |
|
232 | + $field_data = $field; |
|
233 | 233 | $field = (array) $field; |
234 | 234 | $field['separate_value'] = isset( $field_data->field_options['separate_value'] ) ? $field_data->field_options['separate_value'] : 0; |
235 | 235 | unset( $field_data ); |
236 | 236 | |
237 | 237 | $field_name = 'item_meta[' . $id . ']'; |
238 | 238 | $html_id = FrmFieldsHelper::get_html_id( $field ); |
239 | - $checked = ''; |
|
239 | + $checked = ''; |
|
240 | 240 | |
241 | - if ( 'other' == $opt_type ) { |
|
241 | + if ( 'other' == $opt_type ) { |
|
242 | 242 | include( FrmAppHelper::plugin_path() . '/pro/classes/views/frmpro-fields/other-option.php' ); |
243 | - } else { |
|
243 | + } else { |
|
244 | 244 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/single-option.php' ); |
245 | - } |
|
246 | - wp_die(); |
|
247 | - } |
|
245 | + } |
|
246 | + wp_die(); |
|
247 | + } |
|
248 | 248 | |
249 | - public static function edit_option() { |
|
249 | + public static function edit_option() { |
|
250 | 250 | _deprecated_function( __FUNCTION__, '2.3' ); |
251 | - } |
|
251 | + } |
|
252 | 252 | |
253 | - public static function delete_option() { |
|
253 | + public static function delete_option() { |
|
254 | 254 | _deprecated_function( __FUNCTION__, '2.3' ); |
255 | - } |
|
255 | + } |
|
256 | 256 | |
257 | - public static function import_choices() { |
|
258 | - FrmAppHelper::permission_check( 'frm_edit_forms', 'hide' ); |
|
257 | + public static function import_choices() { |
|
258 | + FrmAppHelper::permission_check( 'frm_edit_forms', 'hide' ); |
|
259 | 259 | |
260 | 260 | $field_id = absint( $_REQUEST['field_id'] ); |
261 | 261 | |
262 | - global $current_screen, $hook_suffix; |
|
262 | + global $current_screen, $hook_suffix; |
|
263 | 263 | |
264 | - // Catch plugins that include admin-header.php before admin.php completes. |
|
265 | - if ( empty( $current_screen ) && function_exists( 'set_current_screen' ) ) { |
|
266 | - $hook_suffix = ''; |
|
267 | - set_current_screen(); |
|
268 | - } |
|
264 | + // Catch plugins that include admin-header.php before admin.php completes. |
|
265 | + if ( empty( $current_screen ) && function_exists( 'set_current_screen' ) ) { |
|
266 | + $hook_suffix = ''; |
|
267 | + set_current_screen(); |
|
268 | + } |
|
269 | 269 | |
270 | - if ( function_exists( 'register_admin_color_schemes' ) ) { |
|
271 | - register_admin_color_schemes(); |
|
272 | - } |
|
270 | + if ( function_exists( 'register_admin_color_schemes' ) ) { |
|
271 | + register_admin_color_schemes(); |
|
272 | + } |
|
273 | 273 | |
274 | - $hook_suffix = $admin_body_class = ''; |
|
274 | + $hook_suffix = $admin_body_class = ''; |
|
275 | 275 | |
276 | - if ( get_user_setting( 'mfold' ) == 'f' ) { |
|
277 | - $admin_body_class .= ' folded'; |
|
278 | - } |
|
276 | + if ( get_user_setting( 'mfold' ) == 'f' ) { |
|
277 | + $admin_body_class .= ' folded'; |
|
278 | + } |
|
279 | 279 | |
280 | - if ( function_exists( 'is_admin_bar_showing' ) && is_admin_bar_showing() ) { |
|
281 | - $admin_body_class .= ' admin-bar'; |
|
282 | - } |
|
280 | + if ( function_exists( 'is_admin_bar_showing' ) && is_admin_bar_showing() ) { |
|
281 | + $admin_body_class .= ' admin-bar'; |
|
282 | + } |
|
283 | 283 | |
284 | - if ( is_rtl() ) { |
|
285 | - $admin_body_class .= ' rtl'; |
|
286 | - } |
|
284 | + if ( is_rtl() ) { |
|
285 | + $admin_body_class .= ' rtl'; |
|
286 | + } |
|
287 | 287 | |
288 | - $admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' ); |
|
289 | - $prepop = array(); |
|
290 | - FrmFieldsHelper::get_bulk_prefilled_opts($prepop); |
|
288 | + $admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' ); |
|
289 | + $prepop = array(); |
|
290 | + FrmFieldsHelper::get_bulk_prefilled_opts($prepop); |
|
291 | 291 | |
292 | - $field = FrmField::getOne($field_id); |
|
292 | + $field = FrmField::getOne($field_id); |
|
293 | 293 | |
294 | - wp_enqueue_script( 'utils' ); |
|
294 | + wp_enqueue_script( 'utils' ); |
|
295 | 295 | wp_enqueue_style( 'formidable-admin', FrmAppHelper::plugin_url() . '/css/frm_admin.css' ); |
296 | - FrmAppHelper::load_admin_wide_js(); |
|
296 | + FrmAppHelper::load_admin_wide_js(); |
|
297 | 297 | |
298 | 298 | include( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/import_choices.php' ); |
299 | - wp_die(); |
|
300 | - } |
|
299 | + wp_die(); |
|
300 | + } |
|
301 | 301 | |
302 | - public static function import_options() { |
|
302 | + public static function import_options() { |
|
303 | 303 | FrmAppHelper::permission_check('frm_edit_forms'); |
304 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
304 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
305 | 305 | |
306 | - if ( ! is_admin() || ! current_user_can('frm_edit_forms') ) { |
|
307 | - return; |
|
308 | - } |
|
306 | + if ( ! is_admin() || ! current_user_can('frm_edit_forms') ) { |
|
307 | + return; |
|
308 | + } |
|
309 | 309 | |
310 | 310 | $field_id = absint( $_POST['field_id'] ); |
311 | - $field = FrmField::getOne($field_id); |
|
311 | + $field = FrmField::getOne($field_id); |
|
312 | 312 | |
313 | 313 | if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) { |
314 | - return; |
|
315 | - } |
|
314 | + return; |
|
315 | + } |
|
316 | 316 | |
317 | - $field = FrmFieldsHelper::setup_edit_vars($field); |
|
317 | + $field = FrmFieldsHelper::setup_edit_vars($field); |
|
318 | 318 | $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' ); |
319 | 319 | $opts = explode( "\n", rtrim( $opts, "\n" ) ); |
320 | 320 | $opts = array_map( 'trim', $opts ); |
321 | 321 | |
322 | - if ( $field['separate_value'] ) { |
|
323 | - foreach ( $opts as $opt_key => $opt ) { |
|
324 | - if ( strpos($opt, '|') !== false ) { |
|
325 | - $vals = explode('|', $opt); |
|
326 | - if ( $vals[0] != $vals[1] ) { |
|
327 | - $opts[ $opt_key ] = array( 'label' => trim( $vals[0] ), 'value' => trim( $vals[1] ) ); |
|
328 | - } |
|
329 | - unset($vals); |
|
330 | - } |
|
331 | - unset($opt_key, $opt); |
|
332 | - } |
|
333 | - } |
|
334 | - |
|
335 | - //Keep other options after bulk update |
|
336 | - if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) { |
|
337 | - $other_array = array(); |
|
338 | - foreach ( $field['options'] as $opt_key => $opt ) { |
|
339 | - if ( $opt_key && strpos( $opt_key, 'other' ) !== false ) { |
|
340 | - $other_array[ $opt_key ] = $opt; |
|
341 | - } |
|
342 | - unset($opt_key, $opt); |
|
343 | - } |
|
344 | - if ( ! empty($other_array) ) { |
|
345 | - $opts = array_merge( $opts, $other_array); |
|
346 | - } |
|
347 | - } |
|
348 | - |
|
349 | - $field['options'] = $opts; |
|
350 | - |
|
351 | - if ( $field['type'] == 'radio' || $field['type'] == 'checkbox' ) { |
|
322 | + if ( $field['separate_value'] ) { |
|
323 | + foreach ( $opts as $opt_key => $opt ) { |
|
324 | + if ( strpos($opt, '|') !== false ) { |
|
325 | + $vals = explode('|', $opt); |
|
326 | + if ( $vals[0] != $vals[1] ) { |
|
327 | + $opts[ $opt_key ] = array( 'label' => trim( $vals[0] ), 'value' => trim( $vals[1] ) ); |
|
328 | + } |
|
329 | + unset($vals); |
|
330 | + } |
|
331 | + unset($opt_key, $opt); |
|
332 | + } |
|
333 | + } |
|
334 | + |
|
335 | + //Keep other options after bulk update |
|
336 | + if ( isset( $field['field_options']['other'] ) && $field['field_options']['other'] == true ) { |
|
337 | + $other_array = array(); |
|
338 | + foreach ( $field['options'] as $opt_key => $opt ) { |
|
339 | + if ( $opt_key && strpos( $opt_key, 'other' ) !== false ) { |
|
340 | + $other_array[ $opt_key ] = $opt; |
|
341 | + } |
|
342 | + unset($opt_key, $opt); |
|
343 | + } |
|
344 | + if ( ! empty($other_array) ) { |
|
345 | + $opts = array_merge( $opts, $other_array); |
|
346 | + } |
|
347 | + } |
|
348 | + |
|
349 | + $field['options'] = $opts; |
|
350 | + |
|
351 | + if ( $field['type'] == 'radio' || $field['type'] == 'checkbox' ) { |
|
352 | 352 | $field_name = 'item_meta[' . $id . ']'; |
353 | 353 | |
354 | 354 | // Get html_id which will be used in single-option.php |
355 | 355 | $html_id = FrmFieldsHelper::get_html_id( $field ); |
356 | 356 | |
357 | 357 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/radio.php' ); |
358 | - } else { |
|
359 | - FrmFieldsHelper::show_single_option($field); |
|
360 | - } |
|
358 | + } else { |
|
359 | + FrmFieldsHelper::show_single_option($field); |
|
360 | + } |
|
361 | 361 | |
362 | - wp_die(); |
|
363 | - } |
|
362 | + wp_die(); |
|
363 | + } |
|
364 | 364 | |
365 | - public static function update_order() { |
|
365 | + public static function update_order() { |
|
366 | 366 | FrmAppHelper::permission_check('frm_edit_forms'); |
367 | - check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
367 | + check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
368 | 368 | |
369 | 369 | $fields = FrmAppHelper::get_post_param( 'frm_field_id' ); |
370 | 370 | foreach ( (array) $fields as $position => $item ) { |
371 | 371 | FrmField::update( absint( $item ), array( 'field_order' => absint( $position ) ) ); |
372 | 372 | } |
373 | - wp_die(); |
|
374 | - } |
|
373 | + wp_die(); |
|
374 | + } |
|
375 | 375 | |
376 | 376 | public static function change_type( $type ) { |
377 | - $type_switch = array( |
|
378 | - 'scale' => 'radio', |
|
379 | - '10radio' => 'radio', |
|
380 | - 'rte' => 'textarea', |
|
381 | - 'website' => 'url', |
|
382 | - ); |
|
383 | - if ( isset( $type_switch[ $type ] ) ) { |
|
384 | - $type = $type_switch[ $type ]; |
|
385 | - } |
|
377 | + $type_switch = array( |
|
378 | + 'scale' => 'radio', |
|
379 | + '10radio' => 'radio', |
|
380 | + 'rte' => 'textarea', |
|
381 | + 'website' => 'url', |
|
382 | + ); |
|
383 | + if ( isset( $type_switch[ $type ] ) ) { |
|
384 | + $type = $type_switch[ $type ]; |
|
385 | + } |
|
386 | 386 | |
387 | 387 | $frm_field_selection = FrmField::field_selection(); |
388 | - $types = array_keys($frm_field_selection); |
|
389 | - if ( ! in_array($type, $types) && $type != 'captcha' ) { |
|
390 | - $type = 'text'; |
|
391 | - } |
|
388 | + $types = array_keys($frm_field_selection); |
|
389 | + if ( ! in_array($type, $types) && $type != 'captcha' ) { |
|
390 | + $type = 'text'; |
|
391 | + } |
|
392 | 392 | |
393 | - return $type; |
|
394 | - } |
|
393 | + return $type; |
|
394 | + } |
|
395 | 395 | |
396 | 396 | public static function display_field_options( $display ) { |
397 | 397 | switch ( $display['type'] ) { |
398 | - case 'captcha': |
|
399 | - $display['required'] = false; |
|
400 | - $display['invalid'] = true; |
|
401 | - $display['default_blank'] = false; |
|
398 | + case 'captcha': |
|
399 | + $display['required'] = false; |
|
400 | + $display['invalid'] = true; |
|
401 | + $display['default_blank'] = false; |
|
402 | 402 | $display['captcha_size'] = true; |
403 | - break; |
|
404 | - case 'radio': |
|
405 | - $display['default_blank'] = false; |
|
406 | - break; |
|
407 | - case 'text': |
|
408 | - case 'textarea': |
|
409 | - $display['size'] = true; |
|
410 | - $display['clear_on_focus'] = true; |
|
411 | - break; |
|
412 | - case 'select': |
|
413 | - $display['size'] = true; |
|
414 | - break; |
|
415 | - case 'url': |
|
416 | - case 'website': |
|
417 | - case 'email': |
|
418 | - $display['size'] = true; |
|
419 | - $display['clear_on_focus'] = true; |
|
420 | - $display['invalid'] = true; |
|
421 | - } |
|
422 | - |
|
423 | - return $display; |
|
424 | - } |
|
425 | - |
|
426 | - public static function input_html( $field, $echo = true ) { |
|
427 | - $class = array(); //$field['type']; |
|
428 | - self::add_input_classes($field, $class); |
|
429 | - |
|
430 | - $add_html = array(); |
|
431 | - self::add_html_size($field, $add_html); |
|
432 | - self::add_html_length($field, $add_html); |
|
433 | - self::add_html_placeholder($field, $add_html, $class); |
|
403 | + break; |
|
404 | + case 'radio': |
|
405 | + $display['default_blank'] = false; |
|
406 | + break; |
|
407 | + case 'text': |
|
408 | + case 'textarea': |
|
409 | + $display['size'] = true; |
|
410 | + $display['clear_on_focus'] = true; |
|
411 | + break; |
|
412 | + case 'select': |
|
413 | + $display['size'] = true; |
|
414 | + break; |
|
415 | + case 'url': |
|
416 | + case 'website': |
|
417 | + case 'email': |
|
418 | + $display['size'] = true; |
|
419 | + $display['clear_on_focus'] = true; |
|
420 | + $display['invalid'] = true; |
|
421 | + } |
|
422 | + |
|
423 | + return $display; |
|
424 | + } |
|
425 | + |
|
426 | + public static function input_html( $field, $echo = true ) { |
|
427 | + $class = array(); //$field['type']; |
|
428 | + self::add_input_classes($field, $class); |
|
429 | + |
|
430 | + $add_html = array(); |
|
431 | + self::add_html_size($field, $add_html); |
|
432 | + self::add_html_length($field, $add_html); |
|
433 | + self::add_html_placeholder($field, $add_html, $class); |
|
434 | 434 | self::add_validation_messages( $field, $add_html ); |
435 | 435 | |
436 | - $class = apply_filters('frm_field_classes', implode(' ', $class), $field); |
|
436 | + $class = apply_filters('frm_field_classes', implode(' ', $class), $field); |
|
437 | 437 | |
438 | 438 | FrmFormsHelper::add_html_attr( $class, 'class', $add_html ); |
439 | 439 | |
440 | - self::add_shortcodes_to_html($field, $add_html); |
|
440 | + self::add_shortcodes_to_html($field, $add_html); |
|
441 | 441 | |
442 | 442 | $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field ); |
443 | 443 | $add_html = ' ' . implode( ' ', $add_html ) . ' '; |
444 | 444 | |
445 | - if ( $echo ) { |
|
446 | - echo $add_html; |
|
447 | - } |
|
445 | + if ( $echo ) { |
|
446 | + echo $add_html; |
|
447 | + } |
|
448 | 448 | |
449 | - return $add_html; |
|
450 | - } |
|
449 | + return $add_html; |
|
450 | + } |
|
451 | 451 | |
452 | 452 | private static function add_input_classes( $field, array &$class ) { |
453 | - if ( isset($field['input_class']) && ! empty($field['input_class']) ) { |
|
454 | - $class[] = $field['input_class']; |
|
455 | - } |
|
453 | + if ( isset($field['input_class']) && ! empty($field['input_class']) ) { |
|
454 | + $class[] = $field['input_class']; |
|
455 | + } |
|
456 | 456 | |
457 | - if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) { |
|
458 | - return; |
|
459 | - } |
|
457 | + if ( $field['type'] == 'hidden' || $field['type'] == 'user_id' ) { |
|
458 | + return; |
|
459 | + } |
|
460 | 460 | |
461 | - if ( isset($field['size']) && $field['size'] > 0 ) { |
|
462 | - $class[] = 'auto_width'; |
|
463 | - } |
|
464 | - } |
|
461 | + if ( isset($field['size']) && $field['size'] > 0 ) { |
|
462 | + $class[] = 'auto_width'; |
|
463 | + } |
|
464 | + } |
|
465 | 465 | |
466 | 466 | private static function add_html_size( $field, array &$add_html ) { |
467 | 467 | if ( ! isset( $field['size'] ) || $field['size'] <= 0 || in_array( $field['type'], array( 'select', 'data', 'time', 'hidden', 'file', 'lookup' ) ) ) { |
468 | - return; |
|
469 | - } |
|
468 | + return; |
|
469 | + } |
|
470 | 470 | |
471 | - if ( FrmAppHelper::is_admin_page('formidable' ) ) { |
|
472 | - return; |
|
473 | - } |
|
471 | + if ( FrmAppHelper::is_admin_page('formidable' ) ) { |
|
472 | + return; |
|
473 | + } |
|
474 | 474 | |
475 | - if ( is_numeric($field['size']) ) { |
|
476 | - $field['size'] .= 'px'; |
|
477 | - } |
|
475 | + if ( is_numeric($field['size']) ) { |
|
476 | + $field['size'] .= 'px'; |
|
477 | + } |
|
478 | 478 | |
479 | - $important = apply_filters('frm_use_important_width', 1, $field); |
|
480 | - // Note: This inline styling must stay since we cannot realistically set a class for every possible field size |
|
479 | + $important = apply_filters('frm_use_important_width', 1, $field); |
|
480 | + // Note: This inline styling must stay since we cannot realistically set a class for every possible field size |
|
481 | 481 | $add_html['style'] = 'style="width:' . esc_attr( $field['size'] ) . ( $important ? ' !important' : '' ) . '"'; |
482 | 482 | |
483 | - self::add_html_cols($field, $add_html); |
|
484 | - } |
|
483 | + self::add_html_cols($field, $add_html); |
|
484 | + } |
|
485 | 485 | |
486 | 486 | private static function add_html_cols( $field, array &$add_html ) { |
487 | 487 | if ( ! in_array( $field['type'], array( 'textarea', 'rte' ) ) ) { |
488 | - return; |
|
489 | - } |
|
488 | + return; |
|
489 | + } |
|
490 | 490 | |
491 | - // convert to cols for textareas |
|
492 | - $calc = array( |
|
493 | - '' => 9, |
|
494 | - 'px' => 9, |
|
495 | - 'rem' => 0.444, |
|
496 | - 'em' => 0.544, |
|
497 | - ); |
|
491 | + // convert to cols for textareas |
|
492 | + $calc = array( |
|
493 | + '' => 9, |
|
494 | + 'px' => 9, |
|
495 | + 'rem' => 0.444, |
|
496 | + 'em' => 0.544, |
|
497 | + ); |
|
498 | 498 | |
499 | - // include "col" for valid html |
|
500 | - $unit = trim(preg_replace('/[0-9]+/', '', $field['size'])); |
|
499 | + // include "col" for valid html |
|
500 | + $unit = trim(preg_replace('/[0-9]+/', '', $field['size'])); |
|
501 | 501 | |
502 | - if ( ! isset( $calc[ $unit ] ) ) { |
|
503 | - return; |
|
504 | - } |
|
502 | + if ( ! isset( $calc[ $unit ] ) ) { |
|
503 | + return; |
|
504 | + } |
|
505 | 505 | |
506 | - $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ]; |
|
506 | + $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ]; |
|
507 | 507 | |
508 | 508 | $add_html['cols'] = 'cols="' . absint( $size ) . '"'; |
509 | - } |
|
509 | + } |
|
510 | 510 | |
511 | 511 | private static function add_html_length( $field, array &$add_html ) { |
512 | - // check for max setting and if this field accepts maxlength |
|
512 | + // check for max setting and if this field accepts maxlength |
|
513 | 513 | if ( FrmField::is_option_empty( $field, 'max' ) || in_array( $field['type'], array( 'textarea', 'rte', 'hidden', 'file' ) ) ) { |
514 | - return; |
|
515 | - } |
|
514 | + return; |
|
515 | + } |
|
516 | 516 | |
517 | - if ( FrmAppHelper::is_admin_page('formidable' ) ) { |
|
518 | - // don't load on form builder page |
|
519 | - return; |
|
520 | - } |
|
517 | + if ( FrmAppHelper::is_admin_page('formidable' ) ) { |
|
518 | + // don't load on form builder page |
|
519 | + return; |
|
520 | + } |
|
521 | 521 | |
522 | 522 | $add_html['maxlength'] = 'maxlength="' . esc_attr( $field['max'] ) . '"'; |
523 | - } |
|
523 | + } |
|
524 | 524 | |
525 | 525 | private static function add_html_placeholder( $field, array &$add_html, array &$class ) { |
526 | 526 | if ( empty( $field['default_value'] ) || FrmAppHelper::is_admin_page( 'formidable' ) ) { |
@@ -528,35 +528,35 @@ discard block |
||
528 | 528 | } |
529 | 529 | |
530 | 530 | $default_value_array = is_array( $field['default_value'] ); |
531 | - if ( ! FrmField::is_option_true( $field, 'clear_on_focus' ) ) { |
|
531 | + if ( ! FrmField::is_option_true( $field, 'clear_on_focus' ) ) { |
|
532 | 532 | if ( $default_value_array ) { |
533 | 533 | $field['default_value'] = json_encode( $field['default_value'] ); |
534 | 534 | } |
535 | 535 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $field['default_value'] ) . '"'; |
536 | - return; |
|
537 | - } |
|
536 | + return; |
|
537 | + } |
|
538 | 538 | |
539 | 539 | if ( $default_value_array ) { |
540 | 540 | // don't include a json placeholder |
541 | 541 | return; |
542 | 542 | } |
543 | 543 | |
544 | - $frm_settings = FrmAppHelper::get_settings(); |
|
544 | + $frm_settings = FrmAppHelper::get_settings(); |
|
545 | 545 | |
546 | 546 | if ( $frm_settings->use_html && ! in_array( $field['type'], array( 'select', 'radio', 'checkbox', 'hidden' ) ) ) { |
547 | - // use HMTL5 placeholder with js fallback |
|
547 | + // use HMTL5 placeholder with js fallback |
|
548 | 548 | $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['default_value'] ) . '"'; |
549 | - wp_enqueue_script('jquery-placeholder'); |
|
550 | - } else if ( ! $frm_settings->use_html ) { |
|
549 | + wp_enqueue_script('jquery-placeholder'); |
|
550 | + } else if ( ! $frm_settings->use_html ) { |
|
551 | 551 | $val = str_replace( array( "\r\n", "\n" ), '\r', addslashes( str_replace( ''', "'", esc_attr( $field['default_value'] ) ) ) ); |
552 | 552 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $val ) . '"'; |
553 | - $class[] = 'frm_toggle_default'; |
|
553 | + $class[] = 'frm_toggle_default'; |
|
554 | 554 | |
555 | - if ( $field['value'] == $field['default_value'] ) { |
|
556 | - $class[] = 'frm_default'; |
|
557 | - } |
|
558 | - } |
|
559 | - } |
|
555 | + if ( $field['value'] == $field['default_value'] ) { |
|
556 | + $class[] = 'frm_default'; |
|
557 | + } |
|
558 | + } |
|
559 | + } |
|
560 | 560 | |
561 | 561 | private static function add_validation_messages( $field, array &$add_html ) { |
562 | 562 | if ( FrmField::is_required( $field ) ) { |
@@ -570,44 +570,44 @@ discard block |
||
570 | 570 | } |
571 | 571 | } |
572 | 572 | |
573 | - private static function add_shortcodes_to_html( $field, array &$add_html ) { |
|
574 | - if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) { |
|
575 | - return; |
|
576 | - } |
|
573 | + private static function add_shortcodes_to_html( $field, array &$add_html ) { |
|
574 | + if ( FrmField::is_option_empty( $field, 'shortcodes' ) ) { |
|
575 | + return; |
|
576 | + } |
|
577 | 577 | |
578 | - foreach ( $field['shortcodes'] as $k => $v ) { |
|
579 | - if ( 'opt' === $k ) { |
|
580 | - continue; |
|
581 | - } |
|
578 | + foreach ( $field['shortcodes'] as $k => $v ) { |
|
579 | + if ( 'opt' === $k ) { |
|
580 | + continue; |
|
581 | + } |
|
582 | 582 | |
583 | - if ( is_numeric($k) && strpos($v, '=') ) { |
|
584 | - $add_html[] = $v; |
|
585 | - } else if ( ! empty( $k ) && isset( $add_html[ $k ] ) ) { |
|
583 | + if ( is_numeric($k) && strpos($v, '=') ) { |
|
584 | + $add_html[] = $v; |
|
585 | + } else if ( ! empty( $k ) && isset( $add_html[ $k ] ) ) { |
|
586 | 586 | $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] ); |
587 | - } else { |
|
587 | + } else { |
|
588 | 588 | $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"'; |
589 | - } |
|
590 | - |
|
591 | - unset($k, $v); |
|
592 | - } |
|
593 | - } |
|
594 | - |
|
595 | - public static function check_value( $opt, $opt_key, $field ) { |
|
596 | - if ( is_array( $opt ) ) { |
|
597 | - if ( FrmField::is_option_true( $field, 'separate_value' ) ) { |
|
598 | - $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) ); |
|
599 | - } else { |
|
600 | - $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt ); |
|
601 | - } |
|
602 | - } |
|
603 | - return $opt; |
|
604 | - } |
|
589 | + } |
|
590 | + |
|
591 | + unset($k, $v); |
|
592 | + } |
|
593 | + } |
|
594 | + |
|
595 | + public static function check_value( $opt, $opt_key, $field ) { |
|
596 | + if ( is_array( $opt ) ) { |
|
597 | + if ( FrmField::is_option_true( $field, 'separate_value' ) ) { |
|
598 | + $opt = isset( $opt['value'] ) ? $opt['value'] : ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) ); |
|
599 | + } else { |
|
600 | + $opt = isset( $opt['label'] ) ? $opt['label'] : reset( $opt ); |
|
601 | + } |
|
602 | + } |
|
603 | + return $opt; |
|
604 | + } |
|
605 | 605 | |
606 | 606 | public static function check_label( $opt ) { |
607 | - if ( is_array($opt) ) { |
|
608 | - $opt = (isset($opt['label']) ? $opt['label'] : reset($opt)); |
|
609 | - } |
|
607 | + if ( is_array($opt) ) { |
|
608 | + $opt = (isset($opt['label']) ? $opt['label'] : reset($opt)); |
|
609 | + } |
|
610 | 610 | |
611 | - return $opt; |
|
612 | - } |
|
611 | + return $opt; |
|
612 | + } |
|
613 | 613 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | class FrmFieldsController { |
4 | 4 | |
5 | 5 | public static function load_field() { |
6 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
6 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
7 | 7 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
8 | 8 | |
9 | 9 | $fields = $_POST['field']; |
@@ -34,17 +34,17 @@ discard block |
||
34 | 34 | } |
35 | 35 | |
36 | 36 | $field_name = 'item_meta[' . $field_id . ']'; |
37 | - $html_id = FrmFieldsHelper::get_html_id($field); |
|
37 | + $html_id = FrmFieldsHelper::get_html_id( $field ); |
|
38 | 38 | |
39 | 39 | ob_start(); |
40 | 40 | include( $path . '/classes/views/frm-forms/add_field.php' ); |
41 | - $field_html[ $field_id ] = ob_get_contents(); |
|
41 | + $field_html[$field_id] = ob_get_contents(); |
|
42 | 42 | ob_end_clean(); |
43 | 43 | } |
44 | 44 | |
45 | - unset($path); |
|
45 | + unset( $path ); |
|
46 | 46 | |
47 | - echo json_encode($field_html); |
|
47 | + echo json_encode( $field_html ); |
|
48 | 48 | |
49 | 49 | wp_die(); |
50 | 50 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | * Create a new field with ajax |
54 | 54 | */ |
55 | 55 | public static function create() { |
56 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
56 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
57 | 57 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
58 | 58 | |
59 | 59 | $field_type = FrmAppHelper::get_post_param( 'field_type', '', 'sanitize_text_field' ); |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | $field = self::include_new_field( $field_type, $form_id ); |
63 | 63 | |
64 | 64 | // this hook will allow for multiple fields to be added at once |
65 | - do_action('frm_after_field_created', $field, $form_id); |
|
65 | + do_action( 'frm_after_field_created', $field, $form_id ); |
|
66 | 66 | |
67 | 67 | wp_die(); |
68 | 68 | } |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | public static function include_new_field( $field_type, $form_id ) { |
78 | 78 | $values = array(); |
79 | 79 | if ( FrmAppHelper::pro_is_installed() ) { |
80 | - $values['post_type'] = FrmProFormsHelper::post_type($form_id); |
|
80 | + $values['post_type'] = FrmProFormsHelper::post_type( $form_id ); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | $field_values = FrmFieldsHelper::setup_new_vars( $field_type, $form_id ); |
@@ -89,27 +89,27 @@ discard block |
||
89 | 89 | return false; |
90 | 90 | } |
91 | 91 | |
92 | - $field = self::include_single_field($field_id, $values, $form_id); |
|
92 | + $field = self::include_single_field( $field_id, $values, $form_id ); |
|
93 | 93 | |
94 | 94 | return $field; |
95 | 95 | } |
96 | 96 | |
97 | 97 | public static function edit_name( $field = 'name', $id = '' ) { |
98 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
98 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
99 | 99 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
100 | 100 | |
101 | - if ( empty($field) ) { |
|
101 | + if ( empty( $field ) ) { |
|
102 | 102 | $field = 'name'; |
103 | 103 | } |
104 | 104 | |
105 | - if ( empty($id) ) { |
|
105 | + if ( empty( $id ) ) { |
|
106 | 106 | $id = FrmAppHelper::get_post_param( 'element_id', '', 'sanitize_title' ); |
107 | 107 | $id = str_replace( 'field_label_', '', $id ); |
108 | 108 | } |
109 | 109 | |
110 | 110 | $value = FrmAppHelper::get_post_param( 'update_value', '', 'wp_kses_post' ); |
111 | 111 | $value = trim( $value ); |
112 | - if ( trim(strip_tags($value)) == '' ) { |
|
112 | + if ( trim( strip_tags( $value ) ) == '' ) { |
|
113 | 113 | // set blank value if there is no content |
114 | 114 | $value = ''; |
115 | 115 | } |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | } |
124 | 124 | |
125 | 125 | public static function update_ajax_option() { |
126 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
126 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
127 | 127 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
128 | 128 | |
129 | 129 | $field_id = FrmAppHelper::get_post_param( 'field', 0, 'absint' ); |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | if ( isset( $_POST['separate_value'] ) ) { |
137 | 137 | $new_val = FrmField::is_option_true( $field, 'separate_value' ) ? 0 : 1; |
138 | 138 | $field->field_options['separate_value'] = $new_val; |
139 | - unset($new_val); |
|
139 | + unset( $new_val ); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | FrmField::update( $field_id, array( |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | } |
148 | 148 | |
149 | 149 | public static function duplicate() { |
150 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
150 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
151 | 151 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
152 | 152 | |
153 | 153 | global $wpdb; |
@@ -172,11 +172,11 @@ discard block |
||
172 | 172 | |
173 | 173 | $values = apply_filters( 'frm_prepare_single_field_for_duplication', $values ); |
174 | 174 | |
175 | - if ( ! $field_id = FrmField::create($values) ) { |
|
175 | + if ( ! $field_id = FrmField::create( $values ) ) { |
|
176 | 176 | wp_die(); |
177 | 177 | } |
178 | 178 | |
179 | - self::include_single_field($field_id, $values); |
|
179 | + self::include_single_field( $field_id, $values ); |
|
180 | 180 | |
181 | 181 | wp_die(); |
182 | 182 | } |
@@ -185,9 +185,9 @@ discard block |
||
185 | 185 | * Load a single field in the form builder along with all needed variables |
186 | 186 | */ |
187 | 187 | public static function include_single_field( $field_id, $values, $form_id = 0 ) { |
188 | - $field = FrmFieldsHelper::setup_edit_vars(FrmField::getOne($field_id)); |
|
188 | + $field = FrmFieldsHelper::setup_edit_vars( FrmField::getOne( $field_id ) ); |
|
189 | 189 | $field_name = 'item_meta[' . $field_id . ']'; |
190 | - $html_id = FrmFieldsHelper::get_html_id($field); |
|
190 | + $html_id = FrmFieldsHelper::get_html_id( $field ); |
|
191 | 191 | $id = $form_id ? $form_id : $field['form_id']; |
192 | 192 | if ( $field['type'] == 'html' ) { |
193 | 193 | $field['stop_filter'] = true; |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | } |
200 | 200 | |
201 | 201 | public static function destroy() { |
202 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
202 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
203 | 203 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
204 | 204 | |
205 | 205 | $field_id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); |
@@ -211,14 +211,14 @@ discard block |
||
211 | 211 | |
212 | 212 | //Add Single Option or Other Option |
213 | 213 | public static function add_option() { |
214 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
214 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
215 | 215 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
216 | 216 | |
217 | 217 | $id = FrmAppHelper::get_post_param( 'field_id', 0, 'absint' ); |
218 | 218 | $opt_type = FrmAppHelper::get_post_param( 'opt_type', '', 'sanitize_text_field' ); |
219 | 219 | $opt_key = FrmAppHelper::get_post_param( 'opt_key', 0, 'absint' ); |
220 | 220 | |
221 | - $field = FrmField::getOne($id); |
|
221 | + $field = FrmField::getOne( $id ); |
|
222 | 222 | |
223 | 223 | if ( 'other' == $opt_type ) { |
224 | 224 | $opt = __( 'Other', 'formidable' ); |
@@ -287,9 +287,9 @@ discard block |
||
287 | 287 | |
288 | 288 | $admin_body_class .= ' admin-color-' . sanitize_html_class( get_user_option( 'admin_color' ), 'fresh' ); |
289 | 289 | $prepop = array(); |
290 | - FrmFieldsHelper::get_bulk_prefilled_opts($prepop); |
|
290 | + FrmFieldsHelper::get_bulk_prefilled_opts( $prepop ); |
|
291 | 291 | |
292 | - $field = FrmField::getOne($field_id); |
|
292 | + $field = FrmField::getOne( $field_id ); |
|
293 | 293 | |
294 | 294 | wp_enqueue_script( 'utils' ); |
295 | 295 | wp_enqueue_style( 'formidable-admin', FrmAppHelper::plugin_url() . '/css/frm_admin.css' ); |
@@ -300,35 +300,35 @@ discard block |
||
300 | 300 | } |
301 | 301 | |
302 | 302 | public static function import_options() { |
303 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
303 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
304 | 304 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
305 | 305 | |
306 | - if ( ! is_admin() || ! current_user_can('frm_edit_forms') ) { |
|
306 | + if ( ! is_admin() || ! current_user_can( 'frm_edit_forms' ) ) { |
|
307 | 307 | return; |
308 | 308 | } |
309 | 309 | |
310 | 310 | $field_id = absint( $_POST['field_id'] ); |
311 | - $field = FrmField::getOne($field_id); |
|
311 | + $field = FrmField::getOne( $field_id ); |
|
312 | 312 | |
313 | 313 | if ( ! in_array( $field->type, array( 'radio', 'checkbox', 'select' ) ) ) { |
314 | 314 | return; |
315 | 315 | } |
316 | 316 | |
317 | - $field = FrmFieldsHelper::setup_edit_vars($field); |
|
317 | + $field = FrmFieldsHelper::setup_edit_vars( $field ); |
|
318 | 318 | $opts = FrmAppHelper::get_param( 'opts', '', 'post', 'wp_kses_post' ); |
319 | 319 | $opts = explode( "\n", rtrim( $opts, "\n" ) ); |
320 | 320 | $opts = array_map( 'trim', $opts ); |
321 | 321 | |
322 | 322 | if ( $field['separate_value'] ) { |
323 | 323 | foreach ( $opts as $opt_key => $opt ) { |
324 | - if ( strpos($opt, '|') !== false ) { |
|
325 | - $vals = explode('|', $opt); |
|
324 | + if ( strpos( $opt, '|' ) !== false ) { |
|
325 | + $vals = explode( '|', $opt ); |
|
326 | 326 | if ( $vals[0] != $vals[1] ) { |
327 | - $opts[ $opt_key ] = array( 'label' => trim( $vals[0] ), 'value' => trim( $vals[1] ) ); |
|
327 | + $opts[$opt_key] = array( 'label' => trim( $vals[0] ), 'value' => trim( $vals[1] ) ); |
|
328 | 328 | } |
329 | - unset($vals); |
|
329 | + unset( $vals ); |
|
330 | 330 | } |
331 | - unset($opt_key, $opt); |
|
331 | + unset( $opt_key, $opt ); |
|
332 | 332 | } |
333 | 333 | } |
334 | 334 | |
@@ -337,12 +337,12 @@ discard block |
||
337 | 337 | $other_array = array(); |
338 | 338 | foreach ( $field['options'] as $opt_key => $opt ) { |
339 | 339 | if ( $opt_key && strpos( $opt_key, 'other' ) !== false ) { |
340 | - $other_array[ $opt_key ] = $opt; |
|
340 | + $other_array[$opt_key] = $opt; |
|
341 | 341 | } |
342 | - unset($opt_key, $opt); |
|
342 | + unset( $opt_key, $opt ); |
|
343 | 343 | } |
344 | - if ( ! empty($other_array) ) { |
|
345 | - $opts = array_merge( $opts, $other_array); |
|
344 | + if ( ! empty( $other_array ) ) { |
|
345 | + $opts = array_merge( $opts, $other_array ); |
|
346 | 346 | } |
347 | 347 | } |
348 | 348 | |
@@ -356,14 +356,14 @@ discard block |
||
356 | 356 | |
357 | 357 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-fields/radio.php' ); |
358 | 358 | } else { |
359 | - FrmFieldsHelper::show_single_option($field); |
|
359 | + FrmFieldsHelper::show_single_option( $field ); |
|
360 | 360 | } |
361 | 361 | |
362 | 362 | wp_die(); |
363 | 363 | } |
364 | 364 | |
365 | 365 | public static function update_order() { |
366 | - FrmAppHelper::permission_check('frm_edit_forms'); |
|
366 | + FrmAppHelper::permission_check( 'frm_edit_forms' ); |
|
367 | 367 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
368 | 368 | |
369 | 369 | $fields = FrmAppHelper::get_post_param( 'frm_field_id' ); |
@@ -380,13 +380,13 @@ discard block |
||
380 | 380 | 'rte' => 'textarea', |
381 | 381 | 'website' => 'url', |
382 | 382 | ); |
383 | - if ( isset( $type_switch[ $type ] ) ) { |
|
384 | - $type = $type_switch[ $type ]; |
|
383 | + if ( isset( $type_switch[$type] ) ) { |
|
384 | + $type = $type_switch[$type]; |
|
385 | 385 | } |
386 | 386 | |
387 | 387 | $frm_field_selection = FrmField::field_selection(); |
388 | - $types = array_keys($frm_field_selection); |
|
389 | - if ( ! in_array($type, $types) && $type != 'captcha' ) { |
|
388 | + $types = array_keys( $frm_field_selection ); |
|
389 | + if ( ! in_array( $type, $types ) && $type != 'captcha' ) { |
|
390 | 390 | $type = 'text'; |
391 | 391 | } |
392 | 392 | |
@@ -425,19 +425,19 @@ discard block |
||
425 | 425 | |
426 | 426 | public static function input_html( $field, $echo = true ) { |
427 | 427 | $class = array(); //$field['type']; |
428 | - self::add_input_classes($field, $class); |
|
428 | + self::add_input_classes( $field, $class ); |
|
429 | 429 | |
430 | 430 | $add_html = array(); |
431 | - self::add_html_size($field, $add_html); |
|
432 | - self::add_html_length($field, $add_html); |
|
433 | - self::add_html_placeholder($field, $add_html, $class); |
|
431 | + self::add_html_size( $field, $add_html ); |
|
432 | + self::add_html_length( $field, $add_html ); |
|
433 | + self::add_html_placeholder( $field, $add_html, $class ); |
|
434 | 434 | self::add_validation_messages( $field, $add_html ); |
435 | 435 | |
436 | - $class = apply_filters('frm_field_classes', implode(' ', $class), $field); |
|
436 | + $class = apply_filters( 'frm_field_classes', implode( ' ', $class ), $field ); |
|
437 | 437 | |
438 | 438 | FrmFormsHelper::add_html_attr( $class, 'class', $add_html ); |
439 | 439 | |
440 | - self::add_shortcodes_to_html($field, $add_html); |
|
440 | + self::add_shortcodes_to_html( $field, $add_html ); |
|
441 | 441 | |
442 | 442 | $add_html = apply_filters( 'frm_field_extra_html', $add_html, $field ); |
443 | 443 | $add_html = ' ' . implode( ' ', $add_html ) . ' '; |
@@ -450,7 +450,7 @@ discard block |
||
450 | 450 | } |
451 | 451 | |
452 | 452 | private static function add_input_classes( $field, array &$class ) { |
453 | - if ( isset($field['input_class']) && ! empty($field['input_class']) ) { |
|
453 | + if ( isset( $field['input_class'] ) && ! empty( $field['input_class'] ) ) { |
|
454 | 454 | $class[] = $field['input_class']; |
455 | 455 | } |
456 | 456 | |
@@ -458,7 +458,7 @@ discard block |
||
458 | 458 | return; |
459 | 459 | } |
460 | 460 | |
461 | - if ( isset($field['size']) && $field['size'] > 0 ) { |
|
461 | + if ( isset( $field['size'] ) && $field['size'] > 0 ) { |
|
462 | 462 | $class[] = 'auto_width'; |
463 | 463 | } |
464 | 464 | } |
@@ -468,19 +468,19 @@ discard block |
||
468 | 468 | return; |
469 | 469 | } |
470 | 470 | |
471 | - if ( FrmAppHelper::is_admin_page('formidable' ) ) { |
|
471 | + if ( FrmAppHelper::is_admin_page( 'formidable' ) ) { |
|
472 | 472 | return; |
473 | 473 | } |
474 | 474 | |
475 | - if ( is_numeric($field['size']) ) { |
|
475 | + if ( is_numeric( $field['size'] ) ) { |
|
476 | 476 | $field['size'] .= 'px'; |
477 | 477 | } |
478 | 478 | |
479 | - $important = apply_filters('frm_use_important_width', 1, $field); |
|
479 | + $important = apply_filters( 'frm_use_important_width', 1, $field ); |
|
480 | 480 | // Note: This inline styling must stay since we cannot realistically set a class for every possible field size |
481 | 481 | $add_html['style'] = 'style="width:' . esc_attr( $field['size'] ) . ( $important ? ' !important' : '' ) . '"'; |
482 | 482 | |
483 | - self::add_html_cols($field, $add_html); |
|
483 | + self::add_html_cols( $field, $add_html ); |
|
484 | 484 | } |
485 | 485 | |
486 | 486 | private static function add_html_cols( $field, array &$add_html ) { |
@@ -497,13 +497,13 @@ discard block |
||
497 | 497 | ); |
498 | 498 | |
499 | 499 | // include "col" for valid html |
500 | - $unit = trim(preg_replace('/[0-9]+/', '', $field['size'])); |
|
500 | + $unit = trim( preg_replace( '/[0-9]+/', '', $field['size'] ) ); |
|
501 | 501 | |
502 | - if ( ! isset( $calc[ $unit ] ) ) { |
|
502 | + if ( ! isset( $calc[$unit] ) ) { |
|
503 | 503 | return; |
504 | 504 | } |
505 | 505 | |
506 | - $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[ $unit ]; |
|
506 | + $size = (float) str_replace( $unit, '', $field['size'] ) / $calc[$unit]; |
|
507 | 507 | |
508 | 508 | $add_html['cols'] = 'cols="' . absint( $size ) . '"'; |
509 | 509 | } |
@@ -514,7 +514,7 @@ discard block |
||
514 | 514 | return; |
515 | 515 | } |
516 | 516 | |
517 | - if ( FrmAppHelper::is_admin_page('formidable' ) ) { |
|
517 | + if ( FrmAppHelper::is_admin_page( 'formidable' ) ) { |
|
518 | 518 | // don't load on form builder page |
519 | 519 | return; |
520 | 520 | } |
@@ -546,7 +546,7 @@ discard block |
||
546 | 546 | if ( $frm_settings->use_html && ! in_array( $field['type'], array( 'select', 'radio', 'checkbox', 'hidden' ) ) ) { |
547 | 547 | // use HMTL5 placeholder with js fallback |
548 | 548 | $add_html['placeholder'] = 'placeholder="' . esc_attr( $field['default_value'] ) . '"'; |
549 | - wp_enqueue_script('jquery-placeholder'); |
|
549 | + wp_enqueue_script( 'jquery-placeholder' ); |
|
550 | 550 | } else if ( ! $frm_settings->use_html ) { |
551 | 551 | $val = str_replace( array( "\r\n", "\n" ), '\r', addslashes( str_replace( ''', "'", esc_attr( $field['default_value'] ) ) ) ); |
552 | 552 | $add_html['data-frmval'] = 'data-frmval="' . esc_attr( $val ) . '"'; |
@@ -580,15 +580,15 @@ discard block |
||
580 | 580 | continue; |
581 | 581 | } |
582 | 582 | |
583 | - if ( is_numeric($k) && strpos($v, '=') ) { |
|
583 | + if ( is_numeric( $k ) && strpos( $v, '=' ) ) { |
|
584 | 584 | $add_html[] = $v; |
585 | - } else if ( ! empty( $k ) && isset( $add_html[ $k ] ) ) { |
|
586 | - $add_html[ $k ] = str_replace( $k . '="', $k . '="' . $v, $add_html[ $k ] ); |
|
585 | + } else if ( ! empty( $k ) && isset( $add_html[$k] ) ) { |
|
586 | + $add_html[$k] = str_replace( $k . '="', $k . '="' . $v, $add_html[$k] ); |
|
587 | 587 | } else { |
588 | - $add_html[ $k ] = $k . '="' . esc_attr( $v ) . '"'; |
|
588 | + $add_html[$k] = $k . '="' . esc_attr( $v ) . '"'; |
|
589 | 589 | } |
590 | 590 | |
591 | - unset($k, $v); |
|
591 | + unset( $k, $v ); |
|
592 | 592 | } |
593 | 593 | } |
594 | 594 | |
@@ -604,8 +604,8 @@ discard block |
||
604 | 604 | } |
605 | 605 | |
606 | 606 | public static function check_label( $opt ) { |
607 | - if ( is_array($opt) ) { |
|
608 | - $opt = (isset($opt['label']) ? $opt['label'] : reset($opt)); |
|
607 | + if ( is_array( $opt ) ) { |
|
608 | + $opt = ( isset( $opt['label'] ) ? $opt['label'] : reset( $opt ) ); |
|
609 | 609 | } |
610 | 610 | |
611 | 611 | return $opt; |