| @@ -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. |
| @@ -110,9 +95,9 @@ | ||
| 110 | 95 | * |
| 111 | 96 | * @return void |
| 112 | 97 | */ |
| 113 | 98 | private static function disable_form_css() { |
| 114 | - add_filter( 'get_frm_stylesheet', '__return_empty_array' ); | |
| 99 | + add_filter( 'get_frm_stylesheet', '__return_false' ); | |
| 115 | 100 | } |
| 116 | 101 | |
| 117 | 102 | /** |
| 118 | 103 | * Removing this action prevents front end JavaScript from loading. |
| @@ -134,23 +119,22 @@ | ||
| 134 | 119 | if ( ! FrmAppHelper::is_style_editor_page() ) { |
| 135 | 120 | return; |
| 136 | 121 | } |
| 137 | 122 | |
| 138 | - FrmStyleComponent::register_assets(); | |
| 139 | 123 | self::load_pro_hooks(); |
| 140 | 124 | |
| 141 | 125 | $version = FrmAppHelper::plugin_version(); |
| 126 | + wp_enqueue_script( 'jquery-ui-datepicker' ); | |
| 142 | 127 | |
| 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,44 @@ | ||
| 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 | + if ( $frm_settings->use_html ) { | |
| 277 | + $tag = str_replace( ' type="', ' property="stylesheet" type="', $tag ); | |
| 278 | + } | |
| 302 | 279 | } |
| 303 | 280 | |
| 304 | 281 | return $tag; |
| 305 | 282 | } |
| @@ -347,39 +324,25 @@ | ||
| 347 | 324 | |
| 348 | 325 | self::setup_styles_and_scripts_for_styler(); |
| 349 | 326 | |
| 350 | 327 | $style_id = self::get_style_id_for_styler(); |
| 351 | - | |
| 352 | 328 | if ( ! $style_id ) { |
| 353 | - $error_args = array( | |
| 354 | - 'title' => __( 'No styles', 'formidable' ), | |
| 355 | - 'body' => __( 'You must have a style to use the Visual Styler.', 'formidable' ), | |
| 356 | - 'cancel_url' => admin_url( 'admin.php?page=formidable' ), | |
| 357 | - ); | |
| 358 | - FrmAppController::show_error_modal( $error_args ); | |
| 359 | - return; | |
| 329 | + wp_die( esc_html__( 'Invalid route', 'formidable' ), esc_html__( 'Invalid route', 'formidable' ), 400 ); | |
| 360 | 330 | } |
| 361 | 331 | |
| 362 | 332 | $form_id = FrmAppHelper::simple_get( 'form', 'absint', 0 ); |
| 363 | - | |
| 364 | 333 | if ( ! $form_id ) { |
| 365 | 334 | $form_id = self::get_form_id_for_style( $style_id ); |
| 366 | 335 | } |
| 367 | 336 | |
| 368 | 337 | $form = FrmForm::getOne( $form_id ); |
| 369 | - | |
| 370 | 338 | if ( ! is_object( $form ) ) { |
| 371 | - $error_args = array( | |
| 372 | - 'title' => __( 'No forms', 'formidable' ), | |
| 373 | - 'body' => __( 'You must have a form to use the Visual Styler.', 'formidable' ), | |
| 374 | - 'cancel_url' => admin_url( 'admin.php?page=formidable' ), | |
| 375 | - ); | |
| 376 | - FrmAppController::show_error_modal( $error_args ); | |
| 377 | - return; | |
| 339 | + wp_die( esc_html__( 'Invalid route', 'formidable' ), esc_html__( 'Invalid route', 'formidable' ), 400 ); | |
| 378 | 340 | } |
| 379 | 341 | |
| 380 | - $frm_style = new FrmStyle( $style_id ); | |
| 381 | - $active_style = $frm_style->get_one(); | |
| 342 | + $frm_style = new FrmStyle( $style_id ); | |
| 343 | + $active_style = $frm_style->get_one(); | |
| 344 | + $default_style = self::get_default_style(); | |
| 382 | 345 | |
| 383 | 346 | self::disable_admin_page_styling_on_submit_buttons(); |
| 384 | 347 | |
| 385 | 348 | /** |
| @@ -384,13 +347,15 @@ | ||
| 384 | 347 | |
| 385 | 348 | /** |
| 386 | 349 | * @since 6.0 |
| 387 | 350 | * |
| 388 | - * @param array{form:\stdClass} $data | |
| 351 | + * @param array { | |
| 352 | + * @type stdClass $form | |
| 353 | + * } | |
| 389 | 354 | */ |
| 390 | 355 | do_action( 'frm_before_render_style_page', compact( 'form' ) ); |
| 391 | 356 | |
| 392 | - self::render_style_page( $active_style, $form, self::get_default_style() ); | |
| 357 | + self::render_style_page( $active_style, $form, $default_style ); | |
| 393 | 358 | } |
| 394 | 359 | |
| 395 | 360 | /** |
| 396 | 361 | * @since 6.0 |
| @@ -398,9 +363,8 @@ | ||
| 398 | 363 | * @return int |
| 399 | 364 | */ |
| 400 | 365 | private static function get_style_id_for_styler() { |
| 401 | 366 | $action = FrmAppHelper::simple_get( 'frm_action' ); |
| 402 | - | |
| 403 | 367 | if ( 'duplicate' === $action ) { |
| 404 | 368 | // The duplicate action uses style_id instead of id for better backward compatibility. |
| 405 | 369 | return FrmAppHelper::simple_get( 'style_id', 'absint', 0 ); |
| 406 | 370 | } |
| @@ -405,9 +369,8 @@ | ||
| 405 | 369 | return FrmAppHelper::simple_get( 'style_id', 'absint', 0 ); |
| 406 | 370 | } |
| 407 | 371 | |
| 408 | 372 | $style_id = FrmAppHelper::simple_get( 'id', 'absint', 0 ); |
| 409 | - | |
| 410 | 373 | if ( $style_id ) { |
| 411 | 374 | // Always use the style ID from the URL if one is specified. |
| 412 | 375 | return $style_id; |
| 413 | 376 | } |
| @@ -412,9 +375,8 @@ | ||
| 412 | 375 | return $style_id; |
| 413 | 376 | } |
| 414 | 377 | |
| 415 | 378 | $request_form_id = FrmAppHelper::simple_get( 'form', 'absint', 0 ); |
| 416 | - | |
| 417 | 379 | if ( $request_form_id && is_callable( 'FrmProStylesController::get_active_style_for_form' ) ) { |
| 418 | 380 | return FrmProStylesController::get_active_style_for_form( $request_form_id )->ID; |
| 419 | 381 | } |
| 420 | 382 | |
| @@ -426,9 +388,8 @@ | ||
| 426 | 388 | * |
| 427 | 389 | * @since 6.0 |
| 428 | 390 | * |
| 429 | 391 | * @param int $style_id |
| 430 | - * | |
| 431 | 392 | * @return int |
| 432 | 393 | */ |
| 433 | 394 | private static function get_form_id_for_style( $style_id ) { |
| 434 | 395 | $check = serialize( array( 'custom_style' => (string) $style_id ) ); |
| @@ -441,8 +402,9 @@ | ||
| 441 | 402 | ) |
| 442 | 403 | ); |
| 443 | 404 | |
| 444 | 405 | if ( ! $form_id ) { |
| 406 | + // TODO: Show a message why a random form is being shown (because no form is assigned to the style). | |
| 445 | 407 | // Fallback to any form. |
| 446 | 408 | $where = array( |
| 447 | 409 | 'status' => 'published', |
| 448 | 410 | // Make sure it's not a repeater. |
| @@ -474,10 +436,11 @@ | ||
| 474 | 436 | * |
| 475 | 437 | * @return WP_Post |
| 476 | 438 | */ |
| 477 | 439 | private static function get_default_style() { |
| 478 | - $frm_style = new FrmStyle( 'default' ); | |
| 479 | - return $frm_style->get_one(); | |
| 440 | + $frm_style = new FrmStyle( 'default' ); | |
| 441 | + $default_style = $frm_style->get_one(); | |
| 442 | + return $default_style; | |
| 480 | 443 | } |
| 481 | 444 | |
| 482 | 445 | /** |
| 483 | 446 | * Save style for form (from Styler list page) via a POST action. |
| @@ -487,15 +450,13 @@ | ||
| 487 | 450 | * @return void |
| 488 | 451 | */ |
| 489 | 452 | private static function save_form_style() { |
| 490 | 453 | $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'frm_save_form_style', 'frm_save_form_style_nonce' ); |
| 491 | - | |
| 492 | 454 | if ( $permission_error !== false ) { |
| 493 | 455 | wp_die( 'Unable to save form', '', 403 ); |
| 494 | 456 | } |
| 495 | 457 | |
| 496 | 458 | $style_id = FrmAppHelper::get_post_param( 'style_id', 0, 'absint' ); |
| 497 | - | |
| 498 | 459 | if ( $style_id && ! self::confirm_style_exists_before_setting( $style_id ) ) { |
| 499 | 460 | wp_die( esc_html__( 'Invalid target style', 'formidable' ), esc_html__( 'Invalid target style', 'formidable' ), 400 ); |
| 500 | 461 | return; |
| 501 | 462 | } |
| @@ -515,9 +476,8 @@ | ||
| 515 | 476 | return; |
| 516 | 477 | } |
| 517 | 478 | |
| 518 | 479 | $form_id = FrmAppHelper::get_post_param( 'form_id', 0, 'absint' ); |
| 519 | - | |
| 520 | 480 | if ( ! $form_id ) { |
| 521 | 481 | wp_die( esc_html__( 'No form specified', 'formidable' ), esc_html__( 'No form specified', 'formidable' ), 400 ); |
| 522 | 482 | return; |
| 523 | 483 | } |
| @@ -522,21 +482,18 @@ | ||
| 522 | 482 | return; |
| 523 | 483 | } |
| 524 | 484 | |
| 525 | 485 | $form = FrmForm::getOne( $form_id ); |
| 526 | - | |
| 527 | 486 | if ( ! $form ) { |
| 528 | 487 | wp_die( esc_html__( 'Form does not exist', 'formidable' ), esc_html__( 'Form does not exist', 'formidable' ), 400 ); |
| 529 | 488 | return; |
| 530 | 489 | } |
| 531 | 490 | |
| 532 | - $previous_style_id = $form->options['custom_style']; | |
| 533 | - | |
| 534 | 491 | // If the default style is selected, use the "Always use default" legacy option instead of the default style. |
| 535 | 492 | // There's also a check here for conversational forms. |
| 536 | 493 | // 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'] ) ) { | |
| 494 | + $default_style = self::get_default_style(); | |
| 495 | + if ( $style_id === $default_style->ID && empty( $form->options['chat'] ) ) { | |
| 539 | 496 | $style_id = 1; |
| 540 | 497 | } |
| 541 | 498 | |
| 542 | 499 | // We want to save a string for consistency. FrmStylesHelper::get_form_count_for_style expects the custom style ID is a string. |
| @@ -541,27 +498,13 @@ | ||
| 541 | 498 | |
| 542 | 499 | // We want to save a string for consistency. FrmStylesHelper::get_form_count_for_style expects the custom style ID is a string. |
| 543 | 500 | $form->options['custom_style'] = (string) $style_id; |
| 544 | 501 | |
| 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 | 502 | global $wpdb; |
| 552 | 503 | $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $form->options ) ), array( 'id' => $form->id ) ); |
| 553 | 504 | |
| 554 | 505 | FrmForm::clear_form_cache(); |
| 555 | 506 | |
| 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 | 507 | self::$message = __( 'Successfully updated style.', 'formidable' ); |
| 565 | 508 | } |
| 566 | 509 | |
| 567 | 510 | /** |
| @@ -567,9 +510,8 @@ | ||
| 567 | 510 | /** |
| 568 | 511 | * Validate that we're assigning a form to a style that actually exists before assigning it to a form. |
| 569 | 512 | * |
| 570 | 513 | * @param int $style_id |
| 571 | - * | |
| 572 | 514 | * @return bool True if the style actually exists. |
| 573 | 515 | */ |
| 574 | 516 | private static function confirm_style_exists_before_setting( $style_id ) { |
| 575 | 517 | global $wpdb; |
| @@ -588,9 +530,9 @@ | ||
| 588 | 530 | $plugin_url = FrmAppHelper::plugin_url(); |
| 589 | 531 | $version = FrmAppHelper::plugin_version(); |
| 590 | 532 | $js_dependencies = array( 'wp-i18n', 'wp-hooks', 'formidable_dom' ); |
| 591 | 533 | |
| 592 | - if ( FrmAppHelper::pro_is_installed() && is_callable( 'FrmProAppHelper::use_jquery_datepicker' ) && FrmProAppHelper::use_jquery_datepicker() ) { | |
| 534 | + if ( FrmAppHelper::pro_is_installed() ) { | |
| 593 | 535 | $js_dependencies[] = 'jquery-ui-datepicker'; |
| 594 | 536 | } |
| 595 | 537 | |
| 596 | 538 | wp_register_script( 'formidable_style', $plugin_url . '/js/admin/style.js', $js_dependencies, $version ); |
| @@ -609,9 +551,8 @@ | ||
| 609 | 551 | * |
| 610 | 552 | * @param stdClass|WP_Post $active_style |
| 611 | 553 | * @param stdClass $form |
| 612 | 554 | * @param WP_Post $default_style |
| 613 | - * | |
| 614 | 555 | * @return void |
| 615 | 556 | */ |
| 616 | 557 | private static function render_style_page( $active_style, $form, $default_style ) { |
| 617 | 558 | $style_views_path = self::get_views_path(); |
| @@ -633,44 +574,22 @@ | ||
| 633 | 574 | $style = $active_style; |
| 634 | 575 | break; |
| 635 | 576 | |
| 636 | 577 | 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 | - | |
| 578 | + $style = clone $active_style; | |
| 579 | + $new_style = $frm_style->get_new(); | |
| 649 | 580 | $style->ID = $new_style->ID; |
| 650 | - $style->post_name = $new_name; | |
| 651 | - unset( $new_style, $new_name ); | |
| 581 | + $style->post_name = $new_style->post_name; | |
| 582 | + unset( $new_style ); | |
| 652 | 583 | break; |
| 653 | 584 | |
| 654 | 585 | case 'new_style': |
| 655 | - $style = $frm_style->get_new(); | |
| 656 | - $style->post_name = self::get_new_style_post_name( $style->post_name ); | |
| 586 | + $style = $frm_style->get_new(); | |
| 657 | 587 | break; |
| 658 | - }//end switch | |
| 588 | + } | |
| 659 | 589 | |
| 660 | 590 | 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' ); | |
| 591 | + $style->post_title = FrmAppHelper::simple_get( 'style_name' ); | |
| 673 | 592 | $style->menu_order = 0; |
| 674 | 593 | } |
| 675 | 594 | |
| 676 | 595 | if ( ! isset( $style ) ) { |
| @@ -694,27 +613,8 @@ | ||
| 694 | 613 | include $style_views_path . 'show.php'; |
| 695 | 614 | } |
| 696 | 615 | |
| 697 | 616 | /** |
| 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 | 617 | * @since 6.0 |
| 718 | 618 | * |
| 719 | 619 | * @return string |
| 720 | 620 | */ |
| @@ -727,9 +627,8 @@ | ||
| 727 | 627 | * |
| 728 | 628 | * @since 6.0 |
| 729 | 629 | * |
| 730 | 630 | * @param stdClass|WP_Post $style A new style is not a WP_Post object. |
| 731 | - * | |
| 732 | 631 | * @return void |
| 733 | 632 | */ |
| 734 | 633 | private static function force_form_style( $style ) { |
| 735 | 634 | add_filter( |
| @@ -740,9 +639,9 @@ | ||
| 740 | 639 | /** |
| 741 | 640 | * @param string $class |
| 742 | 641 | */ |
| 743 | 642 | function ( $class ) { |
| 744 | - return $class && ! str_starts_with( $class, 'frm_style_' ); | |
| 643 | + return $class && 0 !== strpos( $class, 'frm_style_' ); | |
| 745 | 644 | } |
| 746 | 645 | ); |
| 747 | 646 | $split[] = 'frm_style_' . $style->post_name; |
| 748 | 647 | return implode( ' ', $split ); |
| @@ -757,10 +656,8 @@ | ||
| 757 | 656 | * |
| 758 | 657 | * @return void |
| 759 | 658 | */ |
| 760 | 659 | public static function save_style() { |
| 761 | - FrmAppHelper::permission_check( 'frm_change_settings' ); | |
| 762 | - | |
| 763 | 660 | $frm_style = new FrmStyle(); |
| 764 | 661 | $post_id = FrmAppHelper::get_post_param( 'ID', false, 'sanitize_title' ); |
| 765 | 662 | $style_nonce = FrmAppHelper::get_post_param( 'frm_style', '', 'sanitize_text_field' ); |
| 766 | 663 | |
| @@ -770,9 +667,8 @@ | ||
| 770 | 667 | return; |
| 771 | 668 | } |
| 772 | 669 | |
| 773 | 670 | $id = $frm_style->update( $post_id ); |
| 774 | - | |
| 775 | 671 | if ( ! $post_id && $id ) { |
| 776 | 672 | self::maybe_redirect_after_save( $id ); |
| 777 | 673 | // Set the post id to the new style so it will be loaded for editing. |
| 778 | 674 | $post_id = reset( $id ); |
| @@ -777,15 +673,8 @@ | ||
| 777 | 673 | // Set the post id to the new style so it will be loaded for editing. |
| 778 | 674 | $post_id = reset( $id ); |
| 779 | 675 | } |
| 780 | 676 | |
| 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 | 677 | self::$message = __( 'Your styling settings have been saved.', 'formidable' ); |
| 789 | 678 | } |
| 790 | 679 | |
| 791 | 680 | /** |
| @@ -804,20 +693,19 @@ | ||
| 804 | 693 | * |
| 805 | 694 | * @since 6.0 |
| 806 | 695 | * |
| 807 | 696 | * @param array $ids |
| 808 | - * | |
| 809 | 697 | * @return void |
| 810 | 698 | */ |
| 811 | 699 | 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']; | |
| 700 | + $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' ); | |
| 701 | + $parsed = parse_url( $referer ); | |
| 702 | + $query = $parsed['query']; | |
| 703 | + | |
| 815 | 704 | $current_action = false; |
| 816 | 705 | $actions_to_redirect = array( 'duplicate', 'new_style' ); |
| 817 | - | |
| 818 | 706 | foreach ( $actions_to_redirect as $action ) { |
| 819 | - if ( str_contains( $query, 'frm_action=' . $action ) ) { | |
| 707 | + if ( false !== strpos( $query, 'frm_action=' . $action ) ) { | |
| 820 | 708 | $current_action = $action; |
| 821 | 709 | break; |
| 822 | 710 | } |
| 823 | 711 | } |
| @@ -827,9 +715,10 @@ | ||
| 827 | 715 | return; |
| 828 | 716 | } |
| 829 | 717 | |
| 830 | 718 | parse_str( $query, $parsed_query ); |
| 831 | - $form_id = ! empty( $parsed_query['form'] ) ? absint( $parsed_query['form'] ) : 0; | |
| 719 | + $form_id = ! empty( $parsed_query['form'] ) ? absint( $parsed_query['form'] ) : 0; | |
| 720 | + | |
| 832 | 721 | $style = new stdClass(); |
| 833 | 722 | $style->ID = end( $ids ); |
| 834 | 723 | wp_safe_redirect( esc_url_raw( FrmStylesHelper::get_edit_url( $style, $form_id ) ) ); |
| 835 | 724 | die(); |
| @@ -839,9 +728,8 @@ | ||
| 839 | 728 | * @since 6.0 |
| 840 | 729 | * |
| 841 | 730 | * @param string $message |
| 842 | 731 | * @param array|object $forms |
| 843 | - * | |
| 844 | 732 | * @return void |
| 845 | 733 | */ |
| 846 | 734 | public static function manage( $message = '', $forms = array() ) { |
| 847 | 735 | $frm_style = new FrmStyle(); |
| @@ -846,9 +734,8 @@ | ||
| 846 | 734 | public static function manage( $message = '', $forms = array() ) { |
| 847 | 735 | $frm_style = new FrmStyle(); |
| 848 | 736 | $styles = $frm_style->get_all(); |
| 849 | 737 | $default_style = $frm_style->get_default_style( $styles ); |
| 850 | - $frm_settings = FrmAppHelper::get_settings(); | |
| 851 | 738 | |
| 852 | 739 | if ( ! $forms ) { |
| 853 | 740 | $forms = FrmForm::get_published_forms(); |
| 854 | 741 | } |
| @@ -865,16 +752,15 @@ | ||
| 865 | 752 | private static function manage_styles() { |
| 866 | 753 | global $wpdb; |
| 867 | 754 | |
| 868 | 755 | $forms = FrmForm::get_published_forms(); |
| 869 | - | |
| 870 | 756 | foreach ( $forms as $form ) { |
| 871 | - if ( ! isset( $_POST['style'] ) || ! isset( $_POST['style'][ $form->id ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 757 | + $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 | |
| 758 | + $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 | |
| 759 | + if ( $new_style == $previous_style ) { | |
| 872 | 760 | continue; |
| 873 | 761 | } |
| 874 | 762 | |
| 875 | - $new_style = sanitize_text_field( wp_unslash( $_POST['style'][ $form->id ] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 876 | - | |
| 877 | 763 | $form->options['custom_style'] = $new_style; |
| 878 | 764 | $wpdb->update( $wpdb->prefix . 'frm_forms', array( 'options' => maybe_serialize( $form->options ) ), array( 'id' => $form->id ) ); |
| 879 | 765 | unset( $form ); |
| 880 | 766 | } |
| @@ -883,28 +769,15 @@ | ||
| 883 | 769 | /** |
| 884 | 770 | * Echo content for the Custom CSS page. |
| 885 | 771 | * |
| 886 | 772 | * @param string $message |
| 887 | - * @param array $extra_args An array of extra arguments. | |
| 888 | - * | |
| 889 | 773 | * @return void |
| 890 | 774 | */ |
| 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 | - ); | |
| 775 | + public static function custom_css( $message = '' ) { | |
| 776 | + $settings = self::enqueue_codemirror(); | |
| 777 | + $id = $settings ? 'frm_codemirror_box' : 'frm_custom_css_box'; | |
| 778 | + $custom_css = self::get_custom_css(); | |
| 902 | 779 | |
| 903 | - if ( $settings ) { | |
| 904 | - $textarea_params['class'] = 'hide-if-js'; | |
| 905 | - } | |
| 906 | - | |
| 907 | 780 | include FrmAppHelper::plugin_path() . '/classes/views/styles/custom_css.php'; |
| 908 | 781 | } |
| 909 | 782 | |
| 910 | 783 | /** |
| @@ -911,33 +784,22 @@ | ||
| 911 | 784 | * Get custom CSS code entered in the Custom CSS page. |
| 912 | 785 | * |
| 913 | 786 | * @since 6.0 |
| 914 | 787 | * |
| 915 | - * @param array|null $single_style_settings The single style settings. | |
| 916 | - * | |
| 917 | 788 | * @return string |
| 918 | 789 | */ |
| 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 | - | |
| 790 | + public static function get_custom_css() { | |
| 929 | 791 | $settings = FrmAppHelper::get_settings(); |
| 930 | - | |
| 931 | 792 | if ( is_string( $settings->custom_css ) ) { |
| 932 | 793 | return $settings->custom_css; |
| 933 | 794 | } |
| 934 | 795 | |
| 935 | 796 | // If it does not exist, check the default style as a fallback. |
| 936 | - $frm_style = new FrmStyle(); | |
| 937 | - $style = $frm_style->get_default_style(); | |
| 797 | + $frm_style = new FrmStyle(); | |
| 798 | + $style = $frm_style->get_default_style(); | |
| 799 | + $custom_css = $style->post_content['custom_css']; | |
| 938 | 800 | |
| 939 | - return $style->post_content['custom_css']; | |
| 801 | + return $custom_css; | |
| 940 | 802 | } |
| 941 | 803 | |
| 942 | 804 | /** |
| 943 | 805 | * Enqueue assets for codemirror, built into WordPress since 4.9. |
| @@ -944,14 +806,11 @@ | ||
| 944 | 806 | * The Custom CSS page uses codemirror. |
| 945 | 807 | * |
| 946 | 808 | * @since 6.0 Previously this code was embedded in self::custom_css. |
| 947 | 809 | * |
| 948 | - * @param string $id The ID of the codemirror box. | |
| 949 | - * @param string $placeholder The placeholder text for the codemirror box. | |
| 950 | - * | |
| 951 | 810 | * @return array|false |
| 952 | 811 | */ |
| 953 | - private static function enqueue_codemirror( $id = 'frm_codemirror_box', $placeholder = '' ) { | |
| 812 | + private static function enqueue_codemirror() { | |
| 954 | 813 | if ( ! function_exists( 'wp_enqueue_code_editor' ) ) { |
| 955 | 814 | // The WordPress version is likely older than 4.9. |
| 956 | 815 | return false; |
| 957 | 816 | } |
| @@ -964,9 +823,8 @@ | ||
| 964 | 823 | 'tabSize' => 2, |
| 965 | 824 | // As the codemirror box only appears once you click into the Custom CSS tab, we need to auto-refresh. |
| 966 | 825 | // Otherwise the line numbers all end up with a 1px width causing overlap issues with the text in the content. |
| 967 | 826 | 'autoRefresh' => true, |
| 968 | - 'placeholder' => $placeholder, | |
| 969 | 827 | ), |
| 970 | 828 | ) |
| 971 | 829 | ); |
| 972 | 830 | |
| @@ -973,11 +831,9 @@ | ||
| 973 | 831 | if ( $settings ) { |
| 974 | 832 | wp_add_inline_script( |
| 975 | 833 | 'code-editor', |
| 976 | 834 | sprintf( |
| 977 | - 'jQuery( function() { window.%s_wp_editor = wp.codeEditor.initialize( \'%s\', %s ); } );', | |
| 978 | - $id, | |
| 979 | - $id, | |
| 835 | + 'jQuery( function() { wp.codeEditor.initialize( \'frm_codemirror_box\', %s ); } );', | |
| 980 | 836 | wp_json_encode( $settings ) |
| 981 | 837 | ) |
| 982 | 838 | ); |
| 983 | 839 | } |
| @@ -1029,35 +885,32 @@ | ||
| 1029 | 885 | FrmAppHelper::permission_check( 'frm_change_settings' ); |
| 1030 | 886 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 1031 | 887 | |
| 1032 | 888 | $style_id = FrmAppHelper::get_post_param( 'style_id', '', 'absint' ); |
| 1033 | - | |
| 1034 | 889 | if ( ! $style_id ) { |
| 1035 | 890 | // A style ID is not sent when resetting on the edit page. |
| 1036 | 891 | // Instead of resetting the style, send the defaults back so the inputs can be updated with JavaScript. |
| 1037 | 892 | $frm_style = new FrmStyle(); |
| 1038 | - echo json_encode( $frm_style->get_defaults() ); | |
| 893 | + $defaults = $frm_style->get_defaults(); | |
| 894 | + echo json_encode( $defaults ); | |
| 1039 | 895 | wp_die(); |
| 1040 | 896 | } |
| 1041 | 897 | |
| 1042 | - $frm_style = new FrmStyle(); | |
| 1043 | - $default_template_style = $frm_style->get_default_template_style( $style_id ); | |
| 1044 | - $where = array( | |
| 898 | + $frm_style = new FrmStyle(); | |
| 899 | + $defaults = $frm_style->get_defaults(); | |
| 900 | + $default_post_content = FrmAppHelper::prepare_and_encode( $defaults ); | |
| 901 | + $where = array( | |
| 1045 | 902 | 'ID' => $style_id, |
| 1046 | 903 | 'post_type' => self::$post_type, |
| 1047 | 904 | ); |
| 1048 | - | |
| 1049 | - $style_object = $frm_style->get_new(); | |
| 1050 | - $style_object->post_content = json_decode( $default_template_style, true ); | |
| 1051 | - | |
| 1052 | 905 | global $wpdb; |
| 1053 | - $wpdb->update( $wpdb->posts, array( 'post_content' => $default_template_style ), $where ); | |
| 906 | + $wpdb->update( $wpdb->posts, array( 'post_content' => $default_post_content ), $where ); | |
| 1054 | 907 | |
| 1055 | 908 | // Save the settings after resetting to default or the old style will still appear. |
| 1056 | 909 | $frm_style->save_settings(); |
| 1057 | 910 | |
| 1058 | 911 | $data = array( |
| 1059 | - 'style' => FrmStylesCardHelper::get_style_param_for_card( $style_object ), | |
| 912 | + 'style' => FrmStylesCardHelper::get_style_param_for_card( $frm_style->get_new() ), | |
| 1060 | 913 | ); |
| 1061 | 914 | wp_send_json_success( $data ); |
| 1062 | 915 | wp_die(); |
| 1063 | 916 | } |
| @@ -1072,10 +925,9 @@ | ||
| 1072 | 925 | public static function change_styling() { |
| 1073 | 926 | FrmAppHelper::permission_check( 'frm_change_settings' ); |
| 1074 | 927 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 1075 | 928 | |
| 1076 | - $is_loaded_via_ajax = true; | |
| 1077 | - $frm_style = new FrmStyle(); | |
| 929 | + $frm_style = new FrmStyle(); | |
| 1078 | 930 | |
| 1079 | 931 | // Intentionally avoid defaults here so nothing gets removed from our style. |
| 1080 | 932 | $defaults = array(); |
| 1081 | 933 | $style = ''; |
| @@ -1089,9 +941,9 @@ | ||
| 1089 | 941 | /** |
| 1090 | 942 | * @return void |
| 1091 | 943 | */ |
| 1092 | 944 | public static function add_meta_boxes() { |
| 1093 | - // Setup meta boxes | |
| 945 | + // setup meta boxes | |
| 1094 | 946 | $meta_boxes = array( |
| 1095 | 947 | 'general' => __( 'General', 'formidable' ), |
| 1096 | 948 | 'form-title' => __( 'Form Title', 'formidable' ), |
| 1097 | 949 | 'form-description' => __( 'Form Description', 'formidable' ), |
| @@ -1121,9 +973,8 @@ | ||
| 1121 | 973 | |
| 1122 | 974 | /** |
| 1123 | 975 | * @param array $atts |
| 1124 | 976 | * @param array $sec |
| 1125 | - * | |
| 1126 | 977 | * @return void |
| 1127 | 978 | */ |
| 1128 | 979 | public static function include_style_section( $atts, $sec ) { |
| 1129 | 980 | extract( $atts ); // phpcs:ignore WordPress.PHP.DontExtract |
| @@ -1186,9 +1037,9 @@ | ||
| 1186 | 1037 | } |
| 1187 | 1038 | |
| 1188 | 1039 | /** |
| 1189 | 1040 | * Add an extra style rule to hide a broken style warning. |
| 1190 | - * To avoid cluttering the front end with any unnecessary styles this is only added when the referer URL matches the styler. | |
| 1041 | + * To avoid cluttering the front end with any unecessary styles this is only added when the referer URL matches the styler. | |
| 1191 | 1042 | * |
| 1192 | 1043 | * @since 6.2.3 |
| 1193 | 1044 | * |
| 1194 | 1045 | * @return void |
| @@ -1194,10 +1045,9 @@ | ||
| 1194 | 1045 | * @return void |
| 1195 | 1046 | */ |
| 1196 | 1047 | public static function maybe_hide_sample_form_error_message() { |
| 1197 | 1048 | $referer = FrmAppHelper::get_server_value( 'HTTP_REFERER' ); |
| 1198 | - | |
| 1199 | - if ( str_contains( $referer, 'admin.php?page=formidable-styles' ) ) { | |
| 1049 | + if ( false !== strpos( $referer, 'admin.php?page=formidable-styles' ) ) { | |
| 1200 | 1050 | echo '#frm_broken_styles_warning { display: none; }'; |
| 1201 | 1051 | } |
| 1202 | 1052 | } |
| 1203 | 1053 | |
| @@ -1206,9 +1056,8 @@ | ||
| 1206 | 1056 | * |
| 1207 | 1057 | * @since 4.11.03 |
| 1208 | 1058 | * |
| 1209 | 1059 | * @param string $css CSS content. |
| 1210 | - * | |
| 1211 | 1060 | * @return string |
| 1212 | 1061 | */ |
| 1213 | 1062 | public static function replace_relative_url( $css ) { |
| 1214 | 1063 | $plugin_url = trailingslashit( FrmAppHelper::plugin_url() ); |
| @@ -1231,27 +1080,22 @@ | ||
| 1231 | 1080 | * Check if the Formidable styling should be loaded, |
| 1232 | 1081 | * then enqueue it for the footer |
| 1233 | 1082 | * |
| 1234 | 1083 | * @since 2.0 |
| 1235 | - * | |
| 1236 | - * @return void | |
| 1237 | 1084 | */ |
| 1238 | 1085 | public static function enqueue_style() { |
| 1239 | 1086 | global $frm_vars; |
| 1240 | 1087 | |
| 1241 | - if ( ! empty( $frm_vars['css_loaded'] ) ) { | |
| 1088 | + if ( isset( $frm_vars['css_loaded'] ) && $frm_vars['css_loaded'] ) { | |
| 1242 | 1089 | // The CSS has already been loaded. |
| 1243 | 1090 | return; |
| 1244 | 1091 | } |
| 1245 | 1092 | |
| 1246 | 1093 | $frm_settings = FrmAppHelper::get_settings(); |
| 1247 | - | |
| 1248 | - if ( $frm_settings->load_style === 'none' ) { | |
| 1249 | - return; | |
| 1094 | + if ( $frm_settings->load_style !== 'none' ) { | |
| 1095 | + wp_enqueue_style( 'formidable' ); | |
| 1096 | + $frm_vars['css_loaded'] = true; | |
| 1250 | 1097 | } |
| 1251 | - | |
| 1252 | - wp_enqueue_style( 'formidable' ); | |
| 1253 | - $frm_vars['css_loaded'] = true; | |
| 1254 | 1098 | } |
| 1255 | 1099 | |
| 1256 | 1100 | /** |
| 1257 | 1101 | * Get the stylesheets for the form settings page |
| @@ -1259,9 +1103,11 @@ | ||
| 1259 | 1103 | * @return array<WP_Post> |
| 1260 | 1104 | */ |
| 1261 | 1105 | public static function get_style_opts() { |
| 1262 | 1106 | $frm_style = new FrmStyle(); |
| 1263 | - return $frm_style->get_all(); | |
| 1107 | + $styles = $frm_style->get_all(); | |
| 1108 | + | |
| 1109 | + return $styles; | |
| 1264 | 1110 | } |
| 1265 | 1111 | |
| 1266 | 1112 | /** |
| 1267 | 1113 | * Get the style post object for a target form. |
| @@ -1266,16 +1112,14 @@ | ||
| 1266 | 1112 | /** |
| 1267 | 1113 | * Get the style post object for a target form. |
| 1268 | 1114 | * |
| 1269 | 1115 | * @param bool|object|string $form |
| 1270 | - * | |
| 1271 | 1116 | * @return WP_Post|null |
| 1272 | 1117 | */ |
| 1273 | 1118 | public static function get_form_style( $form = 'default' ) { |
| 1274 | 1119 | $style = FrmFormsHelper::get_form_style( $form ); |
| 1275 | 1120 | |
| 1276 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 1277 | - if ( ! $style || 1 == $style ) { | |
| 1121 | + if ( empty( $style ) || 1 == $style ) { | |
| 1278 | 1122 | $style = 'default'; |
| 1279 | 1123 | } |
| 1280 | 1124 | |
| 1281 | 1125 | $frm_style = new FrmStyle( $style ); |
| @@ -1282,59 +1126,12 @@ | ||
| 1282 | 1126 | return $frm_style->get_one(); |
| 1283 | 1127 | } |
| 1284 | 1128 | |
| 1285 | 1129 | /** |
| 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 | 1130 | * @param string $class |
| 1331 | 1131 | * @param string $style |
| 1332 | - * | |
| 1333 | - * @return string | |
| 1334 | 1132 | */ |
| 1335 | 1133 | public static function get_form_style_class( $class, $style ) { |
| 1336 | - // phpcs:ignore Universal.Operators.StrictComparisons | |
| 1337 | 1134 | if ( 1 == $style ) { |
| 1338 | 1135 | $style = 'default'; |
| 1339 | 1136 | } |
| 1340 | 1137 | |
| @@ -1350,17 +1147,13 @@ | ||
| 1350 | 1147 | } |
| 1351 | 1148 | |
| 1352 | 1149 | /** |
| 1353 | 1150 | * @since 3.0 |
| 1354 | - * | |
| 1355 | 1151 | * @param object $style |
| 1356 | 1152 | * @param string $class |
| 1357 | - * | |
| 1358 | - * @return void | |
| 1359 | 1153 | */ |
| 1360 | 1154 | private static function maybe_add_rtl_class( $style, &$class ) { |
| 1361 | 1155 | $is_rtl = isset( $style->post_content['direction'] ) && 'rtl' === $style->post_content['direction']; |
| 1362 | - | |
| 1363 | 1156 | if ( $is_rtl ) { |
| 1364 | 1157 | $class .= ' frm_rtl'; |
| 1365 | 1158 | } |
| 1366 | 1159 | } |
| @@ -1365,28 +1158,17 @@ | ||
| 1365 | 1158 | } |
| 1366 | 1159 | } |
| 1367 | 1160 | |
| 1368 | 1161 | /** |
| 1369 | - * @param string $val Style setting key. | |
| 1370 | - * @param int|string $form Form ID or 'default'. | |
| 1371 | - * | |
| 1372 | - * @return mixed | |
| 1162 | + * @param string $val | |
| 1373 | 1163 | */ |
| 1374 | 1164 | public static function get_style_val( $val, $form = 'default' ) { |
| 1375 | 1165 | $style = self::get_form_style( $form ); |
| 1376 | - | |
| 1377 | 1166 | if ( $style && isset( $style->post_content[ $val ] ) ) { |
| 1378 | 1167 | return $style->post_content[ $val ]; |
| 1379 | 1168 | } |
| 1380 | - | |
| 1381 | - return null; | |
| 1382 | 1169 | } |
| 1383 | 1170 | |
| 1384 | - /** | |
| 1385 | - * @param array $default_styles | |
| 1386 | - * | |
| 1387 | - * @return array | |
| 1388 | - */ | |
| 1389 | 1171 | public static function show_entry_styles( $default_styles ) { |
| 1390 | 1172 | $frm_style = new FrmStyle( 'default' ); |
| 1391 | 1173 | $style = $frm_style->get_one(); |
| 1392 | 1174 | |
| @@ -1395,15 +1177,13 @@ | ||
| 1395 | 1177 | } |
| 1396 | 1178 | |
| 1397 | 1179 | foreach ( $default_styles as $name => $val ) { |
| 1398 | 1180 | $setting = $name; |
| 1399 | - | |
| 1400 | - if ( 'border_width' === $name ) { | |
| 1181 | + if ( 'border_width' == $name ) { | |
| 1401 | 1182 | $setting = 'field_border_width'; |
| 1402 | - } elseif ( 'alt_bg_color' === $name ) { | |
| 1183 | + } elseif ( 'alt_bg_color' == $name ) { | |
| 1403 | 1184 | $setting = 'bg_color_active'; |
| 1404 | 1185 | } |
| 1405 | - | |
| 1406 | 1186 | $default_styles[ $name ] = $style->post_content[ $setting ]; |
| 1407 | 1187 | unset( $name, $val ); |
| 1408 | 1188 | } |
| 1409 | 1189 | |
| @@ -1409,16 +1189,12 @@ | ||
| 1409 | 1189 | |
| 1410 | 1190 | return $default_styles; |
| 1411 | 1191 | } |
| 1412 | 1192 | |
| 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'] ); | |
| 1193 | + public static function &important_style( $important, $field ) { | |
| 1194 | + $important = self::get_style_val( 'important_style', $field['form_id'] ); | |
| 1195 | + | |
| 1196 | + return $important; | |
| 1421 | 1197 | } |
| 1422 | 1198 | |
| 1423 | 1199 | /** |
| 1424 | 1200 | * Duplicate of WordPress do_accordion_section function, it adds an additional svg icon support. |
| @@ -1424,18 +1200,14 @@ | ||
| 1424 | 1200 | * Duplicate of WordPress do_accordion_section function, it adds an additional svg icon support. |
| 1425 | 1201 | * |
| 1426 | 1202 | * @since 6.8.3 |
| 1427 | 1203 | * |
| 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 | 1204 | * @return int |
| 1433 | 1205 | */ |
| 1434 | - public static function do_accordion_sections( $screen, $context, $data_object ) { // phpcs:ignore SlevomatCodingStandard.Complexity.Cognitive.ComplexityTooHigh | |
| 1206 | + public static function do_accordion_sections( $screen, $context, $data_object ) { | |
| 1435 | 1207 | global $wp_meta_boxes; |
| 1436 | 1208 | |
| 1437 | - // The symbol id from icons.svg | |
| 1209 | + // the symbol id from icons.svg | |
| 1438 | 1210 | $icon_ids = array( |
| 1439 | 1211 | 'ranking-fields-style' => 'frm_chart_bar_icon', |
| 1440 | 1212 | 'section-fields-style' => 'frm-form-title-style', |
| 1441 | 1213 | ); |
| @@ -1441,9 +1213,9 @@ | ||
| 1441 | 1213 | ); |
| 1442 | 1214 | |
| 1443 | 1215 | wp_enqueue_script( 'accordion' ); |
| 1444 | 1216 | |
| 1445 | - if ( ! $screen ) { | |
| 1217 | + if ( empty( $screen ) ) { | |
| 1446 | 1218 | $screen = get_current_screen(); |
| 1447 | 1219 | } elseif ( is_string( $screen ) ) { |
| 1448 | 1220 | $screen = convert_to_screen( $screen ); |
| 1449 | 1221 | } |
| @@ -1449,9 +1221,8 @@ | ||
| 1449 | 1221 | } |
| 1450 | 1222 | |
| 1451 | 1223 | $page = $screen->id; |
| 1452 | 1224 | |
| 1453 | - // phpcs:disable Generic.WhiteSpace.ScopeIndent | |
| 1454 | 1225 | ?> |
| 1455 | 1226 | <div id="side-sortables" class="accordion-container"> |
| 1456 | 1227 | <ul class="outer-border"> |
| 1457 | 1228 | <?php |
| @@ -1459,46 +1230,40 @@ | ||
| 1459 | 1230 | $first_open = false; |
| 1460 | 1231 | |
| 1461 | 1232 | if ( isset( $wp_meta_boxes[ $page ][ $context ] ) ) { |
| 1462 | 1233 | foreach ( array( 'high', 'core', 'default', 'low' ) as $priority ) { |
| 1463 | - if ( ! isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) { | |
| 1464 | - continue; | |
| 1465 | - } | |
| 1234 | + if ( isset( $wp_meta_boxes[ $page ][ $context ][ $priority ] ) ) { | |
| 1235 | + foreach ( $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) { | |
| 1236 | + if ( false === $box || ! $box['title'] ) { | |
| 1237 | + continue; | |
| 1238 | + } | |
| 1466 | 1239 | |
| 1467 | - foreach ( $wp_meta_boxes[ $page ][ $context ][ $priority ] as $box ) { | |
| 1468 | - if ( false === $box || ! $box['title'] ) { | |
| 1469 | - continue; | |
| 1470 | - } | |
| 1240 | + ++$i; | |
| 1241 | + $icon_id = array_key_exists( $box['id'], $icon_ids ) ? $icon_ids[ $box['id'] ] : 'frm-' . $box['id']; | |
| 1471 | 1242 | |
| 1472 | - ++$i; | |
| 1473 | - $icon_id = array_key_exists( $box['id'], $icon_ids ) ? $icon_ids[ $box['id'] ] : 'frm-' . $box['id']; | |
| 1474 | - $open_class = ''; | |
| 1475 | - | |
| 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 | |
| 1243 | + $open_class = ''; | |
| 1244 | + if ( ! $first_open ) { | |
| 1245 | + $first_open = true; | |
| 1246 | + $open_class = 'open'; | |
| 1247 | + } | |
| 1248 | + ?> | |
| 1249 | + <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'] ); ?>"> | |
| 1250 | + <h3 class="accordion-section-title hndle" tabindex="0"> | |
| 1251 | + <?php | |
| 1252 | + FrmAppHelper::icon_by_class( 'frmfont ' . $icon_id ); | |
| 1253 | + echo esc_html( $box['title'] ); | |
| 1254 | + FrmAppHelper::icon_by_class( 'frmfont frm_arrowdown8_icon' ); | |
| 1255 | + ?> | |
| 1256 | + </h3> | |
| 1257 | + <div class="accordion-section-content <?php postbox_classes( $box['id'], $page ); ?>"> | |
| 1258 | + <div class="inside"> | |
| 1259 | + <?php call_user_func( $box['callback'], $data_object, $box ); ?> | |
| 1260 | + </div><!-- .inside --> | |
| 1261 | + </div><!-- .accordion-section-content --> | |
| 1262 | + </li><!-- .accordion-section --> | |
| 1263 | + <?php | |
| 1264 | + }//end foreach | |
| 1265 | + }//end if | |
| 1501 | 1266 | }//end foreach |
| 1502 | 1267 | }//end if |
| 1503 | 1268 | ?> |
| 1504 | 1269 | </ul><!-- .outer-border --> |
| @@ -1503,9 +1268,8 @@ | ||
| 1503 | 1268 | ?> |
| 1504 | 1269 | </ul><!-- .outer-border --> |
| 1505 | 1270 | </div><!-- .accordion-container --> |
| 1506 | 1271 | <?php |
| 1507 | - // phpcs:enable Generic.WhiteSpace.ScopeIndent | |
| 1508 | 1272 | return $i; |
| 1509 | 1273 | } |
| 1510 | 1274 | |
| 1511 | 1275 | /** |
| @@ -1516,9 +1280,8 @@ | ||
| 1516 | 1280 | * @return void |
| 1517 | 1281 | */ |
| 1518 | 1282 | public static function rename_style() { |
| 1519 | 1283 | $permission_error = FrmAppHelper::permission_nonce_error( 'frm_edit_forms', 'nonce', 'frm_ajax' ); |
| 1520 | - | |
| 1521 | 1284 | if ( $permission_error !== false ) { |
| 1522 | 1285 | $data = array( |
| 1523 | 1286 | 'message' => __( 'Unable to rename style', 'formidable' ), |
| 1524 | 1287 | ); |
| @@ -1537,9 +1300,8 @@ | ||
| 1537 | 1300 | die(); |
| 1538 | 1301 | } |
| 1539 | 1302 | |
| 1540 | 1303 | $post = get_post( $style_id ); |
| 1541 | - | |
| 1542 | 1304 | if ( ! $post || $post->post_type !== self::$post_type ) { |
| 1543 | 1305 | $data = array( |
| 1544 | 1306 | 'message' => __( 'The style you are renaming either does not exist or it is not a style', 'formidable' ), |
| 1545 | 1307 | ); |
| @@ -1560,9 +1322,8 @@ | ||
| 1560 | 1322 | * |
| 1561 | 1323 | * @since 6.0 |
| 1562 | 1324 | * |
| 1563 | 1325 | * @param WP_Styles $styles |
| 1564 | - * | |
| 1565 | 1326 | * @return void |
| 1566 | 1327 | */ |
| 1567 | 1328 | public static function disable_conflicting_wp_admin_css( $styles ) { |
| 1568 | 1329 | if ( ! FrmAppHelper::is_style_editor_page() ) { |