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