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