| @@ -19,20 +19,8 @@ | ||
| 19 | 19 | * @var string|null |
| 20 | 20 | */ |
| 21 | 21 | private static $message; |
| 22 | 22 | |
| 23 | - /** | |
| 24 | - * Cache of the active style object keyed by form ID. | |
| 25 | - * | |
| 26 | - * @since 6.32 | |
| 27 | - * | |
| 28 | - * @var array | |
| 29 | - */ | |
| 30 | - private static $active_style = array(); | |
| 31 | - | |
| 32 | - /** | |
| 33 | - * @return void | |
| 34 | - */ | |
| 35 | 23 | public static function load_pro_hooks() { |
| 36 | 24 | if ( FrmAppHelper::pro_is_installed() ) { |
| 37 | 25 | FrmProStylesController::load_pro_hooks(); |
| 38 | 26 | } |
| @@ -37,11 +25,8 @@ | ||
| 37 | 25 | FrmProStylesController::load_pro_hooks(); |
| 38 | 26 | } |
| 39 | 27 | } |
| 40 | 28 | |
| 41 | - /** | |
| 42 | - * @return void | |
| 43 | - */ | |
| 44 | 29 | public static function register_post_types() { |
| 45 | 30 | register_post_type( |
| 46 | 31 | self::$post_type, |
| 47 | 32 | array( |
| @@ -82,10 +67,10 @@ | ||
| 82 | 67 | * |
| 83 | 68 | * @return void |
| 84 | 69 | */ |
| 85 | 70 | public static function menu() { |
| 86 | - add_submenu_page( 'formidable', 'Formidable | ' . __( 'Styles', 'formidable' ), __( 'Styles', 'formidable' ), 'frm_change_settings', 'formidable-styles', 'FrmStylesController::route' ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 87 | - 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' ); | |
| 88 | 73 | } |
| 89 | 74 | |
| 90 | 75 | /** |
| 91 | 76 | * Remove filters for the visual styler preview. |
| @@ -143,14 +128,13 @@ | ||
| 143 | 128 | if ( FrmAppHelper::is_style_editor_page( 'edit' ) ) { |
| 144 | 129 | wp_enqueue_style( 'wp-color-picker' ); |
| 145 | 130 | } |
| 146 | 131 | |
| 147 | - wp_enqueue_style( 'frm-custom-theme', admin_url( 'admin-ajax.php?action=frmpro_css&frm_scope_custom_css=1' ), array(), $version ); | |
| 132 | + wp_enqueue_style( 'frm-custom-theme', admin_url( 'admin-ajax.php?action=frmpro_css' ), array(), $version ); | |
| 148 | 133 | |
| 149 | 134 | $style = apply_filters( 'frm_style_head', false ); |
| 150 | - | |
| 151 | 135 | if ( $style ) { |
| 152 | - 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 ); | |
| 153 | 137 | } |
| 154 | 138 | } |
| 155 | 139 | |
| 156 | 140 | /** |
| @@ -177,9 +161,8 @@ | ||
| 177 | 161 | |
| 178 | 162 | /** |
| 179 | 163 | * @param string $register Either 'enqueue' or 'register'. |
| 180 | 164 | * @param bool $force True to enqueue/register the style if a form has not been loaded. |
| 181 | - * | |
| 182 | 165 | * @return void |
| 183 | 166 | */ |
| 184 | 167 | public static function enqueue_css( $register = 'enqueue', $force = false ) { |
| 185 | 168 | global $frm_vars; |
| @@ -191,9 +174,8 @@ | ||
| 191 | 174 | return; |
| 192 | 175 | } |
| 193 | 176 | |
| 194 | 177 | $frm_settings = FrmAppHelper::get_settings(); |
| 195 | - | |
| 196 | 178 | if ( $frm_settings->load_style === 'none' ) { |
| 197 | 179 | return; |
| 198 | 180 | } |
| 199 | 181 | |
| @@ -209,9 +191,8 @@ | ||
| 209 | 191 | wp_register_style( $css_key, $file, array(), $this_version ); |
| 210 | 192 | } |
| 211 | 193 | |
| 212 | 194 | $load_on_all = ! FrmAppHelper::is_admin() && 'all' === $frm_settings->load_style; |
| 213 | - | |
| 214 | 195 | if ( $load_on_all || $register !== 'register' ) { |
| 215 | 196 | wp_enqueue_style( $css_key ); |
| 216 | 197 | } |
| 217 | 198 | unset( $css_key, $file ); |
| @@ -242,22 +223,18 @@ | ||
| 242 | 223 | } |
| 243 | 224 | |
| 244 | 225 | /** |
| 245 | 226 | * @param array $stylesheet_urls |
| 246 | - * | |
| 247 | 227 | * @return void |
| 248 | 228 | */ |
| 249 | 229 | private static function get_url_to_custom_style( &$stylesheet_urls ) { |
| 250 | - $add_css_to_uploads_dir = FrmStyle::add_css_to_uploads_dir(); | |
| 251 | - $file_path = FrmStyle::get_generated_css_file_path( $add_css_to_uploads_dir ) . '/' . self::get_file_name(); | |
| 252 | - | |
| 253 | - if ( ! is_readable( $file_path ) ) { | |
| 254 | - $stylesheet_urls['formidable'] = admin_url( 'admin-ajax.php?action=frmpro_css' ); | |
| 255 | - return; | |
| 230 | + $file_name = '/css/' . self::get_file_name(); | |
| 231 | + if ( is_readable( FrmAppHelper::plugin_path() . $file_name ) ) { | |
| 232 | + $url = FrmAppHelper::plugin_url() . $file_name; | |
| 233 | + } else { | |
| 234 | + $url = admin_url( 'admin-ajax.php?action=frmpro_css' ); | |
| 256 | 235 | } |
| 257 | - | |
| 258 | - $base_url = $add_css_to_uploads_dir ? wp_upload_dir()['baseurl'] . '/formidable/css/' : FrmAppHelper::plugin_url() . '/css/'; | |
| 259 | - $stylesheet_urls['formidable'] = $base_url . self::get_file_name(); | |
| 236 | + $stylesheet_urls['formidable'] = $url; | |
| 260 | 237 | } |
| 261 | 238 | |
| 262 | 239 | /** |
| 263 | 240 | * Use a different stylesheet per site in a multisite install |
| @@ -262,44 +239,42 @@ | ||
| 262 | 239 | /** |
| 263 | 240 | * Use a different stylesheet per site in a multisite install |
| 264 | 241 | * |
| 265 | 242 | * @since 3.0.03 |
| 266 | - * | |
| 267 | - * @return string | |
| 268 | 243 | */ |
| 269 | 244 | public static function get_file_name() { |
| 270 | 245 | if ( is_multisite() ) { |
| 271 | - return 'formidableforms' . absint( get_current_blog_id() ) . '.css'; | |
| 246 | + $blog_id = get_current_blog_id(); | |
| 247 | + $name = 'formidableforms' . absint( $blog_id ) . '.css'; | |
| 248 | + } else { | |
| 249 | + $name = 'formidableforms.css'; | |
| 272 | 250 | } |
| 273 | 251 | |
| 274 | - return 'formidableforms.css'; | |
| 252 | + return $name; | |
| 275 | 253 | } |
| 276 | 254 | |
| 277 | - /** | |
| 278 | - * @param string $css_key | |
| 279 | - * @param string $version | |
| 280 | - * | |
| 281 | - * @return string | |
| 282 | - */ | |
| 283 | 255 | private static function get_css_version( $css_key, $version ) { |
| 284 | - if ( 'formidable' !== $css_key ) { | |
| 285 | - 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; | |
| 286 | 263 | } |
| 287 | 264 | |
| 288 | - $this_version = get_option( 'frm_last_style_update' ); | |
| 289 | - | |
| 290 | - return $this_version ? $this_version : $version; | |
| 265 | + return $this_version; | |
| 291 | 266 | } |
| 292 | 267 | |
| 293 | 268 | /** |
| 294 | 269 | * @param string $tag |
| 295 | 270 | * @param string $handle |
| 296 | - * | |
| 297 | 271 | * @return string |
| 298 | 272 | */ |
| 299 | 273 | public static function add_tags_to_css( $tag, $handle ) { |
| 300 | - if ( ( 'formidable' === $handle || 'jquery-theme' === $handle ) && ! str_contains( $tag, ' property=' ) ) { | |
| 301 | - return str_replace( ' type="', ' property="stylesheet" type="', $tag ); | |
| 274 | + if ( ( 'formidable' === $handle || 'jquery-theme' === $handle ) && strpos( $tag, ' property=' ) === false ) { | |
| 275 | + $frm_settings = FrmAppHelper::get_settings(); | |
| 276 | + $tag = str_replace( ' type="', ' property="stylesheet" type="', $tag ); | |
| 302 | 277 | } |
| 303 | 278 | |
| 304 | 279 | return $tag; |
| 305 | 280 | } |
| @@ -347,11 +322,10 @@ | ||
| 347 | 322 | |
| 348 | 323 | self::setup_styles_and_scripts_for_styler(); |
| 349 | 324 | |
| 350 | 325 | $style_id = self::get_style_id_for_styler(); |
| 351 | - | |
| 352 | 326 | if ( ! $style_id ) { |
| 353 | - $error_args = array( | |
| 327 | + $error_args = array( | |
| 354 | 328 | 'title' => __( 'No styles', 'formidable' ), |
| 355 | 329 | 'body' => __( 'You must have a style to use the Visual Styler.', 'formidable' ), |
| 356 | 330 | 'cancel_url' => admin_url( 'admin.php?page=formidable' ), |
| 357 | 331 | ); |
| @@ -359,9 +333,8 @@ | ||
| 359 | 333 | return; |
| 360 | 334 | } |
| 361 | 335 | |
| 362 | 336 | $form_id = FrmAppHelper::simple_get( 'form', 'absint', 0 ); |
| 363 | - | |
| 364 | 337 | if ( ! $form_id ) { |
| 365 | 338 | $form_id = self::get_form_id_for_style( $style_id ); |
| 366 | 339 | } |
| 367 | 340 | |
| @@ -367,9 +340,9 @@ | ||
| 367 | 340 | |
| 368 | 341 | $form = FrmForm::getOne( $form_id ); |
| 369 | 342 | |
| 370 | 343 | if ( ! is_object( $form ) ) { |
| 371 | - $error_args = array( | |
| 344 | + $error_args = array( | |
| 372 | 345 | 'title' => __( 'No forms', 'formidable' ), |
| 373 | 346 | 'body' => __( 'You must have a form to use the Visual Styler.', 'formidable' ), |
| 374 | 347 | 'cancel_url' => admin_url( 'admin.php?page=formidable' ), |
| 375 | 348 | ); |
| @@ -376,10 +349,11 @@ | ||
| 376 | 349 | FrmAppController::show_error_modal( $error_args ); |
| 377 | 350 | return; |
| 378 | 351 | } |
| 379 | 352 | |
| 380 | - $frm_style = new FrmStyle( $style_id ); | |
| 381 | - $active_style = $frm_style->get_one(); | |
| 353 | + $frm_style = new FrmStyle( $style_id ); | |
| 354 | + $active_style = $frm_style->get_one(); | |
| 355 | + $default_style = self::get_default_style(); | |
| 382 | 356 | |
| 383 | 357 | self::disable_admin_page_styling_on_submit_buttons(); |
| 384 | 358 | |
| 385 | 359 | /** |
| @@ -388,9 +362,9 @@ | ||
| 388 | 362 | * @param array{form:\stdClass} $data |
| 389 | 363 | */ |
| 390 | 364 | do_action( 'frm_before_render_style_page', compact( 'form' ) ); |
| 391 | 365 | |
| 392 | - self::render_style_page( $active_style, $form, self::get_default_style() ); | |
| 366 | + self::render_style_page( $active_style, $form, $default_style ); | |
| 393 | 367 | } |
| 394 | 368 | |
| 395 | 369 | /** |
| 396 | 370 | * @since 6.0 |
| @@ -398,9 +372,8 @@ | ||
| 398 | 372 | * @return int |
| 399 | 373 | */ |
| 400 | 374 | private static function get_style_id_for_styler() { |
| 401 | 375 | $action = FrmAppHelper::simple_get( 'frm_action' ); |
| 402 | - | |
| 403 | 376 | if ( 'duplicate' === $action ) { |
| 404 | 377 | // The duplicate action uses style_id instead of id for better backward compatibility. |
| 405 | 378 | return FrmAppHelper::simple_get( 'style_id', 'absint', 0 ); |
| 406 | 379 | } |
| @@ -405,9 +378,8 @@ | ||
| 405 | 378 | return FrmAppHelper::simple_get( 'style_id', 'absint', 0 ); |
| 406 | 379 | } |
| 407 | 380 | |
| 408 | 381 | $style_id = FrmAppHelper::simple_get( 'id', 'absint', 0 ); |
| 409 | - | |
| 410 | 382 | if ( $style_id ) { |
| 411 | 383 | // Always use the style ID from the URL if one is specified. |
| 412 | 384 | return $style_id; |
| 413 | 385 | } |
| @@ -412,9 +384,8 @@ | ||
| 412 | 384 | return $style_id; |
| 413 | 385 | } |
| 414 | 386 | |
| 415 | 387 | $request_form_id = FrmAppHelper::simple_get( 'form', 'absint', 0 ); |
| 416 | - | |
| 417 | 388 | if ( $request_form_id && is_callable( 'FrmProStylesController::get_active_style_for_form' ) ) { |
| 418 | 389 | return FrmProStylesController::get_active_style_for_form( $request_form_id )->ID; |
| 419 | 390 | } |
| 420 | 391 | |
| @@ -426,9 +397,8 @@ | ||
| 426 | 397 | * |
| 427 | 398 | * @since 6.0 |
| 428 | 399 | * |
| 429 | 400 | * @param int $style_id |
| 430 | - * | |
| 431 | 401 | * @return int |
| 432 | 402 | */ |
| 433 | 403 | private static function get_form_id_for_style( $style_id ) { |
| 434 | 404 | $check = serialize( array( 'custom_style' => (string) $style_id ) ); |
| @@ -441,8 +411,9 @@ | ||
| 441 | 411 | ) |
| 442 | 412 | ); |
| 443 | 413 | |
| 444 | 414 | if ( ! $form_id ) { |
| 415 | + // TODO: Show a message why a random form is being shown (because no form is assigned to the style). | |
| 445 | 416 | // Fallback to any form. |
| 446 | 417 | $where = array( |
| 447 | 418 | 'status' => 'published', |
| 448 | 419 | // Make sure it's not a repeater. |
| @@ -474,10 +445,11 @@ | ||
| 474 | 445 | * |
| 475 | 446 | * @return WP_Post |
| 476 | 447 | */ |
| 477 | 448 | private static function get_default_style() { |
| 478 | - $frm_style = new FrmStyle( 'default' ); | |
| 479 | - return $frm_style->get_one(); | |
| 449 | + $frm_style = new FrmStyle( 'default' ); | |
| 450 | + $default_style = $frm_style->get_one(); | |
| 451 | + return $default_style; | |
| 480 | 452 | } |
| 481 | 453 | |
| 482 | 454 | /** |
| 483 | 455 | * Save style for form (from Styler list page) via a POST action. |
| @@ -487,15 +459,13 @@ | ||
| 487 | 459 | * @return void |
| 488 | 460 | */ |
| 489 | 461 | private static function save_form_style() { |
| 490 | 462 | $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'frm_save_form_style', 'frm_save_form_style_nonce' ); |
| 491 | - | |
| 492 | 463 | if ( $permission_error !== false ) { |
| 493 | 464 | wp_die( 'Unable to save form', '', 403 ); |
| 494 | 465 | } |
| 495 | 466 | |
| 496 | 467 | $style_id = FrmAppHelper::get_post_param( 'style_id', 0, 'absint' ); |
| 497 | - | |
| 498 | 468 | if ( $style_id && ! self::confirm_style_exists_before_setting( $style_id ) ) { |
| 499 | 469 | wp_die( esc_html__( 'Invalid target style', 'formidable' ), esc_html__( 'Invalid target style', 'formidable' ), 400 ); |
| 500 | 470 | return; |
| 501 | 471 | } |
| @@ -515,9 +485,8 @@ | ||
| 515 | 485 | return; |
| 516 | 486 | } |
| 517 | 487 | |
| 518 | 488 | $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' ); |
| 519 | - | |
| 520 | 489 | if ( ! $form_id ) { |
| 521 | 490 | wp_die( esc_html__( 'No form specified', 'formidable' ), esc_html__( 'No form specified', 'formidable' ), 400 ); |
| 522 | 491 | return; |
| 523 | 492 | } |
| @@ -522,21 +491,18 @@ | ||
| 522 | 491 | return; |
| 523 | 492 | } |
| 524 | 493 | |
| 525 | 494 | $form = FrmForm::getOne( $form_id ); |
| 526 | - | |
| 527 | 495 | if ( ! $form ) { |
| 528 | 496 | wp_die( esc_html__( 'Form does not exist', 'formidable' ), esc_html__( 'Form does not exist', 'formidable' ), 400 ); |
| 529 | 497 | return; |
| 530 | 498 | } |
| 531 | 499 | |
| 532 | - $previous_style_id = $form->options['custom_style']; | |
| 533 | - | |
| 534 | 500 | // If the default style is selected, use the "Always use default" legacy option instead of the default style. |
| 535 | 501 | // There's also a check here for conversational forms. |
| 536 | 502 | // Without the check it isn't possible to select "Default" because "Always use default" will convert to "Lines" dynamically. |
| 537 | - | |
| 538 | - if ( $style_id === self::get_default_style()->ID && empty( $form->options['chat'] ) ) { | |
| 503 | + $default_style = self::get_default_style(); | |
| 504 | + if ( $style_id === $default_style->ID && empty( $form->options['chat'] ) ) { | |
| 539 | 505 | $style_id = 1; |
| 540 | 506 | } |
| 541 | 507 | |
| 542 | 508 | // We want to save a string for consistency. FrmStylesHelper::get_form_count_for_style expects the custom style ID is a string. |
| @@ -541,27 +507,13 @@ | ||
| 541 | 507 | |
| 542 | 508 | // We want to save a string for consistency. FrmStylesHelper::get_form_count_for_style expects the custom style ID is a string. |
| 543 | 509 | $form->options['custom_style'] = (string) $style_id; |
| 544 | 510 | |
| 545 | - if ( $previous_style_id === $form->options['custom_style'] ) { | |
| 546 | - // Exit early before updating DB if nothing actually changed. | |
| 547 | - self::$message = __( 'Successfully updated style.', 'formidable' ); | |
| 548 | - return; | |
| 549 | - } | |
| 550 | - | |
| 551 | 511 | global $wpdb; |
| 552 | 512 | $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $form->options ) ), array( 'id' => $form->id ) ); |
| 553 | 513 | |
| 554 | 514 | FrmForm::clear_form_cache(); |
| 555 | 515 | |
| 556 | - /** | |
| 557 | - * @since 6.25.1 | |
| 558 | - * | |
| 559 | - * @param int $form_id | |
| 560 | - * @param int $style_id | |
| 561 | - */ | |
| 562 | - do_action( 'frm_after_changed_form_style', absint( $form_id ), absint( $style_id ) ); | |
| 563 | - | |
| 564 | 516 | self::$message = __( 'Successfully updated style.', 'formidable' ); |
| 565 | 517 | } |
| 566 | 518 | |
| 567 | 519 | /** |
| @@ -567,9 +519,8 @@ | ||
| 567 | 519 | /** |
| 568 | 520 | * Validate that we're assigning a form to a style that actually exists before assigning it to a form. |
| 569 | 521 | * |
| 570 | 522 | * @param int $style_id |
| 571 | - * | |
| 572 | 523 | * @return bool True if the style actually exists. |
| 573 | 524 | */ |
| 574 | 525 | private static function confirm_style_exists_before_setting( $style_id ) { |
| 575 | 526 | global $wpdb; |
| @@ -609,9 +560,8 @@ | ||
| 609 | 560 | * |
| 610 | 561 | * @param stdClass|WP_Post $active_style |
| 611 | 562 | * @param stdClass $form |
| 612 | 563 | * @param WP_Post $default_style |
| 613 | - * | |
| 614 | 564 | * @return void |
| 615 | 565 | */ |
| 616 | 566 | private static function render_style_page( $active_style, $form, $default_style ) { |
| 617 | 567 | $style_views_path = self::get_views_path(); |
| @@ -633,44 +583,22 @@ | ||
| 633 | 583 | $style = $active_style; |
| 634 | 584 | break; |
| 635 | 585 | |
| 636 | 586 | case 'duplicate': |
| 637 | - $style = clone $active_style; | |
| 638 | - $new_style = $frm_style->get_new(); | |
| 639 | - $new_name = self::get_new_style_post_name( $new_style->post_name ); | |
| 640 | - | |
| 641 | - // The single style custom CSS is nested under the old style's scope. Re-scope it to the | |
| 642 | - // new style's scope so it unnests correctly for display and re-nests correctly on save. | |
| 643 | - if ( ! empty( $style->post_content['single_style_custom_css'] ) ) { | |
| 644 | - $css_scope_helper = new FrmCssScopeHelper(); | |
| 645 | - $unnested_css = $css_scope_helper->unnest( $style->post_content['single_style_custom_css'], 'frm_style_' . $style->post_name ); // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong | |
| 646 | - $style->post_content['single_style_custom_css'] = $css_scope_helper->nest( $unnested_css, 'frm_style_' . $new_name ); | |
| 647 | - } | |
| 648 | - | |
| 587 | + $style = clone $active_style; | |
| 588 | + $new_style = $frm_style->get_new(); | |
| 649 | 589 | $style->ID = $new_style->ID; |
| 650 | - $style->post_name = $new_name; | |
| 651 | - unset( $new_style, $new_name ); | |
| 590 | + $style->post_name = $new_style->post_name; | |
| 591 | + unset( $new_style ); | |
| 652 | 592 | break; |
| 653 | 593 | |
| 654 | 594 | case 'new_style': |
| 655 | - $style = $frm_style->get_new(); | |
| 656 | - $style->post_name = self::get_new_style_post_name( $style->post_name ); | |
| 595 | + $style = $frm_style->get_new(); | |
| 657 | 596 | break; |
| 658 | - }//end switch | |
| 597 | + } | |
| 659 | 598 | |
| 660 | 599 | if ( in_array( $view, array( 'duplicate', 'new_style' ), true ) ) { |
| 661 | - // A new or duplicated style has no ID yet, so the Rename modal updates the post_title input | |
| 662 | - // instead of calling an endpoint. Prefer that posted title over $_GET['style_name'] when present. | |
| 663 | - $posted_title = ''; | |
| 664 | - | |
| 665 | - // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 666 | - if ( isset( $_POST['frm_style_setting']['post_title'] ) ) { | |
| 667 | - // The nonce is verified in FrmStylesController::save_style before this renders. | |
| 668 | - // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 669 | - $posted_title = sanitize_text_field( wp_unslash( $_POST['frm_style_setting']['post_title'] ) ); | |
| 670 | - } | |
| 671 | - | |
| 672 | - $style->post_title = '' !== $posted_title ? $posted_title : FrmAppHelper::simple_get( 'style_name' ); | |
| 600 | + $style->post_title = FrmAppHelper::simple_get( 'style_name' ); | |
| 673 | 601 | $style->menu_order = 0; |
| 674 | 602 | } |
| 675 | 603 | |
| 676 | 604 | if ( ! isset( $style ) ) { |
| @@ -694,27 +622,8 @@ | ||
| 694 | 622 | include $style_views_path . 'show.php'; |
| 695 | 623 | } |
| 696 | 624 | |
| 697 | 625 | /** |
| 698 | - * Derive the temporary post_name (CSS scope slug) for a new or duplicated style from the chosen | |
| 699 | - * style name so the displayed scope matches the slug WordPress will store on save. | |
| 700 | - * | |
| 701 | - * Falls back to the auto-generated key when no style name was provided so the scope is never empty. | |
| 702 | - * | |
| 703 | - * @since 6.32 | |
| 704 | - * | |
| 705 | - * @param string $fallback The auto-generated post_name to use when no style name is chosen. | |
| 706 | - * | |
| 707 | - * @return string | |
| 708 | - */ | |
| 709 | - private static function get_new_style_post_name( $fallback ) { | |
| 710 | - $style_name = FrmAppHelper::simple_get( 'style_name' ); | |
| 711 | - $slug = $style_name ? sanitize_title( $style_name ) : ''; | |
| 712 | - | |
| 713 | - return $slug ? $slug : $fallback; | |
| 714 | - } | |
| 715 | - | |
| 716 | - /** | |
| 717 | 626 | * @since 6.0 |
| 718 | 627 | * |
| 719 | 628 | * @return string |
| 720 | 629 | */ |
| @@ -727,9 +636,8 @@ | ||
| 727 | 636 | * |
| 728 | 637 | * @since 6.0 |
| 729 | 638 | * |
| 730 | 639 | * @param stdClass|WP_Post $style A new style is not a WP_Post object. |
| 731 | - * | |
| 732 | 640 | * @return void |
| 733 | 641 | */ |
| 734 | 642 | private static function force_form_style( $style ) { |
| 735 | 643 | add_filter( |
| @@ -740,9 +648,9 @@ | ||
| 740 | 648 | /** |
| 741 | 649 | * @param string $class |
| 742 | 650 | */ |
| 743 | 651 | function ( $class ) { |
| 744 | - return $class && ! str_starts_with( $class, 'frm_style_' ); | |
| 652 | + return $class && 0 !== strpos( $class, 'frm_style_' ); | |
| 745 | 653 | } |
| 746 | 654 | ); |
| 747 | 655 | $split[] = 'frm_style_' . $style->post_name; |
| 748 | 656 | return implode( ' ', $split ); |
| @@ -757,10 +665,8 @@ | ||
| 757 | 665 | * |
| 758 | 666 | * @return void |
| 759 | 667 | */ |
| 760 | 668 | public static function save_style() { |
| 761 | - FrmAppHelper::permission_check( 'frm_change_settings' ); | |
| 762 | - | |
| 763 | 669 | $frm_style = new FrmStyle(); |
| 764 | 670 | $post_id = FrmAppHelper::get_post_param( 'ID', false, 'sanitize_title' ); |
| 765 | 671 | $style_nonce = FrmAppHelper::get_post_param( 'frm_style', '', 'sanitize_text_field' ); |
| 766 | 672 | |
| @@ -770,9 +676,8 @@ | ||
| 770 | 676 | return; |
| 771 | 677 | } |
| 772 | 678 | |
| 773 | 679 | $id = $frm_style->update( $post_id ); |
| 774 | - | |
| 775 | 680 | if ( ! $post_id && $id ) { |
| 776 | 681 | self::maybe_redirect_after_save( $id ); |
| 777 | 682 | // Set the post id to the new style so it will be loaded for editing. |
| 778 | 683 | $post_id = reset( $id ); |
| @@ -777,15 +682,8 @@ | ||
| 777 | 682 | // Set the post id to the new style so it will be loaded for editing. |
| 778 | 683 | $post_id = reset( $id ); |
| 779 | 684 | } |
| 780 | 685 | |
| 781 | - /** | |
| 782 | - * @since 6.25.1 | |
| 783 | - * | |
| 784 | - * @param int $post_id | |
| 785 | - */ | |
| 786 | - do_action( 'frm_after_saved_style', absint( $post_id ) ); | |
| 787 | - | |
| 788 | 686 | self::$message = __( 'Your styling settings have been saved.', 'formidable' ); |
| 789 | 687 | } |
| 790 | 688 | |
| 791 | 689 | /** |
| @@ -804,20 +702,19 @@ | ||
| 804 | 702 | * |
| 805 | 703 | * @since 6.0 |
| 806 | 704 | * |
| 807 | 705 | * @param array $ids |
| 808 | - * | |
| 809 | 706 | * @return void |
| 810 | 707 | */ |
| 811 | 708 | private static function maybe_redirect_after_save( $ids ) { |
| 812 | - $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' ); | |
| 813 | - $parsed = parse_url( $referer ); | |
| 814 | - $query = $parsed['query']; | |
| 709 | + $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' ); | |
| 710 | + $parsed = parse_url( $referer ); | |
| 711 | + $query = $parsed['query']; | |
| 712 | + | |
| 815 | 713 | $current_action = false; |
| 816 | 714 | $actions_to_redirect = array( 'duplicate', 'new_style' ); |
| 817 | - | |
| 818 | 715 | foreach ( $actions_to_redirect as $action ) { |
| 819 | - if ( str_contains( $query, 'frm_action=' . $action ) ) { | |
| 716 | + if ( false !== strpos( $query, 'frm_action=' . $action ) ) { | |
| 820 | 717 | $current_action = $action; |
| 821 | 718 | break; |
| 822 | 719 | } |
| 823 | 720 | } |
| @@ -827,9 +724,10 @@ | ||
| 827 | 724 | return; |
| 828 | 725 | } |
| 829 | 726 | |
| 830 | 727 | parse_str( $query, $parsed_query ); |
| 831 | - $form_id = ! empty( $parsed_query['form'] ) ? absint( $parsed_query['form'] ) : 0; | |
| 728 | + $form_id = ! empty( $parsed_query['form'] ) ? absint( $parsed_query['form'] ) : 0; | |
| 729 | + | |
| 832 | 730 | $style = new stdClass(); |
| 833 | 731 | $style->ID = end( $ids ); |
| 834 | 732 | wp_safe_redirect( esc_url_raw( FrmStylesHelper::get_edit_url( $style, $form_id ) ) ); |
| 835 | 733 | die(); |
| @@ -839,9 +737,8 @@ | ||
| 839 | 737 | * @since 6.0 |
| 840 | 738 | * |
| 841 | 739 | * @param string $message |
| 842 | 740 | * @param array|object $forms |
| 843 | - * | |
| 844 | 741 | * @return void |
| 845 | 742 | */ |
| 846 | 743 | public static function manage( $message = '', $forms = array() ) { |
| 847 | 744 | $frm_style = new FrmStyle(); |
| @@ -865,9 +762,8 @@ | ||
| 865 | 762 | private static function manage_styles() { |
| 866 | 763 | global $wpdb; |
| 867 | 764 | |
| 868 | 765 | $forms = FrmForm::get_published_forms(); |
| 869 | - | |
| 870 | 766 | foreach ( $forms as $form ) { |
| 871 | 767 | if ( ! isset( $_POST['style'] ) || ! isset( $_POST['style'][ $form->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 872 | 768 | continue; |
| 873 | 769 | } |
| @@ -883,28 +779,15 @@ | ||
| 883 | 779 | /** |
| 884 | 780 | * Echo content for the Custom CSS page. |
| 885 | 781 | * |
| 886 | 782 | * @param string $message |
| 887 | - * @param array $extra_args An array of extra arguments. | |
| 888 | - * | |
| 889 | 783 | * @return void |
| 890 | 784 | */ |
| 891 | - public static function custom_css( $message = '', $extra_args = array() ) { | |
| 892 | - $id = $extra_args['id'] ?? 'frm_codemirror_box'; | |
| 893 | - $settings = self::enqueue_codemirror( $id, $extra_args['placeholder'] ?? '' ); | |
| 894 | - $id = $settings ? $id : 'frm_custom_css_box'; | |
| 895 | - $show_errors = $extra_args['show_errors'] ?? true; | |
| 896 | - $custom_css = $extra_args['custom_css'] ?? self::get_custom_css(); | |
| 897 | - $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 | |
| 898 | - $textarea_params = ! empty( $extra_args['textarea_params'] ) ? $extra_args['textarea_params'] : array( | |
| 899 | - 'name' => 'frm_custom_css', | |
| 900 | - 'id' => $id, | |
| 901 | - ); | |
| 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(); | |
| 902 | 789 | |
| 903 | - if ( $settings ) { | |
| 904 | - $textarea_params['class'] = 'hide-if-js'; | |
| 905 | - } | |
| 906 | - | |
| 907 | 790 | include FrmAppHelper::plugin_path() . '/classes/views/styles/custom_css.php'; |
| 908 | 791 | } |
| 909 | 792 | |
| 910 | 793 | /** |
| @@ -911,33 +794,22 @@ | ||
| 911 | 794 | * Get custom CSS code entered in the Custom CSS page. |
| 912 | 795 | * |
| 913 | 796 | * @since 6.0 |
| 914 | 797 | * |
| 915 | - * @param array|null $single_style_settings The single style settings. | |
| 916 | - * | |
| 917 | 798 | * @return string |
| 918 | 799 | */ |
| 919 | - public static function get_custom_css( $single_style_settings = null ) { | |
| 920 | - if ( $single_style_settings ) { | |
| 921 | - // If the single style settings are passed, return the custom CSS from the single style settings. | |
| 922 | - if ( ! empty( $single_style_settings['single_style_custom_css'] ) && ! empty( $single_style_settings['enable_style_custom_css'] ) ) { | |
| 923 | - return $single_style_settings['single_style_custom_css']; | |
| 924 | - } | |
| 925 | - | |
| 926 | - return ''; | |
| 927 | - } | |
| 928 | - | |
| 800 | + public static function get_custom_css() { | |
| 929 | 801 | $settings = FrmAppHelper::get_settings(); |
| 930 | - | |
| 931 | 802 | if ( is_string( $settings->custom_css ) ) { |
| 932 | 803 | return $settings->custom_css; |
| 933 | 804 | } |
| 934 | 805 | |
| 935 | 806 | // If it does not exist, check the default style as a fallback. |
| 936 | - $frm_style = new FrmStyle(); | |
| 937 | - $style = $frm_style->get_default_style(); | |
| 807 | + $frm_style = new FrmStyle(); | |
| 808 | + $style = $frm_style->get_default_style(); | |
| 809 | + $custom_css = $style->post_content['custom_css']; | |
| 938 | 810 | |
| 939 | - return $style->post_content['custom_css']; | |
| 811 | + return $custom_css; | |
| 940 | 812 | } |
| 941 | 813 | |
| 942 | 814 | /** |
| 943 | 815 | * Enqueue assets for codemirror, built into WordPress since 4.9. |
| @@ -944,14 +816,11 @@ | ||
| 944 | 816 | * The Custom CSS page uses codemirror. |
| 945 | 817 | * |
| 946 | 818 | * @since 6.0 Previously this code was embedded in self::custom_css. |
| 947 | 819 | * |
| 948 | - * @param string $id The ID of the codemirror box. | |
| 949 | - * @param string $placeholder The placeholder text for the codemirror box. | |
| 950 | - * | |
| 951 | 820 | * @return array|false |
| 952 | 821 | */ |
| 953 | - private static function enqueue_codemirror( $id = 'frm_codemirror_box', $placeholder = '' ) { | |
| 822 | + private static function enqueue_codemirror() { | |
| 954 | 823 | if ( ! function_exists( 'wp_enqueue_code_editor' ) ) { |
| 955 | 824 | // The WordPress version is likely older than 4.9. |
| 956 | 825 | return false; |
| 957 | 826 | } |
| @@ -964,9 +833,8 @@ | ||
| 964 | 833 | 'tabSize' => 2, |
| 965 | 834 | // As the codemirror box only appears once you click into the Custom CSS tab, we need to auto-refresh. |
| 966 | 835 | // Otherwise the line numbers all end up with a 1px width causing overlap issues with the text in the content. |
| 967 | 836 | 'autoRefresh' => true, |
| 968 | - 'placeholder' => $placeholder, | |
| 969 | 837 | ), |
| 970 | 838 | ) |
| 971 | 839 | ); |
| 972 | 840 | |
| @@ -973,11 +841,9 @@ | ||
| 973 | 841 | if ( $settings ) { |
| 974 | 842 | wp_add_inline_script( |
| 975 | 843 | 'code-editor', |
| 976 | 844 | sprintf( |
| 977 | - 'jQuery( function() { window.%s_wp_editor = wp.codeEditor.initialize( \'%s\', %s ); } );', | |
| 978 | - $id, | |
| 979 | - $id, | |
| 845 | + 'jQuery( function() { wp.codeEditor.initialize( \'frm_codemirror_box\', %s ); } );', | |
| 980 | 846 | wp_json_encode( $settings ) |
| 981 | 847 | ) |
| 982 | 848 | ); |
| 983 | 849 | } |
| @@ -1029,14 +895,14 @@ | ||
| 1029 | 895 | FrmAppHelper::permission_check( 'frm_change_settings' ); |
| 1030 | 896 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 1031 | 897 | |
| 1032 | 898 | $style_id = FrmAppHelper::get_post_param( 'style_id', '', 'absint' ); |
| 1033 | - | |
| 1034 | 899 | if ( ! $style_id ) { |
| 1035 | 900 | // A style ID is not sent when resetting on the edit page. |
| 1036 | 901 | // Instead of resetting the style, send the defaults back so the inputs can be updated with JavaScript. |
| 1037 | 902 | $frm_style = new FrmStyle(); |
| 1038 | - echo json_encode( $frm_style->get_defaults() ); | |
| 903 | + $defaults = $frm_style->get_defaults(); | |
| 904 | + echo json_encode( $defaults ); | |
| 1039 | 905 | wp_die(); |
| 1040 | 906 | } |
| 1041 | 907 | |
| 1042 | 908 | $frm_style = new FrmStyle(); |
| @@ -1089,9 +955,9 @@ | ||
| 1089 | 955 | /** |
| 1090 | 956 | * @return void |
| 1091 | 957 | */ |
| 1092 | 958 | public static function add_meta_boxes() { |
| 1093 | - // Setup meta boxes | |
| 959 | + // setup meta boxes | |
| 1094 | 960 | $meta_boxes = array( |
| 1095 | 961 | 'general' => __( 'General', 'formidable' ), |
| 1096 | 962 | 'form-title' => __( 'Form Title', 'formidable' ), |
| 1097 | 963 | 'form-description' => __( 'Form Description', 'formidable' ), |
| @@ -1121,9 +987,8 @@ | ||
| 1121 | 987 | |
| 1122 | 988 | /** |
| 1123 | 989 | * @param array $atts |
| 1124 | 990 | * @param array $sec |
| 1125 | - * | |
| 1126 | 991 | * @return void |
| 1127 | 992 | */ |
| 1128 | 993 | public static function include_style_section( $atts, $sec ) { |
| 1129 | 994 | extract( $atts ); // phpcs:ignore WordPress.PHP.DontExtract |
| @@ -1194,10 +1059,9 @@ | ||
| 1194 | 1059 | * @return void |
| 1195 | 1060 | */ |
| 1196 | 1061 | public static function maybe_hide_sample_form_error_message() { |
| 1197 | 1062 | $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' ); |
| 1198 | - | |
| 1199 | - if ( str_contains( $referer, 'admin.php?page=formidable-styles' ) ) { | |
| 1063 | + if ( false !== strpos( $referer, 'admin.php?page=formidable-styles' ) ) { | |
| 1200 | 1064 | echo '#frm_broken_styles_warning { display: none; }'; |
| 1201 | 1065 | } |
| 1202 | 1066 | } |
| 1203 | 1067 | |
| @@ -1206,9 +1070,8 @@ | ||
| 1206 | 1070 | * |
| 1207 | 1071 | * @since 4.11.03 |
| 1208 | 1072 | * |
| 1209 | 1073 | * @param string $css CSS content. |
| 1210 | - * | |
| 1211 | 1074 | * @return string |
| 1212 | 1075 | */ |
| 1213 | 1076 | public static function replace_relative_url( $css ) { |
| 1214 | 1077 | $plugin_url = trailingslashit( FrmAppHelper::plugin_url() ); |
| @@ -1231,27 +1094,22 @@ | ||
| 1231 | 1094 | * Check if the Formidable styling should be loaded, |
| 1232 | 1095 | * then enqueue it for the footer |
| 1233 | 1096 | * |
| 1234 | 1097 | * @since 2.0 |
| 1235 | - * | |
| 1236 | - * @return void | |
| 1237 | 1098 | */ |
| 1238 | 1099 | public static function enqueue_style() { |
| 1239 | 1100 | global $frm_vars; |
| 1240 | 1101 | |
| 1241 | - if ( ! empty( $frm_vars['css_loaded'] ) ) { | |
| 1102 | + if ( isset( $frm_vars['css_loaded'] ) && $frm_vars['css_loaded'] ) { | |
| 1242 | 1103 | // The CSS has already been loaded. |
| 1243 | 1104 | return; |
| 1244 | 1105 | } |
| 1245 | 1106 | |
| 1246 | 1107 | $frm_settings = FrmAppHelper::get_settings(); |
| 1247 | - | |
| 1248 | - if ( $frm_settings->load_style === 'none' ) { | |
| 1249 | - return; | |
| 1108 | + if ( $frm_settings->load_style !== 'none' ) { | |
| 1109 | + wp_enqueue_style( 'formidable' ); | |
| 1110 | + $frm_vars['css_loaded'] = true; | |
| 1250 | 1111 | } |
| 1251 | - | |
| 1252 | - wp_enqueue_style( 'formidable' ); | |
| 1253 | - $frm_vars['css_loaded'] = true; | |
| 1254 | 1112 | } |
| 1255 | 1113 | |
| 1256 | 1114 | /** |
| 1257 | 1115 | * Get the stylesheets for the form settings page |
| @@ -1259,9 +1117,11 @@ | ||
| 1259 | 1117 | * @return array<WP_Post> |
| 1260 | 1118 | */ |
| 1261 | 1119 | public static function get_style_opts() { |
| 1262 | 1120 | $frm_style = new FrmStyle(); |
| 1263 | - return $frm_style->get_all(); | |
| 1121 | + $styles = $frm_style->get_all(); | |
| 1122 | + | |
| 1123 | + return $styles; | |
| 1264 | 1124 | } |
| 1265 | 1125 | |
| 1266 | 1126 | /** |
| 1267 | 1127 | * Get the style post object for a target form. |
| @@ -1266,16 +1126,14 @@ | ||
| 1266 | 1126 | /** |
| 1267 | 1127 | * Get the style post object for a target form. |
| 1268 | 1128 | * |
| 1269 | 1129 | * @param bool|object|string $form |
| 1270 | - * | |
| 1271 | 1130 | * @return WP_Post|null |
| 1272 | 1131 | */ |
| 1273 | 1132 | public static function get_form_style( $form = 'default' ) { |
| 1274 | 1133 | $style = FrmFormsHelper::get_form_style( $form ); |
| 1275 | 1134 | |
| 1276 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 1277 | - if ( ! $style || 1 == $style ) { | |
| 1135 | + if ( empty( $style ) || 1 == $style ) { | |
| 1278 | 1136 | $style = 'default'; |
| 1279 | 1137 | } |
| 1280 | 1138 | |
| 1281 | 1139 | $frm_style = new FrmStyle( $style ); |
| @@ -1282,59 +1140,12 @@ | ||
| 1282 | 1140 | return $frm_style->get_one(); |
| 1283 | 1141 | } |
| 1284 | 1142 | |
| 1285 | 1143 | /** |
| 1286 | - * Get the active style object for a field's form. | |
| 1287 | - * | |
| 1288 | - * @since 6.32 | |
| 1289 | - * | |
| 1290 | - * @param array|int $field The 'field' array. | |
| 1291 | - * | |
| 1292 | - * @return object | |
| 1293 | - */ | |
| 1294 | - public static function get_active_style( $field ) { | |
| 1295 | - if ( ! is_array( $field ) ) { | |
| 1296 | - return new stdClass(); | |
| 1297 | - } | |
| 1298 | - | |
| 1299 | - $form_id = $field['parent_form_id'] ?? $field['form_id']; | |
| 1300 | - | |
| 1301 | - if ( isset( self::$active_style[ $form_id ] ) ) { | |
| 1302 | - return self::$active_style[ $form_id ]; | |
| 1303 | - } | |
| 1304 | - | |
| 1305 | - $active_style = self::get_form_style( $form_id ); | |
| 1306 | - | |
| 1307 | - if ( ! is_object( $active_style ) ) { | |
| 1308 | - $active_style = new stdClass(); | |
| 1309 | - } | |
| 1310 | - | |
| 1311 | - self::$active_style[ $form_id ] = $active_style; | |
| 1312 | - | |
| 1313 | - return self::$active_style[ $form_id ]; | |
| 1314 | - } | |
| 1315 | - | |
| 1316 | - /** | |
| 1317 | - * Get the style setting key that stores the alignment for a field type. | |
| 1318 | - * | |
| 1319 | - * @since 6.32 | |
| 1320 | - * | |
| 1321 | - * @param string $field_type | |
| 1322 | - * | |
| 1323 | - * @return string | |
| 1324 | - */ | |
| 1325 | - public static function get_align_key_for_style_settings( $field_type ) { | |
| 1326 | - return 'checkbox' === $field_type ? 'check_align' : 'radio_align'; | |
| 1327 | - } | |
| 1328 | - | |
| 1329 | - /** | |
| 1330 | 1144 | * @param string $class |
| 1331 | 1145 | * @param string $style |
| 1332 | - * | |
| 1333 | - * @return string | |
| 1334 | 1146 | */ |
| 1335 | 1147 | public static function get_form_style_class( $class, $style ) { |
| 1336 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 1337 | 1148 | if ( 1 == $style ) { |
| 1338 | 1149 | $style = 'default'; |
| 1339 | 1150 | } |
| 1340 | 1151 | |
| @@ -1350,17 +1161,13 @@ | ||
| 1350 | 1161 | } |
| 1351 | 1162 | |
| 1352 | 1163 | /** |
| 1353 | 1164 | * @since 3.0 |
| 1354 | - * | |
| 1355 | 1165 | * @param object $style |
| 1356 | 1166 | * @param string $class |
| 1357 | - * | |
| 1358 | - * @return void | |
| 1359 | 1167 | */ |
| 1360 | 1168 | private static function maybe_add_rtl_class( $style, &$class ) { |
| 1361 | 1169 | $is_rtl = isset( $style->post_content['direction'] ) && 'rtl' === $style->post_content['direction']; |
| 1362 | - | |
| 1363 | 1170 | if ( $is_rtl ) { |
| 1364 | 1171 | $class .= ' frm_rtl'; |
| 1365 | 1172 | } |
| 1366 | 1173 | } |
| @@ -1365,28 +1172,17 @@ | ||
| 1365 | 1172 | } |
| 1366 | 1173 | } |
| 1367 | 1174 | |
| 1368 | 1175 | /** |
| 1369 | - * @param string $val Style setting key. | |
| 1370 | - * @param int|string $form Form ID or 'default'. | |
| 1371 | - * | |
| 1372 | - * @return mixed | |
| 1176 | + * @param string $val | |
| 1373 | 1177 | */ |
| 1374 | 1178 | public static function get_style_val( $val, $form = 'default' ) { |
| 1375 | 1179 | $style = self::get_form_style( $form ); |
| 1376 | - | |
| 1377 | 1180 | if ( $style && isset( $style->post_content[ $val ] ) ) { |
| 1378 | 1181 | return $style->post_content[ $val ]; |
| 1379 | 1182 | } |
| 1380 | - | |
| 1381 | - return null; | |
| 1382 | 1183 | } |
| 1383 | 1184 | |
| 1384 | - /** | |
| 1385 | - * @param array $default_styles | |
| 1386 | - * | |
| 1387 | - * @return array | |
| 1388 | - */ | |
| 1389 | 1185 | public static function show_entry_styles( $default_styles ) { |
| 1390 | 1186 | $frm_style = new FrmStyle( 'default' ); |
| 1391 | 1187 | $style = $frm_style->get_one(); |
| 1392 | 1188 | |
| @@ -1395,15 +1191,13 @@ | ||
| 1395 | 1191 | } |
| 1396 | 1192 | |
| 1397 | 1193 | foreach ( $default_styles as $name => $val ) { |
| 1398 | 1194 | $setting = $name; |
| 1399 | - | |
| 1400 | - if ( 'border_width' === $name ) { | |
| 1195 | + if ( 'border_width' == $name ) { | |
| 1401 | 1196 | $setting = 'field_border_width'; |
| 1402 | - } elseif ( 'alt_bg_color' === $name ) { | |
| 1197 | + } elseif ( 'alt_bg_color' == $name ) { | |
| 1403 | 1198 | $setting = 'bg_color_active'; |
| 1404 | 1199 | } |
| 1405 | - | |
| 1406 | 1200 | $default_styles[ $name ] = $style->post_content[ $setting ]; |
| 1407 | 1201 | unset( $name, $val ); |
| 1408 | 1202 | } |
| 1409 | 1203 | |
| @@ -1409,16 +1203,12 @@ | ||
| 1409 | 1203 | |
| 1410 | 1204 | return $default_styles; |
| 1411 | 1205 | } |
| 1412 | 1206 | |
| 1413 | - /** | |
| 1414 | - * @param string $important | |
| 1415 | - * @param array $field | |
| 1416 | - * | |
| 1417 | - * @return string | |
| 1418 | - */ | |
| 1419 | - public static function important_style( $important, $field ) { | |
| 1420 | - return self::get_style_val( 'important_style', $field['form_id'] ); | |
| 1207 | + public static function &important_style( $important, $field ) { | |
| 1208 | + $important = self::get_style_val( 'important_style', $field['form_id'] ); | |
| 1209 | + | |
| 1210 | + return $important; | |
| 1421 | 1211 | } |
| 1422 | 1212 | |
| 1423 | 1213 | /** |
| 1424 | 1214 | * Duplicate of WordPress do_accordion_section function, it adds an additional svg icon support. |
| @@ -1424,18 +1214,14 @@ | ||
| 1424 | 1214 | * Duplicate of WordPress do_accordion_section function, it adds an additional svg icon support. |
| 1425 | 1215 | * |
| 1426 | 1216 | * @since 6.8.3 |
| 1427 | 1217 | * |
| 1428 | - * @param string|WP_Screen $screen Screen ID or screen object. | |
| 1429 | - * @param string $context Meta box context. | |
| 1430 | - * @param mixed $data_object Data object passed to callbacks. | |
| 1431 | - * | |
| 1432 | 1218 | * @return int |
| 1433 | 1219 | */ |
| 1434 | - public static function do_accordion_sections( $screen, $context, $data_object ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh | |
| 1220 | + public static function do_accordion_sections( $screen, $context, $data_object ) { | |
| 1435 | 1221 | global $wp_meta_boxes; |
| 1436 | 1222 | |
| 1437 | - // The symbol id from icons.svg | |
| 1223 | + // the symbol id from icons.svg | |
| 1438 | 1224 | $icon_ids = array( |
| 1439 | 1225 | 'ranking-fields-style' => 'frm_chart_bar_icon', |
| 1440 | 1226 | 'section-fields-style' => 'frm-form-title-style', |
| 1441 | 1227 | ); |
| @@ -1441,9 +1227,9 @@ | ||
| 1441 | 1227 | ); |
| 1442 | 1228 | |
| 1443 | 1229 | wp_enqueue_script( 'accordion' ); |
| 1444 | 1230 | |
| 1445 | - if ( ! $screen ) { | |
| 1231 | + if ( empty( $screen ) ) { | |
| 1446 | 1232 | $screen = get_current_screen(); |
| 1447 | 1233 | } elseif ( is_string( $screen ) ) { |
| 1448 | 1234 | $screen = convert_to_screen( $screen ); |
| 1449 | 1235 | } |
| @@ -1449,9 +1235,8 @@ | ||
| 1449 | 1235 | } |
| 1450 | 1236 | |
| 1451 | 1237 | $page = $screen->id; |
| 1452 | 1238 | |
| 1453 | - // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 1454 | 1239 | ?> |
| 1455 | 1240 | <div id="side-sortables" class="accordion-container"> |
| 1456 | 1241 | <ul class="outer-border"> |
| 1457 | 1242 | <?php |
| @@ -1459,46 +1244,46 @@ | ||
| 1459 | 1244 | $first_open = false; |
| 1460 | 1245 | |
| 1461 | 1246 | if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) { |
| 1462 | 1247 | foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) { |
| 1463 | - if ( ! isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) { | |
| 1464 | - continue; | |
| 1465 | - } | |
| 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 | + } | |
| 1466 | 1253 | |
| 1467 | - foreach ( $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) { | |
| 1468 | - if ( false === $box || ! $box['title'] ) { | |
| 1469 | - continue; | |
| 1470 | - } | |
| 1254 | + ++$i; | |
| 1255 | + $icon_id = array_key_exists( $box['id'], $icon_ids ) ? $icon_ids[ $box['id'] ] : 'frm-' . $box['id']; | |
| 1471 | 1256 | |
| 1472 | - ++$i; | |
| 1473 | - $icon_id = array_key_exists( $box['id'], $icon_ids ) ? $icon_ids[ $box['id'] ] : 'frm-' . $box['id']; | |
| 1474 | - $open_class = ''; | |
| 1257 | + $open_class = ''; | |
| 1258 | + if ( ! $first_open ) { | |
| 1259 | + $first_open = true; | |
| 1260 | + $open_class = 'open'; | |
| 1261 | + } | |
| 1475 | 1262 | |
| 1476 | - if ( ! $first_open ) { | |
| 1477 | - $first_open = true; | |
| 1478 | - $open_class = 'open'; | |
| 1479 | - } | |
| 1480 | - | |
| 1481 | - $accordion_content_id = 'frm_style_section_' . $box['id']; | |
| 1482 | - ?> | |
| 1483 | - <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 ?> | |
| 1484 | - <h3 class="accordion-section-title hndle"> | |
| 1485 | - <?php | |
| 1486 | - FrmAppHelper::icon_by_class( 'frmfont ' . $icon_id . ' frm_svg24' ); | |
| 1487 | - echo esc_html( $box['title'] ); | |
| 1488 | - ?> | |
| 1489 | - <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 ?> | |
| 1490 | - <?php FrmAppHelper::icon_by_class( 'frmfont frm_arrowdown8_icon' ); ?> | |
| 1491 | - </button> | |
| 1492 | - </h3> | |
| 1493 | - <div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>" id="<?php echo esc_attr( $accordion_content_id ); ?>"> | |
| 1494 | - <div class="inside"> | |
| 1495 | - <?php call_user_func( $box['callback'], $data_object, $box ); ?> | |
| 1496 | - </div><!-- .inside --> | |
| 1497 | - </div><!-- .accordion-section-content --> | |
| 1498 | - </li><!-- .accordion-section --> | |
| 1499 | - <?php | |
| 1500 | - }//end foreach | |
| 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 ); | |
| 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 | |
| 1273 | + FrmAppHelper::icon_by_class( 'frmfont frm_arrowdown8_icon' ); | |
| 1274 | + ?> | |
| 1275 | + </button> | |
| 1276 | + </h3> | |
| 1277 | + <div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>" id="<?php echo esc_attr( $accordion_content_id ); ?>"> | |
| 1278 | + <div class="inside"> | |
| 1279 | + <?php call_user_func( $box['callback'], $data_object, $box ); ?> | |
| 1280 | + </div><!-- .inside --> | |
| 1281 | + </div><!-- .accordion-section-content --> | |
| 1282 | + </li><!-- .accordion-section --> | |
| 1283 | + <?php | |
| 1284 | + }//end foreach | |
| 1285 | + }//end if | |
| 1501 | 1286 | }//end foreach |
| 1502 | 1287 | }//end if |
| 1503 | 1288 | ?> |
| 1504 | 1289 | </ul><!-- .outer-border --> |
| @@ -1503,9 +1288,8 @@ | ||
| 1503 | 1288 | ?> |
| 1504 | 1289 | </ul><!-- .outer-border --> |
| 1505 | 1290 | </div><!-- .accordion-container --> |
| 1506 | 1291 | <?php |
| 1507 | - // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 1508 | 1292 | return $i; |
| 1509 | 1293 | } |
| 1510 | 1294 | |
| 1511 | 1295 | /** |
| @@ -1516,9 +1300,8 @@ | ||
| 1516 | 1300 | * @return void |
| 1517 | 1301 | */ |
| 1518 | 1302 | public static function rename_style() { |
| 1519 | 1303 | $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'nonce', 'frm_ajax' ); |
| 1520 | - | |
| 1521 | 1304 | if ( $permission_error !== false ) { |
| 1522 | 1305 | $data = array( |
| 1523 | 1306 | 'message' => __( 'Unable to rename style', 'formidable' ), |
| 1524 | 1307 | ); |
| @@ -1536,13 +1319,9 @@ | ||
| 1536 | 1319 | wp_send_json_error( $data, 400 ); |
| 1537 | 1320 | die(); |
| 1538 | 1321 | } |
| 1539 | 1322 | |
| 1540 | - /** | |
| 1541 | - * @var WP_Post|null $post | |
| 1542 | - */ | |
| 1543 | 1323 | $post = get_post( $style_id ); |
| 1544 | - | |
| 1545 | 1324 | if ( ! $post || $post->post_type !== self::$post_type ) { |
| 1546 | 1325 | $data = array( |
| 1547 | 1326 | 'message' => __( 'The style you are renaming either does not exist or it is not a style', 'formidable' ), |
| 1548 | 1327 | ); |
| @@ -1563,9 +1342,8 @@ | ||
| 1563 | 1342 | * |
| 1564 | 1343 | * @since 6.0 |
| 1565 | 1344 | * |
| 1566 | 1345 | * @param WP_Styles $styles |
| 1567 | - * | |
| 1568 | 1346 | * @return void |
| 1569 | 1347 | */ |
| 1570 | 1348 | public static function disable_conflicting_wp_admin_css( $styles ) { |
| 1571 | 1349 | if ( ! FrmAppHelper::is_style_editor_page() ) { |