PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.1
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 +108 -357 6.296.1 View file →
@@ -5,25 +5,22 @@
5 5
6 6 class FrmStylesController {
7 7
8 8 /**
9 - * @var string
9 + * @var string $post_type
10 10 */
11 11 public static $post_type = 'frm_styles';
12 12
13 13 /**
14 - * @var string
14 + * @var string $screen
15 15 */
16 16 public static $screen = 'formidable_page_formidable-styles';
17 17
18 18 /**
19 - * @var string|null
19 + * @var string|null $message
20 20 */
21 21 private static $message;
22 22
23 - /**
24 - * @return void
25 - */
26 23 public static function load_pro_hooks() {
27 24 if ( FrmAppHelper::pro_is_installed() ) {
28 25 FrmProStylesController::load_pro_hooks();
29 26 }
@@ -28,11 +25,8 @@
28 25 FrmProStylesController::load_pro_hooks();
29 26 }
30 27 }
31 28
32 - /**
33 - * @return void
34 - */
35 29 public static function register_post_types() {
36 30 register_post_type(
37 31 self::$post_type,
38 32 array(
@@ -73,10 +67,10 @@
73 67 *
74 68 * @return void
75 69 */
76 70 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
71 + add_submenu_page( 'formidable', 'Formidable | ' . __( 'Styles', 'formidable' ), __( 'Styles', 'formidable' ), 'frm_change_settings', 'formidable-styles', 'FrmStylesController::route' );
72 + add_submenu_page( 'themes.php', 'Formidable | ' . __( 'Styles', 'formidable' ), __( 'Forms', 'formidable' ), 'frm_change_settings', 'formidable-styles2', 'FrmStylesController::route' );
79 73 }
80 74
81 75 /**
82 76 * Remove filters for the visual styler preview.
@@ -101,9 +95,9 @@
101 95 *
102 96 * @return void
103 97 */
104 98 private static function disable_form_css() {
105 - add_filter( 'get_frm_stylesheet', '__return_empty_array' );
99 + add_filter( 'get_frm_stylesheet', '__return_false' );
106 100 }
107 101
108 102 /**
109 103 * Removing this action prevents front end JavaScript from loading.
@@ -125,12 +119,12 @@
125 119 if ( ! FrmAppHelper::is_style_editor_page() ) {
126 120 return;
127 121 }
128 122
129 - FrmStyleComponent::register_assets();
130 123 self::load_pro_hooks();
131 124
132 125 $version = FrmAppHelper::plugin_version();
126 + wp_enqueue_script( 'jquery-ui-datepicker' );
133 127
134 128 if ( FrmAppHelper::is_style_editor_page( 'edit' ) ) {
135 129 wp_enqueue_style( 'wp-color-picker' );
136 130 }
@@ -137,11 +131,10 @@
137 131
138 132 wp_enqueue_style( 'frm-custom-theme', admin_url( 'admin-ajax.php?action=frmpro_css' ), array(), $version );
139 133
140 134 $style = apply_filters( 'frm_style_head', false );
141 -
142 135 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
136 + 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 137 }
145 138 }
146 139
147 140 /**
@@ -159,9 +152,9 @@
159 152 'frm_update_settings',
160 153 /**
161 154 * Update the form data on the "Manage Styles" tab after global settings are saved.
162 155 */
163 - function () {
156 + function() {
164 157 self::manage_styles();
165 158 }
166 159 );
167 160 }
@@ -168,9 +161,8 @@
168 161
169 162 /**
170 163 * @param string $register Either 'enqueue' or 'register'.
171 164 * @param bool $force True to enqueue/register the style if a form has not been loaded.
172 - *
173 165 * @return void
174 166 */
175 167 public static function enqueue_css( $register = 'enqueue', $force = false ) {
176 168 global $frm_vars;
@@ -182,9 +174,8 @@
182 174 return;
183 175 }
184 176
185 177 $frm_settings = FrmAppHelper::get_settings();
186 -
187 178 if ( $frm_settings->load_style === 'none' ) {
188 179 return;
189 180 }
190 181
@@ -200,10 +191,9 @@
200 191 wp_register_style( $css_key, $file, array(), $this_version );
201 192 }
202 193
203 194 $load_on_all = ! FrmAppHelper::is_admin() && 'all' === $frm_settings->load_style;
204 -
205 - if ( $load_on_all || $register !== 'register' ) {
195 + if ( $load_on_all || $register != 'register' ) {
206 196 wp_enqueue_style( $css_key );
207 197 }
208 198 unset( $css_key, $file );
209 199 }
@@ -210,9 +200,9 @@
210 200
211 201 if ( $frm_settings->load_style === 'all' ) {
212 202 $frm_vars['css_loaded'] = true;
213 203 }
214 - }//end if
204 + }
215 205 unset( $css );
216 206
217 207 add_filter( 'style_loader_tag', 'FrmStylesController::add_tags_to_css', 10, 2 );
218 208 }
@@ -233,20 +223,17 @@
233 223 }
234 224
235 225 /**
236 226 * @param array $stylesheet_urls
237 - *
238 227 * @return void
239 228 */
240 229 private static function get_url_to_custom_style( &$stylesheet_urls ) {
241 230 $file_name = '/css/' . self::get_file_name();
242 -
243 231 if ( is_readable( FrmAppHelper::plugin_path() . $file_name ) ) {
244 232 $url = FrmAppHelper::plugin_url() . $file_name;
245 233 } else {
246 234 $url = admin_url( 'admin-ajax.php?action=frmpro_css' );
247 235 }
248 -
249 236 $stylesheet_urls['formidable'] = $url;
250 237 }
251 238
252 239 /**
@@ -252,45 +239,39 @@
252 239 /**
253 240 * Use a different stylesheet per site in a multisite install
254 241 *
255 242 * @since 3.0.03
256 - *
257 - * @return string
258 243 */
259 244 public static function get_file_name() {
260 245 if ( is_multisite() ) {
261 246 $blog_id = get_current_blog_id();
262 - return 'formidableforms' . absint( $blog_id ) . '.css';
247 + $name = 'formidableforms' . absint( $blog_id ) . '.css';
248 + } else {
249 + $name = 'formidableforms.css';
263 250 }
264 251
265 - return 'formidableforms.css';
252 + return $name;
266 253 }
267 254
268 - /**
269 - * @param string $css_key
270 - * @param string $version
271 - *
272 - * @return string
273 - */
274 255 private static function get_css_version( $css_key, $version ) {
275 - if ( 'formidable' !== $css_key ) {
276 - return $version;
256 + if ( 'formidable' == $css_key ) {
257 + $this_version = get_option( 'frm_last_style_update' );
258 + if ( ! $this_version ) {
259 + $this_version = $version;
260 + }
261 + } else {
262 + $this_version = $version;
277 263 }
278 264
279 - $this_version = get_option( 'frm_last_style_update' );
280 -
281 - return $this_version ? $this_version : $version;
265 + return $this_version;
282 266 }
283 267
284 - /**
285 - * @param string $tag
286 - * @param string $handle
287 - *
288 - * @return string
289 - */
290 268 public static function add_tags_to_css( $tag, $handle ) {
291 - if ( ( 'formidable' === $handle || 'jquery-theme' === $handle ) && ! str_contains( $tag, ' property=' ) ) {
292 - return str_replace( ' type="', ' property="stylesheet" type="', $tag );
269 + if ( ( 'formidable' == $handle || 'jquery-theme' == $handle ) && strpos( $tag, ' property=' ) === false ) {
270 + $frm_settings = FrmAppHelper::get_settings();
271 + if ( $frm_settings->use_html ) {
272 + $tag = str_replace( ' type="', ' property="stylesheet" type="', $tag );
273 + }
293 274 }
294 275
295 276 return $tag;
296 277 }
@@ -338,35 +319,20 @@
338 319
339 320 self::setup_styles_and_scripts_for_styler();
340 321
341 322 $style_id = self::get_style_id_for_styler();
342 -
343 323 if ( ! $style_id ) {
344 - $error_args = array(
345 - 'title' => __( 'No styles', 'formidable' ),
346 - 'body' => __( 'You must have a style to use the Visual Styler.', 'formidable' ),
347 - 'cancel_url' => admin_url( 'admin.php?page=formidable' ),
348 - );
349 - FrmAppController::show_error_modal( $error_args );
350 - return;
324 + wp_die( esc_html__( 'Invalid route', 'formidable' ), esc_html__( 'Invalid route', 'formidable' ), 400 );
351 325 }
352 326
353 327 $form_id = FrmAppHelper::simple_get( 'form', 'absint', 0 );
354 -
355 328 if ( ! $form_id ) {
356 329 $form_id = self::get_form_id_for_style( $style_id );
357 330 }
358 331
359 332 $form = FrmForm::getOne( $form_id );
360 -
361 333 if ( ! is_object( $form ) ) {
362 - $error_args = array(
363 - 'title' => __( 'No forms', 'formidable' ),
364 - 'body' => __( 'You must have a form to use the Visual Styler.', 'formidable' ),
365 - 'cancel_url' => admin_url( 'admin.php?page=formidable' ),
366 - );
367 - FrmAppController::show_error_modal( $error_args );
368 - return;
334 + wp_die( esc_html__( 'Invalid route', 'formidable' ), esc_html__( 'Invalid route', 'formidable' ), 400 );
369 335 }
370 336
371 337 $frm_style = new FrmStyle( $style_id );
372 338 $active_style = $frm_style->get_one();
@@ -376,9 +342,11 @@
376 342
377 343 /**
378 344 * @since 6.0
379 345 *
380 - * @param array{form:\stdClass} $data
346 + * @param array {
347 + * @type stdClass $form
348 + * }
381 349 */
382 350 do_action( 'frm_before_render_style_page', compact( 'form' ) );
383 351
384 352 self::render_style_page( $active_style, $form, $default_style );
@@ -390,9 +358,8 @@
390 358 * @return int
391 359 */
392 360 private static function get_style_id_for_styler() {
393 361 $action = FrmAppHelper::simple_get( 'frm_action' );
394 -
395 362 if ( 'duplicate' === $action ) {
396 363 // The duplicate action uses style_id instead of id for better backward compatibility.
397 364 return FrmAppHelper::simple_get( 'style_id', 'absint', 0 );
398 365 }
@@ -397,9 +364,8 @@
397 364 return FrmAppHelper::simple_get( 'style_id', 'absint', 0 );
398 365 }
399 366
400 367 $style_id = FrmAppHelper::simple_get( 'id', 'absint', 0 );
401 -
402 368 if ( $style_id ) {
403 369 // Always use the style ID from the URL if one is specified.
404 370 return $style_id;
405 371 }
@@ -404,9 +370,8 @@
404 370 return $style_id;
405 371 }
406 372
407 373 $request_form_id = FrmAppHelper::simple_get( 'form', 'absint', 0 );
408 -
409 374 if ( $request_form_id && is_callable( 'FrmProStylesController::get_active_style_for_form' ) ) {
410 375 return FrmProStylesController::get_active_style_for_form( $request_form_id )->ID;
411 376 }
412 377
@@ -418,9 +383,8 @@
418 383 *
419 384 * @since 6.0
420 385 *
421 386 * @param int $style_id
422 - *
423 387 * @return int
424 388 */
425 389 private static function get_form_id_for_style( $style_id ) {
426 390 $check = serialize( array( 'custom_style' => (string) $style_id ) );
@@ -433,13 +397,13 @@
433 397 )
434 398 );
435 399
436 400 if ( ! $form_id ) {
401 + // TODO: Show a message why a random form is being shown (because no form is assigned to the style).
437 402 // Fallback to any form.
438 - $where = array(
403 + $where = array(
439 404 'status' => 'published',
440 - // Make sure it's not a repeater.
441 - 'parent_form_id' => array( null, 0 ),
405 + 'parent_form_id' => array( null, 0 ), // Make sure it's not a repeater.
442 406 );
443 407 $form_id = FrmDb::get_var( 'frm_forms', $where, 'id' );
444 408 }
445 409
@@ -453,9 +417,9 @@
453 417 */
454 418 private static function disable_admin_page_styling_on_submit_buttons() {
455 419 add_filter(
456 420 'frm_submit_button_class',
457 - function ( $classes ) {
421 + function( $classes ) {
458 422 $classes[] = 'frm_no_style_button';
459 423 return $classes;
460 424 }
461 425 );
@@ -466,10 +430,11 @@
466 430 *
467 431 * @return WP_Post
468 432 */
469 433 private static function get_default_style() {
470 - $frm_style = new FrmStyle( 'default' );
471 - return $frm_style->get_one();
434 + $frm_style = new FrmStyle( 'default' );
435 + $default_style = $frm_style->get_one();
436 + return $default_style;
472 437 }
473 438
474 439 /**
475 440 * Save style for form (from Styler list page) via a POST action.
@@ -479,15 +444,13 @@
479 444 * @return void
480 445 */
481 446 private static function save_form_style() {
482 447 $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'frm_save_form_style', 'frm_save_form_style_nonce' );
483 -
484 448 if ( $permission_error !== false ) {
485 449 wp_die( 'Unable to save form', '', 403 );
486 450 }
487 451
488 452 $style_id = FrmAppHelper::get_post_param( 'style_id', 0, 'absint' );
489 -
490 453 if ( $style_id && ! self::confirm_style_exists_before_setting( $style_id ) ) {
491 454 wp_die( esc_html__( 'Invalid target style', 'formidable' ), esc_html__( 'Invalid target style', 'formidable' ), 400 );
492 455 return;
493 456 }
@@ -500,16 +463,15 @@
500 463 * @param int $style_id
501 464 */
502 465 $style_id = apply_filters( 'frm_saved_form_style_id', $style_id );
503 466
504 - if ( ! $style_id && '0' !== FrmAppHelper::get_post_param( 'style_id', '', 'sanitize_text_field' ) ) {
467 + if ( ! $style_id && '0' !== FrmAppHelper::get_post_param( 'style_id', 'sanitize_text_field', '' ) ) {
505 468 // "0" is a special value used for the enable/disable toggle.
506 469 wp_die( esc_html__( 'Invalid style value', 'formidable' ), esc_html__( 'Invalid style value', 'formidable' ), 400 );
507 470 return;
508 471 }
509 472
510 - $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' );
511 -
473 + $form_id = FrmAppHelper::get_post_param( 'form_id', 'absint', 0 );
512 474 if ( ! $form_id ) {
513 475 wp_die( esc_html__( 'No form specified', 'formidable' ), esc_html__( 'No form specified', 'formidable' ), 400 );
514 476 return;
515 477 }
@@ -514,47 +476,28 @@
514 476 return;
515 477 }
516 478
517 479 $form = FrmForm::getOne( $form_id );
518 -
519 480 if ( ! $form ) {
520 481 wp_die( esc_html__( 'Form does not exist', 'formidable' ), esc_html__( 'Form does not exist', 'formidable' ), 400 );
521 482 return;
522 483 }
523 484
524 - $previous_style_id = $form->options['custom_style'];
525 -
526 485 // If the default style is selected, use the "Always use default" legacy option instead of the default style.
527 486 // There's also a check here for conversational forms.
528 487 // Without the check it isn't possible to select "Default" because "Always use default" will convert to "Lines" dynamically.
529 488 $default_style = self::get_default_style();
530 -
531 489 if ( $style_id === $default_style->ID && empty( $form->options['chat'] ) ) {
532 490 $style_id = 1;
533 491 }
534 492
535 - // We want to save a string for consistency. FrmStylesHelper::get_form_count_for_style expects the custom style ID is a string.
536 - $form->options['custom_style'] = (string) $style_id;
493 + $form->options['custom_style'] = (string) $style_id; // We want to save a string for consistency. FrmStylesHelper::get_form_count_for_style expects the custom style ID is a string.
537 494
538 - if ( $previous_style_id === $form->options['custom_style'] ) {
539 - // Exit early before updating DB if nothing actually changed.
540 - self::$message = __( 'Successfully updated style.', 'formidable' );
541 - return;
542 - }
543 -
544 495 global $wpdb;
545 496 $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $form->options ) ), array( 'id' => $form->id ) );
546 497
547 498 FrmForm::clear_form_cache();
548 499
549 - /**
550 - * @since 6.25.1
551 - *
552 - * @param int $form_id
553 - * @param int $style_id
554 - */
555 - do_action( 'frm_after_changed_form_style', absint( $form_id ), absint( $style_id ) );
556 -
557 500 self::$message = __( 'Successfully updated style.', 'formidable' );
558 501 }
559 502
560 503 /**
@@ -560,9 +503,8 @@
560 503 /**
561 504 * Validate that we're assigning a form to a style that actually exists before assigning it to a form.
562 505 *
563 506 * @param int $style_id
564 - *
565 507 * @return bool True if the style actually exists.
566 508 */
567 509 private static function confirm_style_exists_before_setting( $style_id ) {
568 510 global $wpdb;
@@ -581,9 +523,9 @@
581 523 $plugin_url = FrmAppHelper::plugin_url();
582 524 $version = FrmAppHelper::plugin_version();
583 525 $js_dependencies = array( 'wp-i18n', 'wp-hooks', 'formidable_dom' );
584 526
585 - if ( FrmAppHelper::pro_is_installed() && is_callable( 'FrmProAppHelper::use_jquery_datepicker' ) && FrmProAppHelper::use_jquery_datepicker() ) {
527 + if ( FrmAppHelper::pro_is_installed() ) {
586 528 $js_dependencies[] = 'jquery-ui-datepicker';
587 529 }
588 530
589 531 wp_register_script( 'formidable_style', $plugin_url . '/js/admin/style.js', $js_dependencies, $version );
@@ -591,9 +533,8 @@
591 533 wp_print_styles( 'formidable_style' );
592 534
593 535 wp_print_styles( 'formidable' );
594 536 wp_enqueue_script( 'formidable_style' );
595 - wp_set_script_translations( 'formidable_style', 'formidable' );
596 537 }
597 538
598 539 /**
599 540 * Render the style page (with a more limited and typed scope than calling it from self::style directly).
@@ -600,22 +541,20 @@
600 541 *
601 542 * @since 6.0
602 543 *
603 544 * @param stdClass|WP_Post $active_style
545 + * @param array<WP_Post> $styles
604 546 * @param stdClass $form
605 547 * @param WP_Post $default_style
606 - *
607 548 * @return void
608 549 */
609 550 private static function render_style_page( $active_style, $form, $default_style ) {
610 551 $style_views_path = self::get_views_path();
611 - // Edit, list (default), new_style.
612 - $view = FrmAppHelper::simple_get( 'frm_action', 'sanitize_text_field', 'list' );
613 - $frm_style = new FrmStyle( $active_style->ID );
552 + $view = FrmAppHelper::simple_get( 'frm_action', 'sanitize_text_field', 'list' ); // edit, list (default), new_style.
553 + $frm_style = new FrmStyle( $active_style->ID );
614 554
615 555 if ( 'new_style' !== $view && ! FrmAppHelper::simple_get( 'form' ) && ! FrmAppHelper::simple_get( 'style_id' ) ) {
616 - // Have the Appearance > Forms link fallback to the edit view. Otherwise we want to use 'list' as the default.
617 - $view = 'edit';
556 + $view = 'edit'; // Have the Appearance > Forms link fallback to the edit view. Otherwise we want to use 'list' as the default.
618 557 }
619 558
620 559 if ( in_array( $view, array( 'edit', 'new_style', 'duplicate' ), true ) ) {
621 560 self::add_meta_boxes();
@@ -678,23 +617,22 @@
678 617 * Filter form classes so the form uses the preview style, not the form's active style.
679 618 *
680 619 * @since 6.0
681 620 *
682 - * @param stdClass|WP_Post $style A new style is not a WP_Post object.
683 - *
621 + * @param WP_Post|stdClass $style A new style is not a WP_Post object.
684 622 * @return void
685 623 */
686 624 private static function force_form_style( $style ) {
687 625 add_filter(
688 626 'frm_add_form_style_class',
689 - function ( $class ) use ( $style ) {
690 - $split = array_filter(
627 + function( $class ) use ( $style ) {
628 + $split = array_filter(
691 629 explode( ' ', $class ),
692 630 /**
693 631 * @param string $class
694 632 */
695 - function ( $class ) {
696 - return $class && ! str_starts_with( $class, 'frm_style_' );
633 + function( $class ) {
634 + return $class && 0 !== strpos( $class, 'frm_style_' );
697 635 }
698 636 );
699 637 $split[] = 'frm_style_' . $style->post_name;
700 638 return implode( ' ', $split );
@@ -709,11 +647,10 @@
709 647 *
710 648 * @return void
711 649 */
712 650 public static function save_style() {
713 - FrmAppHelper::permission_check( 'frm_change_settings' );
714 -
715 651 $frm_style = new FrmStyle();
652 + $message = '';
716 653 $post_id = FrmAppHelper::get_post_param( 'ID', false, 'sanitize_title' );
717 654 $style_nonce = FrmAppHelper::get_post_param( 'frm_style', '', 'sanitize_text_field' );
718 655
719 656 if ( $post_id === false || ! wp_verify_nonce( $style_nonce, 'frm_style_nonce' ) ) {
@@ -722,22 +659,13 @@
722 659 return;
723 660 }
724 661
725 662 $id = $frm_style->update( $post_id );
726 -
727 663 if ( ! $post_id && $id ) {
728 664 self::maybe_redirect_after_save( $id );
729 - // Set the post id to the new style so it will be loaded for editing.
730 - $post_id = reset( $id );
665 + $post_id = reset( $id ); // Set the post id to the new style so it will be loaded for editing.
731 666 }
732 667
733 - /**
734 - * @since 6.25.1
735 - *
736 - * @param int $post_id
737 - */
738 - do_action( 'frm_after_saved_style', absint( $post_id ) );
739 -
740 668 self::$message = __( 'Your styling settings have been saved.', 'formidable' );
741 669 }
742 670
743 671 /**
@@ -756,20 +684,19 @@
756 684 *
757 685 * @since 6.0
758 686 *
759 687 * @param array $ids
760 - *
761 688 * @return void
762 689 */
763 690 private static function maybe_redirect_after_save( $ids ) {
764 - $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' );
765 - $parsed = parse_url( $referer );
766 - $query = $parsed['query'];
691 + $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' );
692 + $parsed = parse_url( $referer );
693 + $query = $parsed['query'];
694 +
767 695 $current_action = false;
768 696 $actions_to_redirect = array( 'duplicate', 'new_style' );
769 -
770 697 foreach ( $actions_to_redirect as $action ) {
771 - if ( str_contains( $query, 'frm_action=' . $action ) ) {
698 + if ( false !== strpos( $query, 'frm_action=' . $action ) ) {
772 699 $current_action = $action;
773 700 break;
774 701 }
775 702 }
@@ -779,9 +706,10 @@
779 706 return;
780 707 }
781 708
782 709 parse_str( $query, $parsed_query );
783 - $form_id = ! empty( $parsed_query['form'] ) ? absint( $parsed_query['form'] ) : 0;
710 + $form_id = ! empty( $parsed_query['form'] ) ? absint( $parsed_query['form'] ) : 0;
711 +
784 712 $style = new stdClass();
785 713 $style->ID = end( $ids );
786 714 wp_safe_redirect( esc_url_raw( FrmStylesHelper::get_edit_url( $style, $form_id ) ) );
787 715 die();
@@ -791,9 +719,8 @@
791 719 * @since 6.0
792 720 *
793 721 * @param string $message
794 722 * @param array|object $forms
795 - *
796 723 * @return void
797 724 */
798 725 public static function manage( $message = '', $forms = array() ) {
799 726 $frm_style = new FrmStyle();
@@ -798,9 +725,8 @@
798 725 public static function manage( $message = '', $forms = array() ) {
799 726 $frm_style = new FrmStyle();
800 727 $styles = $frm_style->get_all();
801 728 $default_style = $frm_style->get_default_style( $styles );
802 - $frm_settings = FrmAppHelper::get_settings();
803 729
804 730 if ( ! $forms ) {
805 731 $forms = FrmForm::get_published_forms();
806 732 }
@@ -817,16 +743,15 @@
817 743 private static function manage_styles() {
818 744 global $wpdb;
819 745
820 746 $forms = FrmForm::get_published_forms();
821 -
822 747 foreach ( $forms as $form ) {
823 - if ( ! isset( $_POST['style'] ) || ! isset( $_POST['style'][ $form->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
748 + $new_style = ( isset( $_POST['style'] ) && isset( $_POST['style'][ $form->id ] ) ) ? sanitize_text_field( wp_unslash( $_POST['style'][ $form->id ] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing
749 + $previous_style = ( isset( $_POST['prev_style'] ) && isset( $_POST['prev_style'][ $form->id ] ) ) ? sanitize_text_field( wp_unslash( $_POST['prev_style'][ $form->id ] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing
750 + if ( $new_style == $previous_style ) {
824 751 continue;
825 752 }
826 753
827 - $new_style = sanitize_text_field( wp_unslash( $_POST['style'][ $form->id ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
828 -
829 754 $form->options['custom_style'] = $new_style;
830 755 $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $form->options ) ), array( 'id' => $form->id ) );
831 756 unset( $form );
832 757 }
@@ -835,28 +760,15 @@
835 760 /**
836 761 * Echo content for the Custom CSS page.
837 762 *
838 763 * @param string $message
839 - * @param array $extra_args An array of extra arguments.
840 - *
841 764 * @return void
842 765 */
843 - public static function custom_css( $message = '', $extra_args = array() ) {
844 - $id = $extra_args['id'] ?? 'frm_codemirror_box';
845 - $settings = self::enqueue_codemirror( $id, $extra_args['placeholder'] ?? '' );
846 - $id = $settings ? $id : 'frm_custom_css_box';
847 - $show_errors = $extra_args['show_errors'] ?? true;
848 - $custom_css = $extra_args['custom_css'] ?? self::get_custom_css();
849 - $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
850 - $textarea_params = ! empty( $extra_args['textarea_params'] ) ? $extra_args['textarea_params'] : array(
851 - 'name' => 'frm_custom_css',
852 - 'id' => $id,
853 - );
766 + public static function custom_css( $message = '' ) {
767 + $settings = self::enqueue_codemirror();
768 + $id = $settings ? 'frm_codemirror_box' : 'frm_custom_css_box';
769 + $custom_css = self::get_custom_css();
854 770
855 - if ( $settings ) {
856 - $textarea_params['class'] = 'hide-if-js';
857 - }
858 -
859 771 include FrmAppHelper::plugin_path() . '/classes/views/styles/custom_css.php';
860 772 }
861 773
862 774 /**
@@ -863,33 +775,22 @@
863 775 * Get custom CSS code entered in the Custom CSS page.
864 776 *
865 777 * @since 6.0
866 778 *
867 - * @param array|null $single_style_settings The single style settings.
868 - *
869 779 * @return string
870 780 */
871 - public static function get_custom_css( $single_style_settings = null ) {
872 - if ( $single_style_settings ) {
873 - // If the single style settings are passed, return the custom CSS from the single style settings.
874 - if ( ! empty( $single_style_settings['single_style_custom_css'] ) && ! empty( $single_style_settings['enable_style_custom_css'] ) ) {
875 - return $single_style_settings['single_style_custom_css'];
876 - }
877 -
878 - return '';
879 - }
880 -
781 + public static function get_custom_css() {
881 782 $settings = FrmAppHelper::get_settings();
882 -
883 783 if ( is_string( $settings->custom_css ) ) {
884 784 return $settings->custom_css;
885 785 }
886 786
887 787 // If it does not exist, check the default style as a fallback.
888 - $frm_style = new FrmStyle();
889 - $style = $frm_style->get_default_style();
788 + $frm_style = new FrmStyle();
789 + $style = $frm_style->get_default_style();
790 + $custom_css = $style->post_content['custom_css'];
890 791
891 - return $style->post_content['custom_css'];
792 + return $custom_css;
892 793 }
893 794
894 795 /**
895 796 * Enqueue assets for codemirror, built into WordPress since 4.9.
@@ -896,14 +797,11 @@
896 797 * The Custom CSS page uses codemirror.
897 798 *
898 799 * @since 6.0 Previously this code was embedded in self::custom_css.
899 800 *
900 - * @param string $id The ID of the codemirror box.
901 - * @param string $placeholder The placeholder text for the codemirror box.
902 - *
903 801 * @return array|false
904 802 */
905 - private static function enqueue_codemirror( $id = 'frm_codemirror_box', $placeholder = '' ) {
803 + private static function enqueue_codemirror() {
906 804 if ( ! function_exists( 'wp_enqueue_code_editor' ) ) {
907 805 // The WordPress version is likely older than 4.9.
908 806 return false;
909 807 }
@@ -916,9 +814,8 @@
916 814 'tabSize' => 2,
917 815 // As the codemirror box only appears once you click into the Custom CSS tab, we need to auto-refresh.
918 816 // Otherwise the line numbers all end up with a 1px width causing overlap issues with the text in the content.
919 817 'autoRefresh' => true,
920 - 'placeholder' => $placeholder,
921 818 ),
922 819 )
923 820 );
924 821
@@ -925,11 +822,9 @@
925 822 if ( $settings ) {
926 823 wp_add_inline_script(
927 824 'code-editor',
928 825 sprintf(
929 - 'jQuery( function() { window.%s_wp_editor = wp.codeEditor.initialize( \'%s\', %s ); } );',
930 - $id,
931 - $id,
826 + 'jQuery( function() { wp.codeEditor.initialize( \'frm_codemirror_box\', %s ); } );',
932 827 wp_json_encode( $settings )
933 828 )
934 829 );
935 830 }
@@ -981,9 +876,8 @@
981 876 FrmAppHelper::permission_check( 'frm_change_settings' );
982 877 check_ajax_referer( 'frm_ajax', 'nonce' );
983 878
984 879 $style_id = FrmAppHelper::get_post_param( 'style_id', '', 'absint' );
985 -
986 880 if ( ! $style_id ) {
987 881 // A style ID is not sent when resetting on the edit page.
988 882 // Instead of resetting the style, send the defaults back so the inputs can be updated with JavaScript.
989 883 $frm_style = new FrmStyle();
@@ -991,26 +885,22 @@
991 885 echo json_encode( $defaults );
992 886 wp_die();
993 887 }
994 888
995 - $frm_style = new FrmStyle();
996 - $default_template_style = $frm_style->get_default_template_style( $style_id );
997 - $where = array(
889 + $frm_style = new FrmStyle();
890 + $defaults = $frm_style->get_defaults();
891 + $default_post_content = FrmAppHelper::prepare_and_encode( $defaults );
892 + $where = array(
998 893 'ID' => $style_id,
999 894 'post_type' => self::$post_type,
1000 895 );
1001 -
1002 - $style_object = $frm_style->get_new();
1003 - $style_object->post_content = json_decode( $default_template_style, true );
1004 -
1005 896 global $wpdb;
1006 - $wpdb->update( $wpdb->posts, array( 'post_content' => $default_template_style ), $where );
897 + $wpdb->update( $wpdb->posts, array( 'post_content' => $default_post_content ), $where );
1007 898
1008 - // Save the settings after resetting to default or the old style will still appear.
1009 - $frm_style->save_settings();
899 + $frm_style->save_settings(); // Save the settings after resetting to default or the old style will still appear.
1010 900
1011 901 $data = array(
1012 - 'style' => FrmStylesCardHelper::get_style_param_for_card( $style_object ),
902 + 'style' => FrmStylesCardHelper::get_style_param_for_card( $frm_style->get_new() ),
1013 903 );
1014 904 wp_send_json_success( $data );
1015 905 wp_die();
1016 906 }
@@ -1025,15 +915,12 @@
1025 915 public static function change_styling() {
1026 916 FrmAppHelper::permission_check( 'frm_change_settings' );
1027 917 check_ajax_referer( 'frm_ajax', 'nonce' );
1028 918
1029 - $is_loaded_via_ajax = true;
1030 - $frm_style = new FrmStyle();
919 + $frm_style = new FrmStyle();
920 + $defaults = false; // Intentionally avoid defaults here so nothing gets removed from our style.
921 + $style = '';
1031 922
1032 - // Intentionally avoid defaults here so nothing gets removed from our style.
1033 - $defaults = array();
1034 - $style = '';
1035 -
1036 923 echo '<style type="text/css">';
1037 924 include FrmAppHelper::plugin_path() . '/css/_single_theme.css.php';
1038 925 echo '</style>';
1039 926 wp_die();
@@ -1042,9 +929,9 @@
1042 929 /**
1043 930 * @return void
1044 931 */
1045 932 public static function add_meta_boxes() {
1046 - // Setup meta boxes
933 + // setup meta boxes
1047 934 $meta_boxes = array(
1048 935 'general' => __( 'General', 'formidable' ),
1049 936 'form-title' => __( 'Form Title', 'formidable' ),
1050 937 'form-description' => __( 'Form Description', 'formidable' ),
@@ -1074,9 +961,8 @@
1074 961
1075 962 /**
1076 963 * @param array $atts
1077 964 * @param array $sec
1078 - *
1079 965 * @return void
1080 966 */
1081 967 public static function include_style_section( $atts, $sec ) {
1082 968 extract( $atts ); // phpcs:ignore WordPress.PHP.DontExtract
@@ -1131,37 +1017,17 @@
1131 1017 */
1132 1018 $output = apply_filters( 'frm_saved_css', $output );
1133 1019
1134 1020 echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1135 -
1136 - self::maybe_hide_sample_form_error_message();
1137 -
1138 1021 wp_die();
1139 1022 }
1140 1023
1141 1024 /**
1142 - * Add an extra style rule to hide a broken style warning.
1143 - * To avoid cluttering the front end with any unnecessary styles this is only added when the referer URL matches the styler.
1144 - *
1145 - * @since 6.2.3
1146 - *
1147 - * @return void
1148 - */
1149 - public static function maybe_hide_sample_form_error_message() {
1150 - $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' );
1151 -
1152 - if ( str_contains( $referer, 'admin.php?page=formidable-styles' ) ) {
1153 - echo '#frm_broken_styles_warning { display: none; }';
1154 - }
1155 - }
1156 -
1157 - /**
1158 1025 * Replaces relative URL with absolute URL.
1159 1026 *
1160 1027 * @since 4.11.03
1161 1028 *
1162 1029 * @param string $css CSS content.
1163 - *
1164 1030 * @return string
1165 1031 */
1166 1032 public static function replace_relative_url( $css ) {
1167 1033 $plugin_url = trailingslashit( FrmAppHelper::plugin_url() );
@@ -1184,27 +1050,22 @@
1184 1050 * Check if the Formidable styling should be loaded,
1185 1051 * then enqueue it for the footer
1186 1052 *
1187 1053 * @since 2.0
1188 - *
1189 - * @return void
1190 1054 */
1191 1055 public static function enqueue_style() {
1192 1056 global $frm_vars;
1193 1057
1194 - if ( ! empty( $frm_vars['css_loaded'] ) ) {
1058 + if ( isset( $frm_vars['css_loaded'] ) && $frm_vars['css_loaded'] ) {
1195 1059 // The CSS has already been loaded.
1196 1060 return;
1197 1061 }
1198 1062
1199 1063 $frm_settings = FrmAppHelper::get_settings();
1200 -
1201 - if ( $frm_settings->load_style === 'none' ) {
1202 - return;
1064 + if ( $frm_settings->load_style != 'none' ) {
1065 + wp_enqueue_style( 'formidable' );
1066 + $frm_vars['css_loaded'] = true;
1203 1067 }
1204 -
1205 - wp_enqueue_style( 'formidable' );
1206 - $frm_vars['css_loaded'] = true;
1207 1068 }
1208 1069
1209 1070 /**
1210 1071 * Get the stylesheets for the form settings page
@@ -1212,23 +1073,23 @@
1212 1073 * @return array<WP_Post>
1213 1074 */
1214 1075 public static function get_style_opts() {
1215 1076 $frm_style = new FrmStyle();
1216 - return $frm_style->get_all();
1077 + $styles = $frm_style->get_all();
1078 +
1079 + return $styles;
1217 1080 }
1218 1081
1219 1082 /**
1220 1083 * Get the style post object for a target form.
1221 1084 *
1222 - * @param bool|object|string $form
1223 - *
1085 + * @param object|string|boolean $form
1224 1086 * @return WP_Post|null
1225 1087 */
1226 1088 public static function get_form_style( $form = 'default' ) {
1227 1089 $style = FrmFormsHelper::get_form_style( $form );
1228 1090
1229 - // phpcs:ignore Universal.Operators.StrictComparisons
1230 - if ( ! $style || 1 == $style ) {
1091 + if ( empty( $style ) || 1 == $style ) {
1231 1092 $style = 'default';
1232 1093 }
1233 1094
1234 1095 $frm_style = new FrmStyle( $style );
@@ -1237,13 +1098,10 @@
1237 1098
1238 1099 /**
1239 1100 * @param string $class
1240 1101 * @param string $style
1241 - *
1242 - * @return string
1243 1102 */
1244 1103 public static function get_form_style_class( $class, $style ) {
1245 - // phpcs:ignore Universal.Operators.StrictComparisons
1246 1104 if ( 1 == $style ) {
1247 1105 $style = 'default';
1248 1106 }
1249 1107
@@ -1258,18 +1116,15 @@
1258 1116 return $class;
1259 1117 }
1260 1118
1261 1119 /**
1262 - * @since 3.0
1263 - *
1264 1120 * @param object $style
1265 1121 * @param string $class
1266 1122 *
1267 - * @return void
1123 + * @since 3.0
1268 1124 */
1269 1125 private static function maybe_add_rtl_class( $style, &$class ) {
1270 1126 $is_rtl = isset( $style->post_content['direction'] ) && 'rtl' === $style->post_content['direction'];
1271 -
1272 1127 if ( $is_rtl ) {
1273 1128 $class .= ' frm_rtl';
1274 1129 }
1275 1130 }
@@ -1274,28 +1129,17 @@
1274 1129 }
1275 1130 }
1276 1131
1277 1132 /**
1278 - * @param string $val Style setting key.
1279 - * @param int|string $form Form ID or 'default'.
1280 - *
1281 - * @return mixed
1133 + * @param string $val
1282 1134 */
1283 1135 public static function get_style_val( $val, $form = 'default' ) {
1284 1136 $style = self::get_form_style( $form );
1285 -
1286 1137 if ( $style && isset( $style->post_content[ $val ] ) ) {
1287 1138 return $style->post_content[ $val ];
1288 1139 }
1289 -
1290 - return null;
1291 1140 }
1292 1141
1293 - /**
1294 - * @param array $default_styles
1295 - *
1296 - * @return array
1297 - */
1298 1142 public static function show_entry_styles( $default_styles ) {
1299 1143 $frm_style = new FrmStyle( 'default' );
1300 1144 $style = $frm_style->get_one();
1301 1145
@@ -1304,15 +1148,13 @@
1304 1148 }
1305 1149
1306 1150 foreach ( $default_styles as $name => $val ) {
1307 1151 $setting = $name;
1308 -
1309 - if ( 'border_width' === $name ) {
1152 + if ( 'border_width' == $name ) {
1310 1153 $setting = 'field_border_width';
1311 - } elseif ( 'alt_bg_color' === $name ) {
1154 + } elseif ( 'alt_bg_color' == $name ) {
1312 1155 $setting = 'bg_color_active';
1313 1156 }
1314 -
1315 1157 $default_styles[ $name ] = $style->post_content[ $setting ];
1316 1158 unset( $name, $val );
1317 1159 }
1318 1160
@@ -1318,104 +1160,16 @@
1318 1160
1319 1161 return $default_styles;
1320 1162 }
1321 1163
1322 - /**
1323 - * @param string $important
1324 - * @param array $field
1325 - *
1326 - * @return string
1327 - */
1328 - public static function important_style( $important, $field ) {
1329 - return self::get_style_val( 'important_style', $field['form_id'] );
1164 + public static function &important_style( $important, $field ) {
1165 + $important = self::get_style_val( 'important_style', $field['form_id'] );
1166 +
1167 + return $important;
1330 1168 }
1331 1169
1332 - /**
1333 - * Duplicate of WordPress do_accordion_section function, it adds an additional svg icon support.
1334 - *
1335 - * @since 6.8.3
1336 - *
1337 - * @param string|WP_Screen $screen Screen ID or screen object.
1338 - * @param string $context Meta box context.
1339 - * @param mixed $data_object Data object passed to callbacks.
1340 - *
1341 - * @return int
1342 - */
1343 - public static function do_accordion_sections( $screen, $context, $data_object ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh
1344 - global $wp_meta_boxes;
1345 -
1346 - // The symbol id from icons.svg
1347 - $icon_ids = array(
1348 - 'ranking-fields-style' => 'frm_chart_bar_icon',
1349 - 'section-fields-style' => 'frm-form-title-style',
1350 - );
1351 -
1352 - wp_enqueue_script( 'accordion' );
1353 -
1354 - if ( ! $screen ) {
1355 - $screen = get_current_screen();
1356 - } elseif ( is_string( $screen ) ) {
1357 - $screen = convert_to_screen( $screen );
1358 - }
1359 -
1360 - $page = $screen->id;
1361 -
1362 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
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 - continue;
1374 - }
1375 -
1376 - foreach ( $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) {
1377 - if ( false === $box || ! $box['title'] ) {
1378 - continue;
1379 - }
1380 -
1381 - ++$i;
1382 - $icon_id = array_key_exists( $box['id'], $icon_ids ) ? $icon_ids[ $box['id'] ] : 'frm-' . $box['id'];
1383 - $open_class = '';
1384 -
1385 - if ( ! $first_open ) {
1386 - $first_open = true;
1387 - $open_class = 'open';
1388 - }
1389 -
1390 - $accordion_content_id = 'frm_style_section_' . $box['id'];
1391 - ?>
1392 - <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 ?>
1393 - <h3 class="accordion-section-title hndle">
1394 - <?php
1395 - FrmAppHelper::icon_by_class( 'frmfont ' . $icon_id . ' frm_svg24' );
1396 - echo esc_html( $box['title'] );
1397 - ?>
1398 - <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 ?>
1399 - <?php FrmAppHelper::icon_by_class( 'frmfont frm_arrowdown8_icon' ); ?>
1400 - </button>
1401 - </h3>
1402 - <div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>" id="<?php echo esc_attr( $accordion_content_id ); ?>">
1403 - <div class="inside">
1404 - <?php call_user_func( $box['callback'], $data_object, $box ); ?>
1405 - </div><!-- .inside -->
1406 - </div><!-- .accordion-section-content -->
1407 - </li><!-- .accordion-section -->
1408 - <?php
1409 - }//end foreach
1410 - }//end foreach
1411 - }//end if
1412 - ?>
1413 - </ul><!-- .outer-border -->
1414 - </div><!-- .accordion-container -->
1415 - <?php
1416 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
1417 - return $i;
1170 + public static function do_accordion_sections( $screen, $context, $object ) {
1171 + return do_accordion_sections( $screen, $context, $object );
1418 1172 }
1419 1173
1420 1174 /**
1421 1175 * Rename a style via an AJAX action.
@@ -1425,9 +1179,8 @@
1425 1179 * @return void
1426 1180 */
1427 1181 public static function rename_style() {
1428 1182 $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'nonce', 'frm_ajax' );
1429 -
1430 1183 if ( $permission_error !== false ) {
1431 1184 $data = array(
1432 1185 'message' => __( 'Unable to rename style', 'formidable' ),
1433 1186 );
@@ -1446,9 +1199,8 @@
1446 1199 die();
1447 1200 }
1448 1201
1449 1202 $post = get_post( $style_id );
1450 -
1451 1203 if ( ! $post || $post->post_type !== self::$post_type ) {
1452 1204 $data = array(
1453 1205 'message' => __( 'The style you are renaming either does not exist or it is not a style', 'formidable' ),
1454 1206 );
@@ -1469,9 +1221,8 @@
1469 1221 *
1470 1222 * @since 6.0
1471 1223 *
1472 1224 * @param WP_Styles $styles
1473 - *
1474 1225 * @return void
1475 1226 */
1476 1227 public static function disable_conflicting_wp_admin_css( $styles ) {
1477 1228 if ( ! FrmAppHelper::is_style_editor_page() ) {
@@ -1481,12 +1232,12 @@
1481 1232 FrmStylesPreviewHelper::disable_conflicting_wp_admin_css( $styles );
1482 1233 }
1483 1234
1484 1235 /**
1485 - * @deprecated 6.1 Saving custom CSS has been moved into Global Settings.
1236 + * @deprecated x.x Saving custom CSS has been moved into Global Settings.
1486 1237 *
1487 1238 * @return void
1488 1239 */
1489 1240 public static function save_css() {
1490 - _deprecated_function( __METHOD__, '6.1' );
1241 + _deprecated_function( __METHOD__, 'x.x' );
1491 1242 }
1492 1243 }