PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 5.5.2
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v5.5.2
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/controllers/FrmStylesController.php +150 -1015 6.275.5.2 View file →
@@ -3,27 +3,11 @@
3 3 die( 'You are not allowed to call this page directly.' );
4 4 }
5 5
6 6 class FrmStylesController {
7 -
8 - /**
9 - * @var string
10 - */
11 7 public static $post_type = 'frm_styles';
12 -
13 - /**
14 - * @var string
15 - */
16 8 public static $screen = 'formidable_page_formidable-styles';
17 9
18 - /**
19 - * @var string|null
20 - */
21 - private static $message;
22 -
23 - /**
24 - * @return void
25 - */
26 10 public static function load_pro_hooks() {
27 11 if ( FrmAppHelper::pro_is_installed() ) {
28 12 FrmProStylesController::load_pro_hooks();
29 13 }
@@ -28,11 +12,8 @@
28 12 FrmProStylesController::load_pro_hooks();
29 13 }
30 14 }
31 15
32 - /**
33 - * @return void
34 - */
35 16 public static function register_post_types() {
36 17 register_post_type(
37 18 self::$post_type,
38 19 array(
@@ -64,119 +45,45 @@
64 45 )
65 46 );
66 47 }
67 48
68 - /**
69 - * Add two links for the visual styler.
70 - * There's a "Styles" submenu in the Formidable menu.
71 - * There's a second alternative "Forms" submenu in the Appearance menu.
72 - * This submenu links to a page to edit a form with the default style.
73 - *
74 - * @return void
75 - */
76 49 public static function menu() {
77 - add_submenu_page( 'formidable', 'Formidable | ' . __( 'Styles', 'formidable' ), __( 'Styles', 'formidable' ), 'frm_change_settings', 'formidable-styles', 'FrmStylesController::route' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
78 - add_submenu_page( 'themes.php', 'Formidable | ' . __( 'Styles', 'formidable' ), __( 'Forms', 'formidable' ), 'frm_change_settings', 'formidable-styles2', 'FrmStylesController::route' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
50 + add_submenu_page( 'formidable', 'Formidable | ' . __( 'Styles', 'formidable' ), __( 'Styles', 'formidable' ), 'frm_change_settings', 'formidable-styles', 'FrmStylesController::route' );
51 + add_submenu_page( 'themes.php', 'Formidable | ' . __( 'Styles', 'formidable' ), __( 'Forms', 'formidable' ), 'frm_change_settings', 'formidable-styles2', 'FrmStylesController::route' );
79 52 }
80 53
81 - /**
82 - * Remove filters for the visual styler preview.
83 - * This triggers earlier than self::admin_init which is called too late.
84 - *
85 - * @return void
86 - */
87 - public static function plugins_loaded() {
88 - if ( ! FrmAppHelper::is_style_editor_page() ) {
54 + public static function admin_init() {
55 + if ( ! FrmAppHelper::is_admin_page( 'formidable-styles' ) && ! FrmAppHelper::is_admin_page( 'formidable-styles2' ) ) {
89 56 return;
90 57 }
91 58
92 - self::disable_form_css();
93 - self::prevent_form_scripts_from_loading();
94 - }
59 + self::load_pro_hooks();
95 60
96 - /**
97 - * Avoid loading CSS the normal way with the preview in the styler.
98 - * It gets loaded instead with the frmpro_css action set to the #frm-custom-theme-css element.
99 - *
100 - * @since 6.0
101 - *
102 - * @return void
103 - */
104 - private static function disable_form_css() {
105 - add_filter( 'get_frm_stylesheet', '__return_empty_array' );
106 - }
107 -
108 - /**
109 - * Removing this action prevents front end JavaScript from loading.
110 - *
111 - * @since 6.0
112 - *
113 - * @return void
114 - */
115 - private static function prevent_form_scripts_from_loading() {
116 - remove_action( 'init', 'FrmFormsController::front_head' );
117 - }
118 -
119 - /**
120 - * @return void
121 - */
122 - public static function admin_init() {
123 - self::maybe_hook_into_global_settings_save();
124 -
125 - if ( ! FrmAppHelper::is_style_editor_page() ) {
61 + $style_tab = FrmAppHelper::get_param( 'frm_action', '', 'get', 'sanitize_title' );
62 + if ( $style_tab === 'manage' || $style_tab === 'custom_css' ) {
63 + // we only need to load these styles/scripts on the styler page
126 64 return;
127 65 }
128 66
129 - FrmStyleComponent::register_assets();
130 - self::load_pro_hooks();
131 -
132 67 $version = FrmAppHelper::plugin_version();
133 -
134 - if ( FrmAppHelper::is_style_editor_page( 'edit' ) ) {
135 - wp_enqueue_style( 'wp-color-picker' );
136 - }
137 -
68 + wp_enqueue_script( 'jquery-ui-datepicker' );
69 + wp_enqueue_style( 'wp-color-picker' );
138 70 wp_enqueue_style( 'frm-custom-theme', admin_url( 'admin-ajax.php?action=frmpro_css' ), array(), $version );
139 71
140 72 $style = apply_filters( 'frm_style_head', false );
141 -
142 73 if ( $style ) {
143 - wp_enqueue_style( 'frm-single-custom-theme', admin_url( 'admin-ajax.php?action=frmpro_load_css&flat=1' ) . '&' . http_build_query( $style->post_content ), array(), $version ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
74 + wp_enqueue_style( 'frm-single-custom-theme', admin_url( 'admin-ajax.php?action=frmpro_load_css&flat=1' ) . '&' . http_build_query( $style->post_content ), array(), $version );
144 75 }
145 76 }
146 77
147 78 /**
148 - * @since 6.0
149 - *
150 - * @return void
151 - */
152 - private static function maybe_hook_into_global_settings_save() {
153 - if ( empty( $_POST ) || ! isset( $_POST['style'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
154 - // Avoid changing any style data if the style array is not sent in the request.
155 - return;
156 - }
157 -
158 - add_action(
159 - 'frm_update_settings',
160 - /**
161 - * Update the form data on the "Manage Styles" tab after global settings are saved.
162 - */
163 - function () {
164 - self::manage_styles();
165 - }
166 - );
167 - }
168 -
169 - /**
170 79 * @param string $register Either 'enqueue' or 'register'.
171 80 * @param bool $force True to enqueue/register the style if a form has not been loaded.
172 - *
173 - * @return void
174 81 */
175 82 public static function enqueue_css( $register = 'enqueue', $force = false ) {
176 83 global $frm_vars;
177 84
178 - $register_css = $register === 'register';
85 + $register_css = ( $register == 'register' );
179 86 $should_load = $force || ( ( $frm_vars['load_css'] || $register_css ) && ! FrmAppHelper::is_admin() );
180 87
181 88 if ( ! $should_load ) {
182 89 return;
@@ -182,17 +89,17 @@
182 89 return;
183 90 }
184 91
185 92 $frm_settings = FrmAppHelper::get_settings();
186 -
187 - if ( $frm_settings->load_style === 'none' ) {
93 + if ( $frm_settings->load_style == 'none' ) {
188 94 return;
189 95 }
190 96
191 97 $css = apply_filters( 'get_frm_stylesheet', self::custom_stylesheet() );
192 98
193 - if ( $css ) {
194 - $css = (array) $css;
99 + if ( ! empty( $css ) ) {
100 + $css = (array) $css;
101 +
195 102 $version = FrmAppHelper::plugin_version();
196 103
197 104 foreach ( $css as $css_key => $file ) {
198 105 if ( $register_css ) {
@@ -199,34 +106,30 @@
199 106 $this_version = self::get_css_version( $css_key, $version );
200 107 wp_register_style( $css_key, $file, array(), $this_version );
201 108 }
202 109
203 - $load_on_all = ! FrmAppHelper::is_admin() && 'all' === $frm_settings->load_style;
204 -
205 - if ( $load_on_all || $register !== 'register' ) {
110 + $load_on_all = ! FrmAppHelper::is_admin() && 'all' == $frm_settings->load_style;
111 + if ( $load_on_all || $register != 'register' ) {
206 112 wp_enqueue_style( $css_key );
207 113 }
208 114 unset( $css_key, $file );
209 115 }
210 116
211 - if ( $frm_settings->load_style === 'all' ) {
117 + if ( $frm_settings->load_style == 'all' ) {
212 118 $frm_vars['css_loaded'] = true;
213 119 }
214 - }//end if
120 + }
215 121 unset( $css );
216 122
217 123 add_filter( 'style_loader_tag', 'FrmStylesController::add_tags_to_css', 10, 2 );
218 124 }
219 125
220 - /**
221 - * @return array<string,string>
222 - */
223 126 public static function custom_stylesheet() {
224 127 global $frm_vars;
225 128 $stylesheet_urls = array();
226 129
227 - if ( empty( $frm_vars['css_loaded'] ) ) {
228 - // Include css in head.
130 + if ( ! isset( $frm_vars['css_loaded'] ) || ! $frm_vars['css_loaded'] ) {
131 + //include css in head
229 132 self::get_url_to_custom_style( $stylesheet_urls );
230 133 }
231 134
232 135 return $stylesheet_urls;
@@ -231,22 +134,15 @@
231 134
232 135 return $stylesheet_urls;
233 136 }
234 137
235 - /**
236 - * @param array $stylesheet_urls
237 - *
238 - * @return void
239 - */
240 138 private static function get_url_to_custom_style( &$stylesheet_urls ) {
241 139 $file_name = '/css/' . self::get_file_name();
242 -
243 140 if ( is_readable( FrmAppHelper::plugin_path() . $file_name ) ) {
244 141 $url = FrmAppHelper::plugin_url() . $file_name;
245 142 } else {
246 143 $url = admin_url( 'admin-ajax.php?action=frmpro_css' );
247 144 }
248 -
249 145 $stylesheet_urls['formidable'] = $url;
250 146 }
251 147
252 148 /**
@@ -252,30 +148,23 @@
252 148 /**
253 149 * Use a different stylesheet per site in a multisite install
254 150 *
255 151 * @since 3.0.03
256 - *
257 - * @return string
258 152 */
259 153 public static function get_file_name() {
260 154 if ( is_multisite() ) {
261 155 $blog_id = get_current_blog_id();
262 - return 'formidableforms' . absint( $blog_id ) . '.css';
156 + $name = 'formidableforms' . absint( $blog_id ) . '.css';
157 + } else {
158 + $name = 'formidableforms.css';
263 159 }
264 160
265 - return 'formidableforms.css';
161 + return $name;
266 162 }
267 163
268 - /**
269 - * @param string $css_key
270 - * @param string $version
271 - *
272 - * @return string
273 - */
274 164 private static function get_css_version( $css_key, $version ) {
275 - if ( 'formidable' === $css_key ) {
165 + if ( 'formidable' == $css_key ) {
276 166 $this_version = get_option( 'frm_last_style_update' );
277 -
278 167 if ( ! $this_version ) {
279 168 $this_version = $version;
280 169 }
281 170 } else {
@@ -284,667 +173,177 @@
284 173
285 174 return $this_version;
286 175 }
287 176
288 - /**
289 - * @param string $tag
290 - * @param string $handle
291 - *
292 - * @return string
293 - */
294 177 public static function add_tags_to_css( $tag, $handle ) {
295 - if ( ( 'formidable' === $handle || 'jquery-theme' === $handle ) && ! str_contains( $tag, ' property=' ) ) {
296 - $tag = str_replace( ' type="', ' property="stylesheet" type="', $tag );
178 + if ( ( 'formidable' == $handle || 'jquery-theme' == $handle ) && strpos( $tag, ' property=' ) === false ) {
179 + $frm_settings = FrmAppHelper::get_settings();
180 + if ( $frm_settings->use_html ) {
181 + $tag = str_replace( ' type="', ' property="stylesheet" type="', $tag );
182 + }
297 183 }
298 184
299 185 return $tag;
300 186 }
301 187
302 - /**
303 - * Route the edit route to the style function.
304 - *
305 - * @since 6.0 this function no longer has any parameter values.
306 - *
307 - * @return void
308 - */
309 - public static function edit() {
310 - self::load_styler();
188 + public static function new_style( $return = '' ) {
189 + self::load_styler( 'default' );
311 190 }
312 191
313 - /**
314 - * When a new style route is hit, show a new style with the defaults. There is no ID yet, it is created after the first save event.
315 - *
316 - * @return void
317 - */
318 - public static function new_style() {
319 - self::load_styler();
320 - }
321 -
322 - /**
323 - * When the duplicate route is hit, it just shows the visual styler with a copy of the target style. There is no ID yet, it is created after the first save event.
324 - *
325 - * @return void
326 - */
327 192 public static function duplicate() {
328 - self::load_styler();
193 + self::load_styler( 'default' );
329 194 }
330 195
331 - /**
332 - * Render the style page for a form for assigning a style to a form, and for updating a target style.
333 - *
334 - * @since 6.0 this function no longer takes parameters.
335 - *
336 - * @return void
337 - */
338 - public static function load_styler() {
339 - if ( 'assign_style' === FrmAppHelper::get_post_param( 'frm_action' ) ) {
340 - self::save_form_style();
341 - }
342 -
343 - self::setup_styles_and_scripts_for_styler();
344 -
345 - $style_id = self::get_style_id_for_styler();
346 -
196 + public static function edit( $style_id = false, $message = '' ) {
347 197 if ( ! $style_id ) {
348 - $error_args = array(
349 - 'title' => __( 'No styles', 'formidable' ),
350 - 'body' => __( 'You must have a style to use the Visual Styler.', 'formidable' ),
351 - 'cancel_url' => admin_url( 'admin.php?page=formidable' ),
352 - );
353 - FrmAppController::show_error_modal( $error_args );
354 - return;
355 - }
356 -
357 - $form_id = FrmAppHelper::simple_get( 'form', 'absint', 0 );
358 -
359 - if ( ! $form_id ) {
360 - $form_id = self::get_form_id_for_style( $style_id );
361 - }
362 -
363 - $form = FrmForm::getOne( $form_id );
364 -
365 - if ( ! is_object( $form ) ) {
366 - $error_args = array(
367 - 'title' => __( 'No forms', 'formidable' ),
368 - 'body' => __( 'You must have a form to use the Visual Styler.', 'formidable' ),
369 - 'cancel_url' => admin_url( 'admin.php?page=formidable' ),
370 - );
371 - FrmAppController::show_error_modal( $error_args );
372 - return;
373 - }
374 -
375 - $frm_style = new FrmStyle( $style_id );
376 - $active_style = $frm_style->get_one();
377 - $default_style = self::get_default_style();
378 -
379 - self::disable_admin_page_styling_on_submit_buttons();
380 -
381 - /**
382 - * @since 6.0
383 - *
384 - * @param array{form:\stdClass} $data
385 - */
386 - do_action( 'frm_before_render_style_page', compact( 'form' ) );
387 -
388 - self::render_style_page( $active_style, $form, $default_style );
389 - }
390 -
391 - /**
392 - * @since 6.0
393 - *
394 - * @return int
395 - */
396 - private static function get_style_id_for_styler() {
397 - $action = FrmAppHelper::simple_get( 'frm_action' );
398 -
399 - if ( 'duplicate' === $action ) {
400 - // The duplicate action uses style_id instead of id for better backward compatibility.
401 - return FrmAppHelper::simple_get( 'style_id', 'absint', 0 );
402 - }
403 -
404 - $style_id = FrmAppHelper::simple_get( 'id', 'absint', 0 );
405 -
406 - if ( $style_id ) {
407 - // Always use the style ID from the URL if one is specified.
408 - return $style_id;
409 - }
410 -
411 - $request_form_id = FrmAppHelper::simple_get( 'form', 'absint', 0 );
412 -
413 - if ( $request_form_id && is_callable( 'FrmProStylesController::get_active_style_for_form' ) ) {
414 - return FrmProStylesController::get_active_style_for_form( $request_form_id )->ID;
415 - }
416 -
417 - return self::get_default_style()->ID;
418 - }
419 -
420 - /**
421 - * If a form ID is not being passed in the URL, try to get the best match.
422 - *
423 - * @since 6.0
424 - *
425 - * @param int $style_id
426 - *
427 - * @return int
428 - */
429 - private static function get_form_id_for_style( $style_id ) {
430 - $check = serialize( array( 'custom_style' => (string) $style_id ) );
431 - $check = substr( $check, 5, -1 );
432 - $form_id = FrmDb::get_var(
433 - 'frm_forms',
434 - array(
435 - 'options LIKE' => $check,
436 - 'status' => 'published',
437 - )
438 - );
439 -
440 - if ( ! $form_id ) {
441 - // Fallback to any form.
442 - $where = array(
443 - 'status' => 'published',
444 - // Make sure it's not a repeater.
445 - 'parent_form_id' => array( null, 0 ),
446 - );
447 - $form_id = FrmDb::get_var( 'frm_forms', $where, 'id' );
448 - }
449 -
450 - return $form_id;
451 - }
452 -
453 - /**
454 - * Add a frm_no_style_button class to all buttons to avoid some style rules like border-radius: 30px.
455 - *
456 - * @return void
457 - */
458 - private static function disable_admin_page_styling_on_submit_buttons() {
459 - add_filter(
460 - 'frm_submit_button_class',
461 - function ( $classes ) {
462 - $classes[] = 'frm_no_style_button';
463 - return $classes;
198 + $style_id = FrmAppHelper::get_param( 'id', '', 'get', 'absint' );
199 + if ( empty( $style_id ) ) {
200 + $style_id = 'default';
464 201 }
465 - );
466 - }
467 -
468 - /**
469 - * @since 6.0
470 - *
471 - * @return WP_Post
472 - */
473 - private static function get_default_style() {
474 - $frm_style = new FrmStyle( 'default' );
475 - return $frm_style->get_one();
476 - }
477 -
478 - /**
479 - * Save style for form (from Styler list page) via a POST action.
480 - *
481 - * @since 6.0
482 - *
483 - * @return void
484 - */
485 - private static function save_form_style() {
486 - $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'frm_save_form_style', 'frm_save_form_style_nonce' );
487 -
488 - if ( $permission_error !== false ) {
489 - wp_die( 'Unable to save form', '', 403 );
490 202 }
491 203
492 - $style_id = FrmAppHelper::get_post_param( 'style_id', 0, 'absint' );
493 -
494 - if ( $style_id && ! self::confirm_style_exists_before_setting( $style_id ) ) {
495 - wp_die( esc_html__( 'Invalid target style', 'formidable' ), esc_html__( 'Invalid target style', 'formidable' ), 400 );
496 - return;
204 + if ( 'default' == $style_id ) {
205 + $style = 'default';
206 + } else {
207 + $frm_style = new FrmStyle( $style_id );
208 + $style = $frm_style->get_one();
209 + $style = $style->ID;
497 210 }
498 211
499 - /**
500 - * Hook into the saved style ID so Pro can import a style template by its key and return a new style ID.
501 - *
502 - * @since 6.0
503 - *
504 - * @param int $style_id
505 - */
506 - $style_id = apply_filters( 'frm_saved_form_style_id', $style_id );
507 -
508 - if ( ! $style_id && '0' !== FrmAppHelper::get_post_param( 'style_id', '', 'sanitize_text_field' ) ) {
509 - // "0" is a special value used for the enable/disable toggle.
510 - wp_die( esc_html__( 'Invalid style value', 'formidable' ), esc_html__( 'Invalid style value', 'formidable' ), 400 );
511 - return;
512 - }
513 -
514 - $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
515 -
516 - if ( ! $form_id ) {
517 - wp_die( esc_html__( 'No form specified', 'formidable' ), esc_html__( 'No form specified', 'formidable' ), 400 );
518 - return;
519 - }
520 -
521 - $form = FrmForm::getOne( $form_id );
522 -
523 - if ( ! $form ) {
524 - wp_die( esc_html__( 'Form does not exist', 'formidable' ), esc_html__( 'Form does not exist', 'formidable' ), 400 );
525 - return;
526 - }
527 -
528 - $previous_style_id = $form->options['custom_style'];
529 -
530 - // If the default style is selected, use the "Always use default" legacy option instead of the default style.
531 - // There's also a check here for conversational forms.
532 - // Without the check it isn't possible to select "Default" because "Always use default" will convert to "Lines" dynamically.
533 - $default_style = self::get_default_style();
534 -
535 - if ( $style_id === $default_style->ID && empty( $form->options['chat'] ) ) {
536 - $style_id = 1;
537 - }
538 -
539 - // We want to save a string for consistency. FrmStylesHelper::get_form_count_for_style expects the custom style ID is a string.
540 - $form->options['custom_style'] = (string) $style_id;
541 -
542 - if ( $previous_style_id === $form->options['custom_style'] ) {
543 - // Exit early before updating DB if nothing actually changed.
544 - self::$message = __( 'Successfully updated style.', 'formidable' );
545 - return;
546 - }
547 -
548 - global $wpdb;
549 - $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $form->options ) ), array( 'id' => $form->id ) );
550 -
551 - FrmForm::clear_form_cache();
552 -
553 - /**
554 - * @since 6.25.1
555 - *
556 - * @param int $form_id
557 - * @param int $style_id
558 - */
559 - do_action( 'frm_after_changed_form_style', absint( $form_id ), absint( $style_id ) );
560 -
561 - self::$message = __( 'Successfully updated style.', 'formidable' );
212 + self::load_styler( $style, $message );
562 213 }
563 214
564 - /**
565 - * Validate that we're assigning a form to a style that actually exists before assigning it to a form.
566 - *
567 - * @param int $style_id
568 - *
569 - * @return bool True if the style actually exists.
570 - */
571 - private static function confirm_style_exists_before_setting( $style_id ) {
572 - global $wpdb;
573 - $post_type = FrmDb::get_var( $wpdb->posts, array( 'ID' => $style_id ), 'post_type' );
574 - return self::$post_type === $post_type;
575 - }
576 -
577 - /**
578 - * Register and enqueue styles and scripts for the style tab page.
579 - *
580 - * @since 6.0
581 - *
582 - * @return void
583 - */
584 - private static function setup_styles_and_scripts_for_styler() {
585 - $plugin_url = FrmAppHelper::plugin_url();
586 - $version = FrmAppHelper::plugin_version();
587 - $js_dependencies = array( 'wp-i18n', 'wp-hooks', 'formidable_dom' );
588 -
589 - if ( FrmAppHelper::pro_is_installed() && is_callable( 'FrmProAppHelper::use_jquery_datepicker' ) && FrmProAppHelper::use_jquery_datepicker() ) {
590 - $js_dependencies[] = 'jquery-ui-datepicker';
591 - }
592 -
593 - wp_register_script( 'formidable_style', $plugin_url . '/js/admin/style.js', $js_dependencies, $version );
594 - wp_register_style( 'formidable_style', $plugin_url . '/css/admin/style.css', array(), $version );
595 - wp_print_styles( 'formidable_style' );
596 -
597 - wp_print_styles( 'formidable' );
598 - wp_enqueue_script( 'formidable_style' );
599 - wp_set_script_translations( 'formidable_style', 'formidable' );
600 - }
601 -
602 - /**
603 - * Render the style page (with a more limited and typed scope than calling it from self::style directly).
604 - *
605 - * @since 6.0
606 - *
607 - * @param stdClass|WP_Post $active_style
608 - * @param stdClass $form
609 - * @param WP_Post $default_style
610 - *
611 - * @return void
612 - */
613 - private static function render_style_page( $active_style, $form, $default_style ) {
614 - $style_views_path = self::get_views_path();
615 - // Edit, list (default), new_style.
616 - $view = FrmAppHelper::simple_get( 'frm_action', 'sanitize_text_field', 'list' );
617 - $frm_style = new FrmStyle( $active_style->ID );
618 -
619 - if ( 'new_style' !== $view && ! FrmAppHelper::simple_get( 'form' ) && ! FrmAppHelper::simple_get( 'style_id' ) ) {
620 - // Have the Appearance > Forms link fallback to the edit view. Otherwise we want to use 'list' as the default.
621 - $view = 'edit';
622 - }
623 -
624 - if ( in_array( $view, array( 'edit', 'new_style', 'duplicate' ), true ) ) {
625 - self::add_meta_boxes();
626 - }
627 -
628 - switch ( $view ) {
629 - case 'edit':
630 - $style = $active_style;
631 - break;
632 -
633 - case 'duplicate':
634 - $style = clone $active_style;
635 - $new_style = $frm_style->get_new();
636 - $style->ID = $new_style->ID;
637 - $style->post_name = $new_style->post_name;
638 - unset( $new_style );
639 - break;
640 -
641 - case 'new_style':
642 - $style = $frm_style->get_new();
643 - break;
644 - }
645 -
646 - if ( in_array( $view, array( 'duplicate', 'new_style' ), true ) ) {
647 - $style->post_title = FrmAppHelper::simple_get( 'style_name' );
648 - $style->menu_order = 0;
649 - }
650 -
651 - if ( ! isset( $style ) ) {
652 - $style = $active_style;
653 - }
654 -
655 - self::force_form_style( $style );
656 -
657 - if ( isset( self::$message ) ) {
658 - $message = self::$message;
659 - }
660 -
661 - $preview_helper = new FrmStylesPreviewHelper( $form->id );
662 - $preview_helper->adjust_form_for_preview();
663 -
664 - // Get form HTML before displaying warnings and notes so we can check global $frm_vars data without adding extra database calls.
665 - $target_form_preview_html = $preview_helper->get_html_for_form_preview();
666 - $warnings = $preview_helper->get_warnings_for_styler_preview( $style, $default_style, $view );
667 - $notes = $preview_helper->get_notes_for_styler_preview();
668 -
669 - include $style_views_path . 'show.php';
670 - }
671 -
672 - /**
673 - * @since 6.0
674 - *
675 - * @return string
676 - */
677 - private static function get_views_path() {
678 - return FrmAppHelper::plugin_path() . '/classes/views/styles/';
679 - }
680 -
681 - /**
682 - * Filter form classes so the form uses the preview style, not the form's active style.
683 - *
684 - * @since 6.0
685 - *
686 - * @param stdClass|WP_Post $style A new style is not a WP_Post object.
687 - *
688 - * @return void
689 - */
690 - private static function force_form_style( $style ) {
691 - add_filter(
692 - 'frm_add_form_style_class',
693 - function ( $class ) use ( $style ) {
694 - $split = array_filter(
695 - explode( ' ', $class ),
696 - /**
697 - * @param string $class
698 - */
699 - function ( $class ) {
700 - return $class && ! str_starts_with( $class, 'frm_style_' );
701 - }
702 - );
703 - $split[] = 'frm_style_' . $style->post_name;
704 - return implode( ' ', $split );
705 - }
706 - );
707 - }
708 -
709 - /**
710 - * Save style post object via a POST request submitted from the Visual styler "edit" page.
711 - *
712 - * @since 6.0
713 - *
714 - * @return void
715 - */
716 - public static function save_style() {
215 + public static function save() {
717 216 $frm_style = new FrmStyle();
217 + $message = '';
718 218 $post_id = FrmAppHelper::get_post_param( 'ID', false, 'sanitize_title' );
719 219 $style_nonce = FrmAppHelper::get_post_param( 'frm_style', '', 'sanitize_text_field' );
720 220
721 - if ( $post_id === false || ! wp_verify_nonce( $style_nonce, 'frm_style_nonce' ) ) {
722 - // Exit early if the request isn't valid.
723 - // Since we're not dying, it should just reload the visual styler without any message.
724 - return;
221 + if ( $post_id !== false && wp_verify_nonce( $style_nonce, 'frm_style_nonce' ) ) {
222 + $id = $frm_style->update( $post_id );
223 + if ( empty( $post_id ) && ! empty( $id ) ) {
224 + // set the post id to the new style so it will be loaded for editing
225 + $post_id = reset( $id );
226 + }
227 + // include the CSS that includes this style
228 + echo '<link href="' . esc_url( admin_url( 'admin-ajax.php?action=frmpro_css' ) ) . '" type="text/css" rel="Stylesheet" class="frm-custom-theme" />';
229 + $message = __( 'Your styling settings have been saved.', 'formidable' );
725 230 }
726 231
727 - $id = $frm_style->update( $post_id );
728 -
729 - if ( ! $post_id && $id ) {
730 - self::maybe_redirect_after_save( $id );
731 - // Set the post id to the new style so it will be loaded for editing.
732 - $post_id = reset( $id );
733 - }
734 -
735 - /**
736 - * @since 6.25.1
737 - *
738 - * @param int $post_id
739 - */
740 - do_action( 'frm_after_saved_style', absint( $post_id ) );
741 -
742 - self::$message = __( 'Your styling settings have been saved.', 'formidable' );
232 + return self::edit( $post_id, $message );
743 233 }
744 234
745 - /**
746 - * Show the edit view after saving.
747 - * The save event is triggered earlier, on admin init where self::save_style is called.
748 - * This happens earlier because there is a possible redirect (to adjust the URL for a new or duplicated style).
749 - *
750 - * @return void
751 - */
752 - public static function save() {
753 - self::edit();
754 - }
235 + public static function load_styler( $style, $message = '' ) {
236 + global $frm_settings;
755 237
756 - /**
757 - * Force a redirect after duplicating or creating a new style to avoid an old stale URL that could result in more styles than intended.
758 - *
759 - * @since 6.0
760 - *
761 - * @param array $ids
762 - *
763 - * @return void
764 - */
765 - private static function maybe_redirect_after_save( $ids ) {
766 - $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' );
767 - $parsed = parse_url( $referer );
768 - $query = $parsed['query'];
769 - $current_action = false;
770 - $actions_to_redirect = array( 'duplicate', 'new_style' );
238 + $frm_style = new FrmStyle();
239 + $styles = $frm_style->get_all();
771 240
772 - foreach ( $actions_to_redirect as $action ) {
773 - if ( str_contains( $query, 'frm_action=' . $action ) ) {
774 - $current_action = $action;
775 - break;
776 - }
241 + if ( is_numeric( $style ) ) {
242 + $style = $styles[ $style ];
243 + } elseif ( 'default' == $style ) {
244 + $style = $frm_style->get_default_style( $styles );
777 245 }
778 246
779 - if ( false === $current_action ) {
780 - // Do not redirect as the referer URL did not match $actions_to_redirect.
781 - return;
782 - }
247 + self::add_meta_boxes();
783 248
784 - parse_str( $query, $parsed_query );
785 - $form_id = ! empty( $parsed_query['form'] ) ? absint( $parsed_query['form'] ) : 0;
786 - $style = new stdClass();
787 - $style->ID = end( $ids );
788 - wp_safe_redirect( esc_url_raw( FrmStylesHelper::get_edit_url( $style, $form_id ) ) );
789 - die();
249 + include( FrmAppHelper::plugin_path() . '/classes/views/styles/show.php' );
790 250 }
791 251
792 252 /**
793 - * @since 6.0
794 - *
795 - * @param string $message
253 + * @param string $message
796 254 * @param array|object $forms
797 - *
798 - * @return void
799 255 */
800 - public static function manage( $message = '', $forms = array() ) {
256 + private static function manage( $message = '', $forms = array() ) {
801 257 $frm_style = new FrmStyle();
802 258 $styles = $frm_style->get_all();
803 259 $default_style = $frm_style->get_default_style( $styles );
804 - $frm_settings = FrmAppHelper::get_settings();
805 260
806 - if ( ! $forms ) {
261 + if ( empty( $forms ) ) {
807 262 $forms = FrmForm::get_published_forms();
808 263 }
809 264
810 - include FrmAppHelper::plugin_path() . '/classes/views/styles/manage.php';
265 + include( FrmAppHelper::plugin_path() . '/classes/views/styles/manage.php' );
811 266 }
812 267
813 - /**
814 - * Handle saving for the page rendered in self::manage which is included in Global Settings in the "Manage Styles" tab.
815 - * This gets called from the frm_update_settings hook which is called after saving Global settings.
816 - *
817 - * @return void
818 - */
819 268 private static function manage_styles() {
269 + $style_nonce = FrmAppHelper::get_post_param( 'frm_manage_style', '', 'sanitize_text_field' );
270 + // phpcs:ignore WordPress.Security.NonceVerification.Missing
271 + if ( ! $_POST || ! isset( $_POST['style'] ) || ! wp_verify_nonce( $style_nonce, 'frm_manage_style_nonce' ) ) {
272 + return self::manage();
273 + }
274 +
820 275 global $wpdb;
821 276
822 277 $forms = FrmForm::get_published_forms();
823 -
824 278 foreach ( $forms as $form ) {
825 - if ( ! isset( $_POST['style'] ) || ! isset( $_POST['style'][ $form->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
279 + $new_style = ( isset( $_POST['style'] ) && isset( $_POST['style'][ $form->id ] ) ) ? sanitize_text_field( wp_unslash( $_POST['style'][ $form->id ] ) ) : '';
280 + $previous_style = ( isset( $_POST['prev_style'] ) && isset( $_POST['prev_style'][ $form->id ] ) ) ? sanitize_text_field( wp_unslash( $_POST['prev_style'][ $form->id ] ) ) : '';
281 + if ( $new_style == $previous_style ) {
826 282 continue;
827 283 }
828 284
829 - $new_style = sanitize_text_field( wp_unslash( $_POST['style'][ $form->id ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
285 + $form->options['custom_style'] = $new_style;
830 286
831 - $form->options['custom_style'] = $new_style;
832 287 $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $form->options ) ), array( 'id' => $form->id ) );
833 288 unset( $form );
834 289 }
290 +
291 + $message = __( 'Your form styles have been saved.', 'formidable' );
292 +
293 + return self::manage( $message, $forms );
835 294 }
836 295
837 296 /**
838 - * Echo content for the Custom CSS page.
839 - *
840 - * @param string $message
841 - * @param array $extra_args An array of extra arguments.
842 - *
297 + * @param string $message
298 + * @param FrmStyle|null $style
843 299 * @return void
844 300 */
845 - public static function custom_css( $message = '', $extra_args = array() ) {
846 - $id = $extra_args['id'] ?? 'frm_codemirror_box';
847 - $settings = self::enqueue_codemirror( $id, $extra_args['placeholder'] ?? '' );
848 - $id = $settings ? $id : 'frm_custom_css_box';
849 - $show_errors = $extra_args['show_errors'] ?? true;
850 - $custom_css = $extra_args['custom_css'] ?? self::get_custom_css();
851 - $heading = $extra_args['heading'] ?? __( 'You can add custom css here or in your theme style.css. Any CSS added here will be used anywhere the Formidable CSS is loaded.', 'formidable' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
852 - $textarea_params = ! empty( $extra_args['textarea_params'] ) ? $extra_args['textarea_params'] : array(
853 - 'name' => 'frm_custom_css',
854 - 'id' => $id,
855 - );
856 -
857 - if ( $settings ) {
858 - $textarea_params['class'] = 'hide-if-js';
301 + public static function custom_css( $message = '', $style = null ) {
302 + if ( function_exists( 'wp_enqueue_code_editor' ) ) {
303 + $id = 'frm_codemirror_box';
304 + $settings = wp_enqueue_code_editor(
305 + array(
306 + 'type' => 'text/css',
307 + 'codemirror' => array(
308 + 'indentUnit' => 2,
309 + 'tabSize' => 2,
310 + ),
311 + )
312 + );
313 + } else {
314 + $settings = false;
859 315 }
860 316
861 - include FrmAppHelper::plugin_path() . '/classes/views/styles/custom_css.php';
862 - }
863 -
864 - /**
865 - * Get custom CSS code entered in the Custom CSS page.
866 - *
867 - * @since 6.0
868 - *
869 - * @param array|null $single_style_settings The single style settings.
870 - *
871 - * @return string
872 - */
873 - public static function get_custom_css( $single_style_settings = null ) {
874 - if ( $single_style_settings ) {
875 - // If the single style settings are passed, return the custom CSS from the single style settings.
876 - if ( ! empty( $single_style_settings['single_style_custom_css'] ) && ! empty( $single_style_settings['enable_style_custom_css'] ) ) {
877 - return $single_style_settings['single_style_custom_css'];
878 - }
879 -
880 - return '';
317 + if ( empty( $settings ) ) {
318 + $id = 'frm_custom_css_box';
881 319 }
882 320
883 - $settings = FrmAppHelper::get_settings();
884 -
885 - if ( is_string( $settings->custom_css ) ) {
886 - return $settings->custom_css;
321 + if ( ! isset( $style ) ) {
322 + $frm_style = new FrmStyle();
323 + $style = $frm_style->get_default_style();
887 324 }
888 325
889 - // If it does not exist, check the default style as a fallback.
890 - $frm_style = new FrmStyle();
891 - $style = $frm_style->get_default_style();
892 -
893 - return $style->post_content['custom_css'];
326 + include FrmAppHelper::plugin_path() . '/classes/views/styles/custom_css.php';
894 327 }
895 328
896 329 /**
897 - * Enqueue assets for codemirror, built into WordPress since 4.9.
898 - * The Custom CSS page uses codemirror.
899 - *
900 - * @since 6.0 Previously this code was embedded in self::custom_css.
901 - *
902 - * @param string $id The ID of the codemirror box.
903 - * @param string $placeholder The placeholder text for the codemirror box.
904 - *
905 - * @return array|false
330 + * @return void
906 331 */
907 - private static function enqueue_codemirror( $id = 'frm_codemirror_box', $placeholder = '' ) {
908 - if ( ! function_exists( 'wp_enqueue_code_editor' ) ) {
909 - // The WordPress version is likely older than 4.9.
910 - return false;
911 - }
332 + public static function save_css() {
333 + $frm_style = new FrmStyle();
912 334
913 - $settings = wp_enqueue_code_editor(
914 - array(
915 - 'type' => 'text/css',
916 - 'codemirror' => array(
917 - 'indentUnit' => 2,
918 - 'tabSize' => 2,
919 - // As the codemirror box only appears once you click into the Custom CSS tab, we need to auto-refresh.
920 - // Otherwise the line numbers all end up with a 1px width causing overlap issues with the text in the content.
921 - 'autoRefresh' => true,
922 - 'placeholder' => $placeholder,
923 - ),
924 - )
925 - );
926 -
927 - if ( $settings ) {
928 - wp_add_inline_script(
929 - 'code-editor',
930 - sprintf(
931 - 'jQuery( function() { window.%s_wp_editor = wp.codeEditor.initialize( \'%s\', %s ); } );',
932 - $id,
933 - $id,
934 - wp_json_encode( $settings )
935 - )
936 - );
335 + $message = '';
336 + $post_id = FrmAppHelper::get_post_param( 'ID', false, 'sanitize_text_field' );
337 + $nonce = FrmAppHelper::get_post_param( 'frm_custom_css', '', 'sanitize_text_field' );
338 + if ( wp_verify_nonce( $nonce, 'frm_custom_css_nonce' ) ) {
339 + $frm_style->update( $post_id );
340 + $message = __( 'Your styling settings have been saved.', 'formidable' );
937 341 }
938 342
939 - return $settings;
343 + self::custom_css( $message );
940 344 }
941 345
942 - /**
943 - * Handling routing for the visual styler.
944 - *
945 - * @return void
946 - */
947 346 public static function route() {
948 347 $action = FrmAppHelper::get_param( 'frm_action', '', 'get', 'sanitize_title' );
949 348 FrmAppHelper::include_svg();
950 349
@@ -950,102 +349,53 @@
950 349
951 350 switch ( $action ) {
952 351 case 'edit':
953 352 case 'save':
954 - self::$action();
955 - return;
353 + case 'manage':
354 + case 'manage_styles':
355 + case 'custom_css':
356 + case 'save_css':
357 + return self::$action();
956 358 default:
957 359 do_action( 'frm_style_action_route', $action );
958 -
959 360 if ( apply_filters( 'frm_style_stop_action_route', false, $action ) ) {
960 361 return;
961 362 }
962 363
963 - if ( in_array( $action, array( 'new_style', 'duplicate' ), true ) ) {
964 - self::$action();
965 - return;
364 + if ( 'new_style' == $action || 'duplicate' == $action ) {
365 + return self::$action();
966 366 }
967 367
968 - self::edit();
969 - return;
368 + return self::edit();
970 369 }
971 370 }
972 371
973 - /**
974 - * Handle AJAX routing for frm_settings_reset for resetting styles to the default settings.
975 - * From the edit view, it will return default styles and not actually update the style.
976 - * On the list view, it does update the style immediately, and returns the default card style attributes so the style card can be reset as well.
977 - *
978 - * @since 6.0 When a style_id is passed to this action, the style will actually be reset.
979 - *
980 - * @return void
981 - */
982 372 public static function reset_styling() {
983 373 FrmAppHelper::permission_check( 'frm_change_settings' );
984 374 check_ajax_referer( 'frm_ajax', 'nonce' );
985 375
986 - $style_id = FrmAppHelper::get_post_param( 'style_id', '', 'absint' );
376 + $frm_style = new FrmStyle();
377 + $defaults = $frm_style->get_defaults();
987 378
988 - if ( ! $style_id ) {
989 - // A style ID is not sent when resetting on the edit page.
990 - // Instead of resetting the style, send the defaults back so the inputs can be updated with JavaScript.
991 - $frm_style = new FrmStyle();
992 - $defaults = $frm_style->get_defaults();
993 - echo json_encode( $defaults );
994 - wp_die();
995 - }
996 -
997 - $frm_style = new FrmStyle();
998 - $default_template_style = $frm_style->get_default_template_style( $style_id );
999 - $where = array(
1000 - 'ID' => $style_id,
1001 - 'post_type' => self::$post_type,
1002 - );
1003 -
1004 - $style_object = $frm_style->get_new();
1005 - $style_object->post_content = json_decode( $default_template_style, true );
1006 -
1007 - global $wpdb;
1008 - $wpdb->update( $wpdb->posts, array( 'post_content' => $default_template_style ), $where );
1009 -
1010 - // Save the settings after resetting to default or the old style will still appear.
1011 - $frm_style->save_settings();
1012 -
1013 - $data = array(
1014 - 'style' => FrmStylesCardHelper::get_style_param_for_card( $style_object ),
1015 - );
1016 - wp_send_json_success( $data );
379 + echo json_encode( $defaults );
1017 380 wp_die();
1018 381 }
1019 382
1020 - /**
1021 - * Handle routing for the frm_change_styling AJAX action.
1022 - * This doesn't actually change styling. It just handles the events when someone changes a style.
1023 - * It responds with the new CSS required for the updated styler preview in the edit page.
1024 - *
1025 - * @return void
1026 - */
1027 383 public static function change_styling() {
1028 - FrmAppHelper::permission_check( 'frm_change_settings' );
1029 384 check_ajax_referer( 'frm_ajax', 'nonce' );
1030 385
1031 - $is_loaded_via_ajax = true;
1032 - $frm_style = new FrmStyle();
386 + $frm_style = new FrmStyle();
387 + $defaults = $frm_style->get_defaults();
388 + $style = '';
1033 389
1034 - // Intentionally avoid defaults here so nothing gets removed from our style.
1035 - $defaults = array();
1036 - $style = '';
1037 -
1038 390 echo '<style type="text/css">';
1039 - include FrmAppHelper::plugin_path() . '/css/_single_theme.css.php';
391 + include( FrmAppHelper::plugin_path() . '/css/_single_theme.css.php' );
1040 392 echo '</style>';
1041 393 wp_die();
1042 394 }
1043 395
1044 - /**
1045 - * @return void
1046 - */
1047 - public static function add_meta_boxes() {
396 + private static function add_meta_boxes() {
397 +
1048 398 // setup meta boxes
1049 399 $meta_boxes = array(
1050 400 'general' => __( 'General', 'formidable' ),
1051 401 'form-title' => __( 'Form Title', 'formidable' ),
@@ -1062,10 +412,8 @@
1062 412 /**
1063 413 * Add custom boxes to the styling settings
1064 414 *
1065 415 * @since 2.3
1066 - *
1067 - * @param array $meta_boxes
1068 416 */
1069 417 $meta_boxes = apply_filters( 'frm_style_boxes', $meta_boxes );
1070 418
1071 419 foreach ( $meta_boxes as $nicename => $name ) {
@@ -1073,14 +421,8 @@
1073 421 unset( $nicename, $name );
1074 422 }
1075 423 }
1076 424
1077 - /**
1078 - * @param array $atts
1079 - * @param array $sec
1080 - *
1081 - * @return void
1082 - */
1083 425 public static function include_style_section( $atts, $sec ) {
1084 426 extract( $atts ); // phpcs:ignore WordPress.PHP.DontExtract
1085 427 $style = $atts['style'];
1086 428 FrmStylesHelper::prepare_color_output( $style->post_content, false );
@@ -1097,9 +439,9 @@
1097 439 */
1098 440 $file_name = apply_filters( 'frm_style_settings_' . $sec['args'], $file_name );
1099 441
1100 442 echo '<div class="frm_grid_container">';
1101 - include $file_name;
443 + include( $file_name );
1102 444 echo '</div>';
1103 445 }
1104 446
1105 447 public static function load_css() {
@@ -1133,37 +475,17 @@
1133 475 */
1134 476 $output = apply_filters( 'frm_saved_css', $output );
1135 477
1136 478 echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1137 -
1138 - self::maybe_hide_sample_form_error_message();
1139 -
1140 479 wp_die();
1141 480 }
1142 481
1143 482 /**
1144 - * Add an extra style rule to hide a broken style warning.
1145 - * To avoid cluttering the front end with any unnecessary styles this is only added when the referer URL matches the styler.
1146 - *
1147 - * @since 6.2.3
1148 - *
1149 - * @return void
1150 - */
1151 - public static function maybe_hide_sample_form_error_message() {
1152 - $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' );
1153 -
1154 - if ( str_contains( $referer, 'admin.php?page=formidable-styles' ) ) {
1155 - echo '#frm_broken_styles_warning { display: none; }';
1156 - }
1157 - }
1158 -
1159 - /**
1160 483 * Replaces relative URL with absolute URL.
1161 484 *
1162 485 * @since 4.11.03
1163 486 *
1164 487 * @param string $css CSS content.
1165 - *
1166 488 * @return string
1167 489 */
1168 490 public static function replace_relative_url( $css ) {
1169 491 $plugin_url = trailingslashit( FrmAppHelper::plugin_url() );
@@ -1186,22 +508,19 @@
1186 508 * Check if the Formidable styling should be loaded,
1187 509 * then enqueue it for the footer
1188 510 *
1189 511 * @since 2.0
1190 - *
1191 - * @return void
1192 512 */
1193 513 public static function enqueue_style() {
1194 514 global $frm_vars;
1195 515
1196 - if ( ! empty( $frm_vars['css_loaded'] ) ) {
516 + if ( isset( $frm_vars['css_loaded'] ) && $frm_vars['css_loaded'] ) {
1197 517 // The CSS has already been loaded.
1198 518 return;
1199 519 }
1200 520
1201 521 $frm_settings = FrmAppHelper::get_settings();
1202 -
1203 - if ( $frm_settings->load_style !== 'none' ) {
522 + if ( $frm_settings->load_style != 'none' ) {
1204 523 wp_enqueue_style( 'formidable' );
1205 524 $frm_vars['css_loaded'] = true;
1206 525 }
1207 526 }
@@ -1207,32 +526,25 @@
1207 526 }
1208 527
1209 528 /**
1210 529 * Get the stylesheets for the form settings page
1211 - *
1212 - * @return array<WP_Post>
1213 530 */
1214 531 public static function get_style_opts() {
1215 532 $frm_style = new FrmStyle();
1216 - return $frm_style->get_all();
533 + $styles = $frm_style->get_all();
534 +
535 + return $styles;
1217 536 }
1218 537
1219 - /**
1220 - * Get the style post object for a target form.
1221 - *
1222 - * @param bool|object|string $form
1223 - *
1224 - * @return WP_Post|null
1225 - */
1226 538 public static function get_form_style( $form = 'default' ) {
1227 539 $style = FrmFormsHelper::get_form_style( $form );
1228 540
1229 - // phpcs:ignore Universal.Operators.StrictComparisons
1230 - if ( ! $style || 1 == $style ) {
541 + if ( empty( $style ) || 1 == $style ) {
1231 542 $style = 'default';
1232 543 }
1233 544
1234 545 $frm_style = new FrmStyle( $style );
546 +
1235 547 return $frm_style->get_one();
1236 548 }
1237 549
1238 550 /**
@@ -1237,13 +549,10 @@
1237 549
1238 550 /**
1239 551 * @param string $class
1240 552 * @param string $style
1241 - *
1242 - * @return string
1243 553 */
1244 554 public static function get_form_style_class( $class, $style ) {
1245 - // phpcs:ignore Universal.Operators.StrictComparisons
1246 555 if ( 1 == $style ) {
1247 556 $style = 'default';
1248 557 }
1249 558
@@ -1258,18 +567,15 @@
1258 567 return $class;
1259 568 }
1260 569
1261 570 /**
1262 - * @since 3.0
1263 - *
1264 571 * @param object $style
1265 572 * @param string $class
1266 573 *
1267 - * @return void
574 + * @since 3.0
1268 575 */
1269 576 private static function maybe_add_rtl_class( $style, &$class ) {
1270 577 $is_rtl = isset( $style->post_content['direction'] ) && 'rtl' === $style->post_content['direction'];
1271 -
1272 578 if ( $is_rtl ) {
1273 579 $class .= ' frm_rtl';
1274 580 }
1275 581 }
@@ -1274,28 +580,17 @@
1274 580 }
1275 581 }
1276 582
1277 583 /**
1278 - * @param string $val Style setting key.
1279 - * @param int|string $form Form ID or 'default'.
1280 - *
1281 - * @return mixed
584 + * @param string $val
1282 585 */
1283 586 public static function get_style_val( $val, $form = 'default' ) {
1284 587 $style = self::get_form_style( $form );
1285 -
1286 588 if ( $style && isset( $style->post_content[ $val ] ) ) {
1287 589 return $style->post_content[ $val ];
1288 590 }
1289 -
1290 - return null;
1291 591 }
1292 592
1293 - /**
1294 - * @param array $default_styles
1295 - *
1296 - * @return array
1297 - */
1298 593 public static function show_entry_styles( $default_styles ) {
1299 594 $frm_style = new FrmStyle( 'default' );
1300 595 $style = $frm_style->get_one();
1301 596
@@ -1304,15 +599,13 @@
1304 599 }
1305 600
1306 601 foreach ( $default_styles as $name => $val ) {
1307 602 $setting = $name;
1308 -
1309 - if ( 'border_width' === $name ) {
603 + if ( 'border_width' == $name ) {
1310 604 $setting = 'field_border_width';
1311 - } elseif ( 'alt_bg_color' === $name ) {
605 + } elseif ( 'alt_bg_color' == $name ) {
1312 606 $setting = 'bg_color_active';
1313 607 }
1314 -
1315 608 $default_styles[ $name ] = $style->post_content[ $setting ];
1316 609 unset( $name, $val );
1317 610 }
1318 611
@@ -1318,172 +611,14 @@
1318 611
1319 612 return $default_styles;
1320 613 }
1321 614
1322 - /**
1323 - * @param string $important
1324 - * @param array $field
1325 - *
1326 - * @return string
1327 - */
1328 615 public static function &important_style( $important, $field ) {
1329 616 $important = self::get_style_val( 'important_style', $field['form_id'] );
617 +
1330 618 return $important;
1331 619 }
1332 620
1333 - /**
1334 - * Duplicate of WordPress do_accordion_section function, it adds an additional svg icon support.
1335 - *
1336 - * @since 6.8.3
1337 - *
1338 - * @param string|WP_Screen $screen Screen ID or screen object.
1339 - * @param string $context Meta box context.
1340 - * @param mixed $data_object Data object passed to callbacks.
1341 - *
1342 - * @return int
1343 - */
1344 - public static function do_accordion_sections( $screen, $context, $data_object ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh
1345 - global $wp_meta_boxes;
1346 -
1347 - // the symbol id from icons.svg
1348 - $icon_ids = array(
1349 - 'ranking-fields-style' => 'frm_chart_bar_icon',
1350 - 'section-fields-style' => 'frm-form-title-style',
1351 - );
1352 -
1353 - wp_enqueue_script( 'accordion' );
1354 -
1355 - if ( ! $screen ) {
1356 - $screen = get_current_screen();
1357 - } elseif ( is_string( $screen ) ) {
1358 - $screen = convert_to_screen( $screen );
1359 - }
1360 -
1361 - $page = $screen->id;
1362 -
1363 - ?>
1364 - <div id="side-sortables" class="accordion-container">
1365 - <ul class="outer-border">
1366 - <?php
1367 - $i = 0;
1368 - $first_open = false;
1369 -
1370 - if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) {
1371 - foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) {
1372 - if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) {
1373 - foreach ( $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
1374 - if ( false === $box || ! $box['title'] ) {
1375 - continue;
1376 - }
1377 -
1378 - ++$i;
1379 - $icon_id = array_key_exists( $box['id'], $icon_ids ) ? $icon_ids[ $box['id'] ] : 'frm-' . $box['id'];
1380 - $open_class = '';
1381 -
1382 - if ( ! $first_open ) {
1383 - $first_open = true;
1384 - $open_class = 'open';
1385 - }
1386 -
1387 - $accordion_content_id = 'frm_style_section_' . $box['id'];
1388 - ?>
1389 - <li class="control-section accordion-section <?php echo esc_attr( $open_class ); ?> <?php echo esc_attr( $box['id'] ); ?>" id="<?php echo esc_attr( $box['id'] ); ?>"><?php // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong ?>
1390 - <h3 class="accordion-section-title hndle">
1391 - <?php
1392 - FrmAppHelper::icon_by_class( 'frmfont ' . $icon_id . ' frm_svg24' );
1393 - echo esc_html( $box['title'] );
1394 - ?>
1395 - <button type="button" aria-expanded="<?php echo esc_attr( 'open' === $open_class ? 'true' : 'false' ); ?>" aria-controls="<?php echo esc_attr( $accordion_content_id ); ?>" aria-label="<?php echo esc_attr( $box['title'] ); ?>"><?php // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong ?>
1396 - <?php FrmAppHelper::icon_by_class( 'frmfont frm_arrowdown8_icon' ); ?>
1397 - </button>
1398 - </h3>
1399 - <div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>" id="<?php echo esc_attr( $accordion_content_id ); ?>">
1400 - <div class="inside">
1401 - <?php call_user_func( $box['callback'], $data_object, $box ); ?>
1402 - </div><!-- .inside -->
1403 - </div><!-- .accordion-section-content -->
1404 - </li><!-- .accordion-section -->
1405 - <?php
1406 - }//end foreach
1407 - }//end if
1408 - }//end foreach
1409 - }//end if
1410 - ?>
1411 - </ul><!-- .outer-border -->
1412 - </div><!-- .accordion-container -->
1413 - <?php
1414 - return $i;
1415 - }
1416 -
1417 - /**
1418 - * Rename a style via an AJAX action.
1419 - *
1420 - * @since 6.0
1421 - *
1422 - * @return void
1423 - */
1424 - public static function rename_style() {
1425 - $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'nonce', 'frm_ajax' );
1426 -
1427 - if ( $permission_error !== false ) {
1428 - $data = array(
1429 - 'message' => __( 'Unable to rename style', 'formidable' ),
1430 - );
1431 - wp_send_json_error( $data, 403 );
1432 - die();
1433 - }
1434 -
1435 - $style_id = FrmAppHelper::get_post_param( 'style_id', 0, 'absint' );
1436 - $style_name = FrmAppHelper::get_post_param( 'style_name', '', 'sanitize_text_field' );
1437 -
1438 - if ( ! $style_id || ! $style_name ) {
1439 - $data = array(
1440 - 'message' => __( 'Invalid route', 'formidable' ),
1441 - );
1442 - wp_send_json_error( $data, 400 );
1443 - die();
1444 - }
1445 -
1446 - $post = get_post( $style_id );
1447 -
1448 - if ( ! $post || $post->post_type !== self::$post_type ) {
1449 - $data = array(
1450 - 'message' => __( 'The style you are renaming either does not exist or it is not a style', 'formidable' ),
1451 - );
1452 - wp_send_json_error( $data, 404 );
1453 - die();
1454 - }
1455 -
1456 - global $wpdb;
1457 - $wpdb->update( $wpdb->posts, array( 'post_title' => $style_name ), array( 'ID' => $post->ID ) );
1458 -
1459 - $data = array();
1460 - wp_send_json_success( $data );
1461 - }
1462 -
1463 - /**
1464 - * Prevent the WordPress edit.css file from loading on the visual styler page.
1465 - * This way .form-field elements do not have border styles applied to them.
1466 - *
1467 - * @since 6.0
1468 - *
1469 - * @param WP_Styles $styles
1470 - *
1471 - * @return void
1472 - */
1473 - public static function disable_conflicting_wp_admin_css( $styles ) {
1474 - if ( ! FrmAppHelper::is_style_editor_page() ) {
1475 - return;
1476 - }
1477 -
1478 - FrmStylesPreviewHelper::disable_conflicting_wp_admin_css( $styles );
1479 - }
1480 -
1481 - /**
1482 - * @deprecated 6.1 Saving custom CSS has been moved into Global Settings.
1483 - *
1484 - * @return void
1485 - */
1486 - public static function save_css() {
1487 - _deprecated_function( __METHOD__, '6.1' );
621 + public static function do_accordion_sections( $screen, $context, $object ) {
622 + return do_accordion_sections( $screen, $context, $object );
1488 623 }
1489 624 }