| @@ -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( |
| @@ -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,9 +131,8 @@ | ||
| 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 | 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 | } |
| @@ -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,14 +223,12 @@ | ||
| 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' ); |
| @@ -251,10 +239,8 @@ | ||
| 251 | 239 | /** |
| 252 | 240 | * Use a different stylesheet per site in a multisite install |
| 253 | 241 | * |
| 254 | 242 | * @since 3.0.03 |
| 255 | - * | |
| 256 | - * @return string | |
| 257 | 243 | */ |
| 258 | 244 | public static function get_file_name() { |
| 259 | 245 | if ( is_multisite() ) { |
| 260 | 246 | $blog_id = get_current_blog_id(); |
| @@ -265,18 +251,11 @@ | ||
| 265 | 251 | |
| 266 | 252 | return $name; |
| 267 | 253 | } |
| 268 | 254 | |
| 269 | - /** | |
| 270 | - * @param string $css_key | |
| 271 | - * @param string $version | |
| 272 | - * | |
| 273 | - * @return string | |
| 274 | - */ | |
| 275 | 255 | private static function get_css_version( $css_key, $version ) { |
| 276 | - if ( 'formidable' === $css_key ) { | |
| 256 | + if ( 'formidable' == $css_key ) { | |
| 277 | 257 | $this_version = get_option( 'frm_last_style_update' ); |
| 278 | - | |
| 279 | 258 | if ( ! $this_version ) { |
| 280 | 259 | $this_version = $version; |
| 281 | 260 | } |
| 282 | 261 | } else { |
| @@ -285,18 +264,14 @@ | ||
| 285 | 264 | |
| 286 | 265 | return $this_version; |
| 287 | 266 | } |
| 288 | 267 | |
| 289 | - /** | |
| 290 | - * @param string $tag | |
| 291 | - * @param string $handle | |
| 292 | - * | |
| 293 | - * @return string | |
| 294 | - */ | |
| 295 | 268 | public static function add_tags_to_css( $tag, $handle ) { |
| 296 | - if ( ( 'formidable' === $handle || 'jquery-theme' === $handle ) && strpos( $tag, ' property=' ) === false ) { | |
| 269 | + if ( ( 'formidable' == $handle || 'jquery-theme' == $handle ) && strpos( $tag, ' property=' ) === false ) { | |
| 297 | 270 | $frm_settings = FrmAppHelper::get_settings(); |
| 298 | - $tag = str_replace( ' type="', ' property="stylesheet" type="', $tag ); | |
| 271 | + if ( $frm_settings->use_html ) { | |
| 272 | + $tag = str_replace( ' type="', ' property="stylesheet" type="', $tag ); | |
| 273 | + } | |
| 299 | 274 | } |
| 300 | 275 | |
| 301 | 276 | return $tag; |
| 302 | 277 | } |
| @@ -344,35 +319,20 @@ | ||
| 344 | 319 | |
| 345 | 320 | self::setup_styles_and_scripts_for_styler(); |
| 346 | 321 | |
| 347 | 322 | $style_id = self::get_style_id_for_styler(); |
| 348 | - | |
| 349 | 323 | if ( ! $style_id ) { |
| 350 | - $error_args = array( | |
| 351 | - 'title' => __( 'No styles', 'formidable' ), | |
| 352 | - 'body' => __( 'You must have a style to use the Visual Styler.', 'formidable' ), | |
| 353 | - 'cancel_url' => admin_url( 'admin.php?page=formidable' ), | |
| 354 | - ); | |
| 355 | - FrmAppController::show_error_modal( $error_args ); | |
| 356 | - return; | |
| 324 | + wp_die( esc_html__( 'Invalid route', 'formidable' ), esc_html__( 'Invalid route', 'formidable' ), 400 ); | |
| 357 | 325 | } |
| 358 | 326 | |
| 359 | 327 | $form_id = FrmAppHelper::simple_get( 'form', 'absint', 0 ); |
| 360 | - | |
| 361 | 328 | if ( ! $form_id ) { |
| 362 | 329 | $form_id = self::get_form_id_for_style( $style_id ); |
| 363 | 330 | } |
| 364 | 331 | |
| 365 | 332 | $form = FrmForm::getOne( $form_id ); |
| 366 | - | |
| 367 | 333 | if ( ! is_object( $form ) ) { |
| 368 | - $error_args = array( | |
| 369 | - 'title' => __( 'No forms', 'formidable' ), | |
| 370 | - 'body' => __( 'You must have a form to use the Visual Styler.', 'formidable' ), | |
| 371 | - 'cancel_url' => admin_url( 'admin.php?page=formidable' ), | |
| 372 | - ); | |
| 373 | - FrmAppController::show_error_modal( $error_args ); | |
| 374 | - return; | |
| 334 | + wp_die( esc_html__( 'Invalid route', 'formidable' ), esc_html__( 'Invalid route', 'formidable' ), 400 ); | |
| 375 | 335 | } |
| 376 | 336 | |
| 377 | 337 | $frm_style = new FrmStyle( $style_id ); |
| 378 | 338 | $active_style = $frm_style->get_one(); |
| @@ -382,9 +342,11 @@ | ||
| 382 | 342 | |
| 383 | 343 | /** |
| 384 | 344 | * @since 6.0 |
| 385 | 345 | * |
| 386 | - * @param array{form:\stdClass} $data | |
| 346 | + * @param array { | |
| 347 | + * @type stdClass $form | |
| 348 | + * } | |
| 387 | 349 | */ |
| 388 | 350 | do_action( 'frm_before_render_style_page', compact( 'form' ) ); |
| 389 | 351 | |
| 390 | 352 | self::render_style_page( $active_style, $form, $default_style ); |
| @@ -396,9 +358,8 @@ | ||
| 396 | 358 | * @return int |
| 397 | 359 | */ |
| 398 | 360 | private static function get_style_id_for_styler() { |
| 399 | 361 | $action = FrmAppHelper::simple_get( 'frm_action' ); |
| 400 | - | |
| 401 | 362 | if ( 'duplicate' === $action ) { |
| 402 | 363 | // The duplicate action uses style_id instead of id for better backward compatibility. |
| 403 | 364 | return FrmAppHelper::simple_get( 'style_id', 'absint', 0 ); |
| 404 | 365 | } |
| @@ -403,9 +364,8 @@ | ||
| 403 | 364 | return FrmAppHelper::simple_get( 'style_id', 'absint', 0 ); |
| 404 | 365 | } |
| 405 | 366 | |
| 406 | 367 | $style_id = FrmAppHelper::simple_get( 'id', 'absint', 0 ); |
| 407 | - | |
| 408 | 368 | if ( $style_id ) { |
| 409 | 369 | // Always use the style ID from the URL if one is specified. |
| 410 | 370 | return $style_id; |
| 411 | 371 | } |
| @@ -410,9 +370,8 @@ | ||
| 410 | 370 | return $style_id; |
| 411 | 371 | } |
| 412 | 372 | |
| 413 | 373 | $request_form_id = FrmAppHelper::simple_get( 'form', 'absint', 0 ); |
| 414 | - | |
| 415 | 374 | if ( $request_form_id && is_callable( 'FrmProStylesController::get_active_style_for_form' ) ) { |
| 416 | 375 | return FrmProStylesController::get_active_style_for_form( $request_form_id )->ID; |
| 417 | 376 | } |
| 418 | 377 | |
| @@ -424,9 +383,8 @@ | ||
| 424 | 383 | * |
| 425 | 384 | * @since 6.0 |
| 426 | 385 | * |
| 427 | 386 | * @param int $style_id |
| 428 | - * | |
| 429 | 387 | * @return int |
| 430 | 388 | */ |
| 431 | 389 | private static function get_form_id_for_style( $style_id ) { |
| 432 | 390 | $check = serialize( array( 'custom_style' => (string) $style_id ) ); |
| @@ -441,12 +399,11 @@ | ||
| 441 | 399 | |
| 442 | 400 | if ( ! $form_id ) { |
| 443 | 401 | // TODO: Show a message why a random form is being shown (because no form is assigned to the style). |
| 444 | 402 | // Fallback to any form. |
| 445 | - $where = array( | |
| 403 | + $where = array( | |
| 446 | 404 | 'status' => 'published', |
| 447 | - // Make sure it's not a repeater. | |
| 448 | - 'parent_form_id' => array( null, 0 ), | |
| 405 | + 'parent_form_id' => array( null, 0 ), // Make sure it's not a repeater. | |
| 449 | 406 | ); |
| 450 | 407 | $form_id = FrmDb::get_var( 'frm_forms', $where, 'id' ); |
| 451 | 408 | } |
| 452 | 409 | |
| @@ -460,9 +417,9 @@ | ||
| 460 | 417 | */ |
| 461 | 418 | private static function disable_admin_page_styling_on_submit_buttons() { |
| 462 | 419 | add_filter( |
| 463 | 420 | 'frm_submit_button_class', |
| 464 | - function ( $classes ) { | |
| 421 | + function( $classes ) { | |
| 465 | 422 | $classes[] = 'frm_no_style_button'; |
| 466 | 423 | return $classes; |
| 467 | 424 | } |
| 468 | 425 | ); |
| @@ -487,15 +444,13 @@ | ||
| 487 | 444 | * @return void |
| 488 | 445 | */ |
| 489 | 446 | private static function save_form_style() { |
| 490 | 447 | $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'frm_save_form_style', 'frm_save_form_style_nonce' ); |
| 491 | - | |
| 492 | 448 | if ( $permission_error !== false ) { |
| 493 | 449 | wp_die( 'Unable to save form', '', 403 ); |
| 494 | 450 | } |
| 495 | 451 | |
| 496 | 452 | $style_id = FrmAppHelper::get_post_param( 'style_id', 0, 'absint' ); |
| 497 | - | |
| 498 | 453 | if ( $style_id && ! self::confirm_style_exists_before_setting( $style_id ) ) { |
| 499 | 454 | wp_die( esc_html__( 'Invalid target style', 'formidable' ), esc_html__( 'Invalid target style', 'formidable' ), 400 ); |
| 500 | 455 | return; |
| 501 | 456 | } |
| @@ -508,16 +463,15 @@ | ||
| 508 | 463 | * @param int $style_id |
| 509 | 464 | */ |
| 510 | 465 | $style_id = apply_filters( 'frm_saved_form_style_id', $style_id ); |
| 511 | 466 | |
| 512 | - 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', '' ) ) { | |
| 513 | 468 | // "0" is a special value used for the enable/disable toggle. |
| 514 | 469 | wp_die( esc_html__( 'Invalid style value', 'formidable' ), esc_html__( 'Invalid style value', 'formidable' ), 400 ); |
| 515 | 470 | return; |
| 516 | 471 | } |
| 517 | 472 | |
| 518 | - $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' ); | |
| 519 | - | |
| 473 | + $form_id = FrmAppHelper::get_post_param( 'form_id', 'absint', 0 ); | |
| 520 | 474 | if ( ! $form_id ) { |
| 521 | 475 | wp_die( esc_html__( 'No form specified', 'formidable' ), esc_html__( 'No form specified', 'formidable' ), 400 ); |
| 522 | 476 | return; |
| 523 | 477 | } |
| @@ -522,47 +476,28 @@ | ||
| 522 | 476 | return; |
| 523 | 477 | } |
| 524 | 478 | |
| 525 | 479 | $form = FrmForm::getOne( $form_id ); |
| 526 | - | |
| 527 | 480 | if ( ! $form ) { |
| 528 | 481 | wp_die( esc_html__( 'Form does not exist', 'formidable' ), esc_html__( 'Form does not exist', 'formidable' ), 400 ); |
| 529 | 482 | return; |
| 530 | 483 | } |
| 531 | 484 | |
| 532 | - $previous_style_id = $form->options['custom_style']; | |
| 533 | - | |
| 534 | 485 | // If the default style is selected, use the "Always use default" legacy option instead of the default style. |
| 535 | 486 | // There's also a check here for conversational forms. |
| 536 | 487 | // Without the check it isn't possible to select "Default" because "Always use default" will convert to "Lines" dynamically. |
| 537 | 488 | $default_style = self::get_default_style(); |
| 538 | - | |
| 539 | 489 | if ( $style_id === $default_style->ID && empty( $form->options['chat'] ) ) { |
| 540 | 490 | $style_id = 1; |
| 541 | 491 | } |
| 542 | 492 | |
| 543 | - // We want to save a string for consistency. FrmStylesHelper::get_form_count_for_style expects the custom style ID is a string. | |
| 544 | - $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. | |
| 545 | 494 | |
| 546 | - if ( $previous_style_id === $form->options['custom_style'] ) { | |
| 547 | - // Exit early before updating DB if nothing actually changed. | |
| 548 | - self::$message = __( 'Successfully updated style.', 'formidable' ); | |
| 549 | - return; | |
| 550 | - } | |
| 551 | - | |
| 552 | 495 | global $wpdb; |
| 553 | 496 | $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $form->options ) ), array( 'id' => $form->id ) ); |
| 554 | 497 | |
| 555 | 498 | FrmForm::clear_form_cache(); |
| 556 | 499 | |
| 557 | - /** | |
| 558 | - * @since 6.25.1 | |
| 559 | - * | |
| 560 | - * @param int $form_id | |
| 561 | - * @param int $style_id | |
| 562 | - */ | |
| 563 | - do_action( 'frm_after_changed_form_style', absint( $form_id ), absint( $style_id ) ); | |
| 564 | - | |
| 565 | 500 | self::$message = __( 'Successfully updated style.', 'formidable' ); |
| 566 | 501 | } |
| 567 | 502 | |
| 568 | 503 | /** |
| @@ -568,9 +503,8 @@ | ||
| 568 | 503 | /** |
| 569 | 504 | * Validate that we're assigning a form to a style that actually exists before assigning it to a form. |
| 570 | 505 | * |
| 571 | 506 | * @param int $style_id |
| 572 | - * | |
| 573 | 507 | * @return bool True if the style actually exists. |
| 574 | 508 | */ |
| 575 | 509 | private static function confirm_style_exists_before_setting( $style_id ) { |
| 576 | 510 | global $wpdb; |
| @@ -589,9 +523,9 @@ | ||
| 589 | 523 | $plugin_url = FrmAppHelper::plugin_url(); |
| 590 | 524 | $version = FrmAppHelper::plugin_version(); |
| 591 | 525 | $js_dependencies = array( 'wp-i18n', 'wp-hooks', 'formidable_dom' ); |
| 592 | 526 | |
| 593 | - if ( FrmAppHelper::pro_is_installed() && is_callable( 'FrmProAppHelper::use_jquery_datepicker' ) && FrmProAppHelper::use_jquery_datepicker() ) { | |
| 527 | + if ( FrmAppHelper::pro_is_installed() ) { | |
| 594 | 528 | $js_dependencies[] = 'jquery-ui-datepicker'; |
| 595 | 529 | } |
| 596 | 530 | |
| 597 | 531 | wp_register_script( 'formidable_style', $plugin_url . '/js/admin/style.js', $js_dependencies, $version ); |
| @@ -599,9 +533,8 @@ | ||
| 599 | 533 | wp_print_styles( 'formidable_style' ); |
| 600 | 534 | |
| 601 | 535 | wp_print_styles( 'formidable' ); |
| 602 | 536 | wp_enqueue_script( 'formidable_style' ); |
| 603 | - wp_set_script_translations( 'formidable_style', 'formidable' ); | |
| 604 | 537 | } |
| 605 | 538 | |
| 606 | 539 | /** |
| 607 | 540 | * Render the style page (with a more limited and typed scope than calling it from self::style directly). |
| @@ -608,22 +541,20 @@ | ||
| 608 | 541 | * |
| 609 | 542 | * @since 6.0 |
| 610 | 543 | * |
| 611 | 544 | * @param stdClass|WP_Post $active_style |
| 545 | + * @param array<WP_Post> $styles | |
| 612 | 546 | * @param stdClass $form |
| 613 | 547 | * @param WP_Post $default_style |
| 614 | - * | |
| 615 | 548 | * @return void |
| 616 | 549 | */ |
| 617 | 550 | private static function render_style_page( $active_style, $form, $default_style ) { |
| 618 | 551 | $style_views_path = self::get_views_path(); |
| 619 | - // Edit, list (default), new_style. | |
| 620 | - $view = FrmAppHelper::simple_get( 'frm_action', 'sanitize_text_field', 'list' ); | |
| 621 | - $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 ); | |
| 622 | 554 | |
| 623 | 555 | if ( 'new_style' !== $view && ! FrmAppHelper::simple_get( 'form' ) && ! FrmAppHelper::simple_get( 'style_id' ) ) { |
| 624 | - // Have the Appearance > Forms link fallback to the edit view. Otherwise we want to use 'list' as the default. | |
| 625 | - $view = 'edit'; | |
| 556 | + $view = 'edit'; // Have the Appearance > Forms link fallback to the edit view. Otherwise we want to use 'list' as the default. | |
| 626 | 557 | } |
| 627 | 558 | |
| 628 | 559 | if ( in_array( $view, array( 'edit', 'new_style', 'duplicate' ), true ) ) { |
| 629 | 560 | self::add_meta_boxes(); |
| @@ -686,22 +617,21 @@ | ||
| 686 | 617 | * Filter form classes so the form uses the preview style, not the form's active style. |
| 687 | 618 | * |
| 688 | 619 | * @since 6.0 |
| 689 | 620 | * |
| 690 | - * @param stdClass|WP_Post $style A new style is not a WP_Post object. | |
| 691 | - * | |
| 621 | + * @param WP_Post|stdClass $style A new style is not a WP_Post object. | |
| 692 | 622 | * @return void |
| 693 | 623 | */ |
| 694 | 624 | private static function force_form_style( $style ) { |
| 695 | 625 | add_filter( |
| 696 | 626 | 'frm_add_form_style_class', |
| 697 | - function ( $class ) use ( $style ) { | |
| 698 | - $split = array_filter( | |
| 627 | + function( $class ) use ( $style ) { | |
| 628 | + $split = array_filter( | |
| 699 | 629 | explode( ' ', $class ), |
| 700 | 630 | /** |
| 701 | 631 | * @param string $class |
| 702 | 632 | */ |
| 703 | - function ( $class ) { | |
| 633 | + function( $class ) { | |
| 704 | 634 | return $class && 0 !== strpos( $class, 'frm_style_' ); |
| 705 | 635 | } |
| 706 | 636 | ); |
| 707 | 637 | $split[] = 'frm_style_' . $style->post_name; |
| @@ -718,8 +648,9 @@ | ||
| 718 | 648 | * @return void |
| 719 | 649 | */ |
| 720 | 650 | public static function save_style() { |
| 721 | 651 | $frm_style = new FrmStyle(); |
| 652 | + $message = ''; | |
| 722 | 653 | $post_id = FrmAppHelper::get_post_param( 'ID', false, 'sanitize_title' ); |
| 723 | 654 | $style_nonce = FrmAppHelper::get_post_param( 'frm_style', '', 'sanitize_text_field' ); |
| 724 | 655 | |
| 725 | 656 | if ( $post_id === false || ! wp_verify_nonce( $style_nonce, 'frm_style_nonce' ) ) { |
| @@ -728,22 +659,13 @@ | ||
| 728 | 659 | return; |
| 729 | 660 | } |
| 730 | 661 | |
| 731 | 662 | $id = $frm_style->update( $post_id ); |
| 732 | - | |
| 733 | 663 | if ( ! $post_id && $id ) { |
| 734 | 664 | self::maybe_redirect_after_save( $id ); |
| 735 | - // Set the post id to the new style so it will be loaded for editing. | |
| 736 | - $post_id = reset( $id ); | |
| 665 | + $post_id = reset( $id ); // Set the post id to the new style so it will be loaded for editing. | |
| 737 | 666 | } |
| 738 | 667 | |
| 739 | - /** | |
| 740 | - * @since 6.25.1 | |
| 741 | - * | |
| 742 | - * @param int $post_id | |
| 743 | - */ | |
| 744 | - do_action( 'frm_after_saved_style', absint( $post_id ) ); | |
| 745 | - | |
| 746 | 668 | self::$message = __( 'Your styling settings have been saved.', 'formidable' ); |
| 747 | 669 | } |
| 748 | 670 | |
| 749 | 671 | /** |
| @@ -762,9 +684,8 @@ | ||
| 762 | 684 | * |
| 763 | 685 | * @since 6.0 |
| 764 | 686 | * |
| 765 | 687 | * @param array $ids |
| 766 | - * | |
| 767 | 688 | * @return void |
| 768 | 689 | */ |
| 769 | 690 | private static function maybe_redirect_after_save( $ids ) { |
| 770 | 691 | $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' ); |
| @@ -772,9 +693,8 @@ | ||
| 772 | 693 | $query = $parsed['query']; |
| 773 | 694 | |
| 774 | 695 | $current_action = false; |
| 775 | 696 | $actions_to_redirect = array( 'duplicate', 'new_style' ); |
| 776 | - | |
| 777 | 697 | foreach ( $actions_to_redirect as $action ) { |
| 778 | 698 | if ( false !== strpos( $query, 'frm_action=' . $action ) ) { |
| 779 | 699 | $current_action = $action; |
| 780 | 700 | break; |
| @@ -786,9 +706,9 @@ | ||
| 786 | 706 | return; |
| 787 | 707 | } |
| 788 | 708 | |
| 789 | 709 | parse_str( $query, $parsed_query ); |
| 790 | - $form_id = ! empty( $parsed_query['form'] ) ? absint( $parsed_query['form'] ) : 0; | |
| 710 | + $form_id = ! empty( $parsed_query['form'] ) ? absint( $parsed_query['form'] ) : 0; | |
| 791 | 711 | |
| 792 | 712 | $style = new stdClass(); |
| 793 | 713 | $style->ID = end( $ids ); |
| 794 | 714 | wp_safe_redirect( esc_url_raw( FrmStylesHelper::get_edit_url( $style, $form_id ) ) ); |
| @@ -799,9 +719,8 @@ | ||
| 799 | 719 | * @since 6.0 |
| 800 | 720 | * |
| 801 | 721 | * @param string $message |
| 802 | 722 | * @param array|object $forms |
| 803 | - * | |
| 804 | 723 | * @return void |
| 805 | 724 | */ |
| 806 | 725 | public static function manage( $message = '', $forms = array() ) { |
| 807 | 726 | $frm_style = new FrmStyle(); |
| @@ -806,9 +725,8 @@ | ||
| 806 | 725 | public static function manage( $message = '', $forms = array() ) { |
| 807 | 726 | $frm_style = new FrmStyle(); |
| 808 | 727 | $styles = $frm_style->get_all(); |
| 809 | 728 | $default_style = $frm_style->get_default_style( $styles ); |
| 810 | - $frm_settings = FrmAppHelper::get_settings(); | |
| 811 | 729 | |
| 812 | 730 | if ( ! $forms ) { |
| 813 | 731 | $forms = FrmForm::get_published_forms(); |
| 814 | 732 | } |
| @@ -825,16 +743,15 @@ | ||
| 825 | 743 | private static function manage_styles() { |
| 826 | 744 | global $wpdb; |
| 827 | 745 | |
| 828 | 746 | $forms = FrmForm::get_published_forms(); |
| 829 | - | |
| 830 | 747 | foreach ( $forms as $form ) { |
| 831 | - 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 ) { | |
| 832 | 751 | continue; |
| 833 | 752 | } |
| 834 | 753 | |
| 835 | - $new_style = sanitize_text_field( wp_unslash( $_POST['style'][ $form->id ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 836 | - | |
| 837 | 754 | $form->options['custom_style'] = $new_style; |
| 838 | 755 | $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $form->options ) ), array( 'id' => $form->id ) ); |
| 839 | 756 | unset( $form ); |
| 840 | 757 | } |
| @@ -843,27 +760,15 @@ | ||
| 843 | 760 | /** |
| 844 | 761 | * Echo content for the Custom CSS page. |
| 845 | 762 | * |
| 846 | 763 | * @param string $message |
| 847 | - * @param array $extra_args An array of extra arguments. | |
| 848 | - * | |
| 849 | 764 | * @return void |
| 850 | 765 | */ |
| 851 | - public static function custom_css( $message = '', $extra_args = array() ) { | |
| 852 | - $id = $extra_args['id'] ?? 'frm_codemirror_box'; | |
| 853 | - $settings = self::enqueue_codemirror( $id, $extra_args['placeholder'] ?? '' ); | |
| 854 | - $id = $settings ? $id : 'frm_custom_css_box'; | |
| 855 | - $show_errors = $extra_args['show_errors'] ?? true; | |
| 856 | - $custom_css = $extra_args['custom_css'] ?? self::get_custom_css(); | |
| 857 | - $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' ); | |
| 858 | - $textarea_params = ! empty( $extra_args['textarea_params'] ) ? $extra_args['textarea_params'] : array( | |
| 859 | - 'name' => 'frm_custom_css', | |
| 860 | - 'id' => $id, | |
| 861 | - ); | |
| 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(); | |
| 862 | 770 | |
| 863 | - if ( ! empty( $settings ) ) { | |
| 864 | - $textarea_params['class'] = 'hide-if-js'; | |
| 865 | - } | |
| 866 | 771 | include FrmAppHelper::plugin_path() . '/classes/views/styles/custom_css.php'; |
| 867 | 772 | } |
| 868 | 773 | |
| 869 | 774 | /** |
| @@ -870,20 +775,12 @@ | ||
| 870 | 775 | * Get custom CSS code entered in the Custom CSS page. |
| 871 | 776 | * |
| 872 | 777 | * @since 6.0 |
| 873 | 778 | * |
| 874 | - * @param array|null $single_style_settings The single style settings. | |
| 875 | - * | |
| 876 | 779 | * @return string |
| 877 | 780 | */ |
| 878 | - public static function get_custom_css( $single_style_settings = null ) { | |
| 879 | - // If the single style settings are passed, return the custom CSS from the single style settings. | |
| 880 | - if ( ! empty( $single_style_settings['single_style_custom_css'] ) && ! empty( $single_style_settings['enable_style_custom_css'] ) ) { | |
| 881 | - return $single_style_settings['single_style_custom_css']; | |
| 882 | - } | |
| 883 | - | |
| 781 | + public static function get_custom_css() { | |
| 884 | 782 | $settings = FrmAppHelper::get_settings(); |
| 885 | - | |
| 886 | 783 | if ( is_string( $settings->custom_css ) ) { |
| 887 | 784 | return $settings->custom_css; |
| 888 | 785 | } |
| 889 | 786 | |
| @@ -900,14 +797,11 @@ | ||
| 900 | 797 | * The Custom CSS page uses codemirror. |
| 901 | 798 | * |
| 902 | 799 | * @since 6.0 Previously this code was embedded in self::custom_css. |
| 903 | 800 | * |
| 904 | - * @param string $id The ID of the codemirror box. | |
| 905 | - * @param string $placeholder The placeholder text for the codemirror box. | |
| 906 | - * | |
| 907 | 801 | * @return array|false |
| 908 | 802 | */ |
| 909 | - private static function enqueue_codemirror( $id = 'frm_codemirror_box', $placeholder = '' ) { | |
| 803 | + private static function enqueue_codemirror() { | |
| 910 | 804 | if ( ! function_exists( 'wp_enqueue_code_editor' ) ) { |
| 911 | 805 | // The WordPress version is likely older than 4.9. |
| 912 | 806 | return false; |
| 913 | 807 | } |
| @@ -920,9 +814,8 @@ | ||
| 920 | 814 | 'tabSize' => 2, |
| 921 | 815 | // As the codemirror box only appears once you click into the Custom CSS tab, we need to auto-refresh. |
| 922 | 816 | // Otherwise the line numbers all end up with a 1px width causing overlap issues with the text in the content. |
| 923 | 817 | 'autoRefresh' => true, |
| 924 | - 'placeholder' => $placeholder, | |
| 925 | 818 | ), |
| 926 | 819 | ) |
| 927 | 820 | ); |
| 928 | 821 | |
| @@ -929,11 +822,9 @@ | ||
| 929 | 822 | if ( $settings ) { |
| 930 | 823 | wp_add_inline_script( |
| 931 | 824 | 'code-editor', |
| 932 | 825 | sprintf( |
| 933 | - 'jQuery( function() { window.%s_wp_editor = wp.codeEditor.initialize( \'%s\', %s ); } );', | |
| 934 | - $id, | |
| 935 | - $id, | |
| 826 | + 'jQuery( function() { wp.codeEditor.initialize( \'frm_codemirror_box\', %s ); } );', | |
| 936 | 827 | wp_json_encode( $settings ) |
| 937 | 828 | ) |
| 938 | 829 | ); |
| 939 | 830 | } |
| @@ -985,9 +876,8 @@ | ||
| 985 | 876 | FrmAppHelper::permission_check( 'frm_change_settings' ); |
| 986 | 877 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 987 | 878 | |
| 988 | 879 | $style_id = FrmAppHelper::get_post_param( 'style_id', '', 'absint' ); |
| 989 | - | |
| 990 | 880 | if ( ! $style_id ) { |
| 991 | 881 | // A style ID is not sent when resetting on the edit page. |
| 992 | 882 | // Instead of resetting the style, send the defaults back so the inputs can be updated with JavaScript. |
| 993 | 883 | $frm_style = new FrmStyle(); |
| @@ -995,26 +885,22 @@ | ||
| 995 | 885 | echo json_encode( $defaults ); |
| 996 | 886 | wp_die(); |
| 997 | 887 | } |
| 998 | 888 | |
| 999 | - $frm_style = new FrmStyle(); | |
| 1000 | - $default_template_style = $frm_style->get_default_template_style( $style_id ); | |
| 1001 | - $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( | |
| 1002 | 893 | 'ID' => $style_id, |
| 1003 | 894 | 'post_type' => self::$post_type, |
| 1004 | 895 | ); |
| 1005 | - | |
| 1006 | - $style_object = $frm_style->get_new(); | |
| 1007 | - $style_object->post_content = json_decode( $default_template_style, true ); | |
| 1008 | - | |
| 1009 | 896 | global $wpdb; |
| 1010 | - $wpdb->update( $wpdb->posts, array( 'post_content' => $default_template_style ), $where ); | |
| 897 | + $wpdb->update( $wpdb->posts, array( 'post_content' => $default_post_content ), $where ); | |
| 1011 | 898 | |
| 1012 | - // Save the settings after resetting to default or the old style will still appear. | |
| 1013 | - $frm_style->save_settings(); | |
| 899 | + $frm_style->save_settings(); // Save the settings after resetting to default or the old style will still appear. | |
| 1014 | 900 | |
| 1015 | 901 | $data = array( |
| 1016 | - 'style' => FrmStylesCardHelper::get_style_param_for_card( $style_object ), | |
| 902 | + 'style' => FrmStylesCardHelper::get_style_param_for_card( $frm_style->get_new() ), | |
| 1017 | 903 | ); |
| 1018 | 904 | wp_send_json_success( $data ); |
| 1019 | 905 | wp_die(); |
| 1020 | 906 | } |
| @@ -1029,15 +915,12 @@ | ||
| 1029 | 915 | public static function change_styling() { |
| 1030 | 916 | FrmAppHelper::permission_check( 'frm_change_settings' ); |
| 1031 | 917 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 1032 | 918 | |
| 1033 | - $is_loaded_via_ajax = true; | |
| 1034 | - $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 = ''; | |
| 1035 | 922 | |
| 1036 | - // Intentionally avoid defaults here so nothing gets removed from our style. | |
| 1037 | - $defaults = array(); | |
| 1038 | - $style = ''; | |
| 1039 | - | |
| 1040 | 923 | echo '<style type="text/css">'; |
| 1041 | 924 | include FrmAppHelper::plugin_path() . '/css/_single_theme.css.php'; |
| 1042 | 925 | echo '</style>'; |
| 1043 | 926 | wp_die(); |
| @@ -1078,9 +961,8 @@ | ||
| 1078 | 961 | |
| 1079 | 962 | /** |
| 1080 | 963 | * @param array $atts |
| 1081 | 964 | * @param array $sec |
| 1082 | - * | |
| 1083 | 965 | * @return void |
| 1084 | 966 | */ |
| 1085 | 967 | public static function include_style_section( $atts, $sec ) { |
| 1086 | 968 | extract( $atts ); // phpcs:ignore WordPress.PHP.DontExtract |
| @@ -1143,9 +1025,9 @@ | ||
| 1143 | 1025 | } |
| 1144 | 1026 | |
| 1145 | 1027 | /** |
| 1146 | 1028 | * Add an extra style rule to hide a broken style warning. |
| 1147 | - * To avoid cluttering the front end with any unnecessary styles this is only added when the referer URL matches the styler. | |
| 1029 | + * To avoid cluttering the front end with any unecessary styles this is only added when the referer URL matches the styler. | |
| 1148 | 1030 | * |
| 1149 | 1031 | * @since 6.2.3 |
| 1150 | 1032 | * |
| 1151 | 1033 | * @return void |
| @@ -1151,9 +1033,8 @@ | ||
| 1151 | 1033 | * @return void |
| 1152 | 1034 | */ |
| 1153 | 1035 | public static function maybe_hide_sample_form_error_message() { |
| 1154 | 1036 | $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' ); |
| 1155 | - | |
| 1156 | 1037 | if ( false !== strpos( $referer, 'admin.php?page=formidable-styles' ) ) { |
| 1157 | 1038 | echo '#frm_broken_styles_warning { display: none; }'; |
| 1158 | 1039 | } |
| 1159 | 1040 | } |
| @@ -1163,9 +1044,8 @@ | ||
| 1163 | 1044 | * |
| 1164 | 1045 | * @since 4.11.03 |
| 1165 | 1046 | * |
| 1166 | 1047 | * @param string $css CSS content. |
| 1167 | - * | |
| 1168 | 1048 | * @return string |
| 1169 | 1049 | */ |
| 1170 | 1050 | public static function replace_relative_url( $css ) { |
| 1171 | 1051 | $plugin_url = trailingslashit( FrmAppHelper::plugin_url() ); |
| @@ -1188,10 +1068,8 @@ | ||
| 1188 | 1068 | * Check if the Formidable styling should be loaded, |
| 1189 | 1069 | * then enqueue it for the footer |
| 1190 | 1070 | * |
| 1191 | 1071 | * @since 2.0 |
| 1192 | - * | |
| 1193 | - * @return void | |
| 1194 | 1072 | */ |
| 1195 | 1073 | public static function enqueue_style() { |
| 1196 | 1074 | global $frm_vars; |
| 1197 | 1075 | |
| @@ -1200,10 +1078,9 @@ | ||
| 1200 | 1078 | return; |
| 1201 | 1079 | } |
| 1202 | 1080 | |
| 1203 | 1081 | $frm_settings = FrmAppHelper::get_settings(); |
| 1204 | - | |
| 1205 | - if ( $frm_settings->load_style !== 'none' ) { | |
| 1082 | + if ( $frm_settings->load_style != 'none' ) { | |
| 1206 | 1083 | wp_enqueue_style( 'formidable' ); |
| 1207 | 1084 | $frm_vars['css_loaded'] = true; |
| 1208 | 1085 | } |
| 1209 | 1086 | } |
| @@ -1222,10 +1099,9 @@ | ||
| 1222 | 1099 | |
| 1223 | 1100 | /** |
| 1224 | 1101 | * Get the style post object for a target form. |
| 1225 | 1102 | * |
| 1226 | - * @param bool|object|string $form | |
| 1227 | - * | |
| 1103 | + * @param object|string|boolean $form | |
| 1228 | 1104 | * @return WP_Post|null |
| 1229 | 1105 | */ |
| 1230 | 1106 | public static function get_form_style( $form = 'default' ) { |
| 1231 | 1107 | $style = FrmFormsHelper::get_form_style( $form ); |
| @@ -1240,10 +1116,8 @@ | ||
| 1240 | 1116 | |
| 1241 | 1117 | /** |
| 1242 | 1118 | * @param string $class |
| 1243 | 1119 | * @param string $style |
| 1244 | - * | |
| 1245 | - * @return string | |
| 1246 | 1120 | */ |
| 1247 | 1121 | public static function get_form_style_class( $class, $style ) { |
| 1248 | 1122 | if ( 1 == $style ) { |
| 1249 | 1123 | $style = 'default'; |
| @@ -1260,18 +1134,15 @@ | ||
| 1260 | 1134 | return $class; |
| 1261 | 1135 | } |
| 1262 | 1136 | |
| 1263 | 1137 | /** |
| 1264 | - * @since 3.0 | |
| 1265 | - * | |
| 1266 | 1138 | * @param object $style |
| 1267 | 1139 | * @param string $class |
| 1268 | 1140 | * |
| 1269 | - * @return void | |
| 1141 | + * @since 3.0 | |
| 1270 | 1142 | */ |
| 1271 | 1143 | private static function maybe_add_rtl_class( $style, &$class ) { |
| 1272 | 1144 | $is_rtl = isset( $style->post_content['direction'] ) && 'rtl' === $style->post_content['direction']; |
| 1273 | - | |
| 1274 | 1145 | if ( $is_rtl ) { |
| 1275 | 1146 | $class .= ' frm_rtl'; |
| 1276 | 1147 | } |
| 1277 | 1148 | } |
| @@ -1276,26 +1147,17 @@ | ||
| 1276 | 1147 | } |
| 1277 | 1148 | } |
| 1278 | 1149 | |
| 1279 | 1150 | /** |
| 1280 | - * @param string $val Style setting key. | |
| 1281 | - * @param int|string $form Form ID or 'default'. | |
| 1282 | - * | |
| 1283 | - * @return mixed | |
| 1151 | + * @param string $val | |
| 1284 | 1152 | */ |
| 1285 | 1153 | public static function get_style_val( $val, $form = 'default' ) { |
| 1286 | 1154 | $style = self::get_form_style( $form ); |
| 1287 | - | |
| 1288 | 1155 | if ( $style && isset( $style->post_content[ $val ] ) ) { |
| 1289 | 1156 | return $style->post_content[ $val ]; |
| 1290 | 1157 | } |
| 1291 | 1158 | } |
| 1292 | 1159 | |
| 1293 | - /** | |
| 1294 | - * @param array $default_styles | |
| 1295 | - * | |
| 1296 | - * @return array | |
| 1297 | - */ | |
| 1298 | 1160 | public static function show_entry_styles( $default_styles ) { |
| 1299 | 1161 | $frm_style = new FrmStyle( 'default' ); |
| 1300 | 1162 | $style = $frm_style->get_one(); |
| 1301 | 1163 | |
| @@ -1304,9 +1166,8 @@ | ||
| 1304 | 1166 | } |
| 1305 | 1167 | |
| 1306 | 1168 | foreach ( $default_styles as $name => $val ) { |
| 1307 | 1169 | $setting = $name; |
| 1308 | - | |
| 1309 | 1170 | if ( 'border_width' == $name ) { |
| 1310 | 1171 | $setting = 'field_border_width'; |
| 1311 | 1172 | } elseif ( 'alt_bg_color' == $name ) { |
| 1312 | 1173 | $setting = 'bg_color_active'; |
| @@ -1317,14 +1178,8 @@ | ||
| 1317 | 1178 | |
| 1318 | 1179 | return $default_styles; |
| 1319 | 1180 | } |
| 1320 | 1181 | |
| 1321 | - /** | |
| 1322 | - * @param string $important | |
| 1323 | - * @param array $field | |
| 1324 | - * | |
| 1325 | - * @return string | |
| 1326 | - */ | |
| 1327 | 1182 | public static function &important_style( $important, $field ) { |
| 1328 | 1183 | $important = self::get_style_val( 'important_style', $field['form_id'] ); |
| 1329 | 1184 | |
| 1330 | 1185 | return $important; |
| @@ -1329,91 +1184,10 @@ | ||
| 1329 | 1184 | |
| 1330 | 1185 | return $important; |
| 1331 | 1186 | } |
| 1332 | 1187 | |
| 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 ) { | |
| 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 ( empty( $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 | - | |
| 1381 | - $open_class = ''; | |
| 1382 | - | |
| 1383 | - if ( ! $first_open ) { | |
| 1384 | - $first_open = true; | |
| 1385 | - $open_class = 'open'; | |
| 1386 | - } | |
| 1387 | - | |
| 1388 | - $accordion_content_id = 'frm_style_section_' . $box['id']; | |
| 1389 | - ?> | |
| 1390 | - <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'] ); ?>"> | |
| 1391 | - <h3 class="accordion-section-title hndle"> | |
| 1392 | - <?php | |
| 1393 | - FrmAppHelper::icon_by_class( 'frmfont ' . $icon_id . ' frm_svg24' ); | |
| 1394 | - echo esc_html( $box['title'] ); | |
| 1395 | - ?> | |
| 1396 | - <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'] ); ?>"> | |
| 1397 | - <?php FrmAppHelper::icon_by_class( 'frmfont frm_arrowdown8_icon' ); ?> | |
| 1398 | - </button> | |
| 1399 | - </h3> | |
| 1400 | - <div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>" id="<?php echo esc_attr( $accordion_content_id ); ?>"> | |
| 1401 | - <div class="inside"> | |
| 1402 | - <?php call_user_func( $box['callback'], $data_object, $box ); ?> | |
| 1403 | - </div><!-- .inside --> | |
| 1404 | - </div><!-- .accordion-section-content --> | |
| 1405 | - </li><!-- .accordion-section --> | |
| 1406 | - <?php | |
| 1407 | - }//end foreach | |
| 1408 | - }//end if | |
| 1409 | - }//end foreach | |
| 1410 | - }//end if | |
| 1411 | - ?> | |
| 1412 | - </ul><!-- .outer-border --> | |
| 1413 | - </div><!-- .accordion-container --> | |
| 1414 | - <?php | |
| 1415 | - return $i; | |
| 1188 | + public static function do_accordion_sections( $screen, $context, $object ) { | |
| 1189 | + return do_accordion_sections( $screen, $context, $object ); | |
| 1416 | 1190 | } |
| 1417 | 1191 | |
| 1418 | 1192 | /** |
| 1419 | 1193 | * Rename a style via an AJAX action. |
| @@ -1423,9 +1197,8 @@ | ||
| 1423 | 1197 | * @return void |
| 1424 | 1198 | */ |
| 1425 | 1199 | public static function rename_style() { |
| 1426 | 1200 | $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'nonce', 'frm_ajax' ); |
| 1427 | - | |
| 1428 | 1201 | if ( $permission_error !== false ) { |
| 1429 | 1202 | $data = array( |
| 1430 | 1203 | 'message' => __( 'Unable to rename style', 'formidable' ), |
| 1431 | 1204 | ); |
| @@ -1444,9 +1217,8 @@ | ||
| 1444 | 1217 | die(); |
| 1445 | 1218 | } |
| 1446 | 1219 | |
| 1447 | 1220 | $post = get_post( $style_id ); |
| 1448 | - | |
| 1449 | 1221 | if ( ! $post || $post->post_type !== self::$post_type ) { |
| 1450 | 1222 | $data = array( |
| 1451 | 1223 | 'message' => __( 'The style you are renaming either does not exist or it is not a style', 'formidable' ), |
| 1452 | 1224 | ); |
| @@ -1467,9 +1239,8 @@ | ||
| 1467 | 1239 | * |
| 1468 | 1240 | * @since 6.0 |
| 1469 | 1241 | * |
| 1470 | 1242 | * @param WP_Styles $styles |
| 1471 | - * | |
| 1472 | 1243 | * @return void |
| 1473 | 1244 | */ |
| 1474 | 1245 | public static function disable_conflicting_wp_admin_css( $styles ) { |
| 1475 | 1246 | if ( ! FrmAppHelper::is_style_editor_page() ) { |