diff --git a/classes/controllers/FrmStylesController.php b/classes/controllers/FrmStylesController.php index 8be5d031f0..077a1904b4 100644 --- a/classes/controllers/FrmStylesController.php +++ b/classes/controllers/FrmStylesController.php @@ -1348,6 +1348,11 @@ public static function get_form_style_class( $class, $style ) { $frm_style = new FrmStyle( $style ); $style = $frm_style->get_one(); + if ( ! $style ) { + // The style was deleted, so use the default style. + $style = ( new FrmStyle( 'default' ) )->get_one(); + } + if ( $style ) { $class .= ' frm_style_' . $style->post_name; self::maybe_add_rtl_class( $style, $class ); diff --git a/tests/phpunit/styles/test_FrmStylesController.php b/tests/phpunit/styles/test_FrmStylesController.php index a80f158abd..ed7d7c75df 100644 --- a/tests/phpunit/styles/test_FrmStylesController.php +++ b/tests/phpunit/styles/test_FrmStylesController.php @@ -185,4 +185,16 @@ public function test_save() { $updated_style = $frm_style->get_one(); $this->assertSame( $style->post_title . ' Updated', $updated_style->post_title ); } + + public function test_get_form_style_class_falls_back_to_default_style_when_style_is_deleted() { + $default_style = ( new FrmStyle( 'default' ) )->get_one(); + $this->assertNotEmpty( $default_style ); + + $deleted_style_id = $default_style->ID + 100000; + $this->assertNull( ( new FrmStyle( $deleted_style_id ) )->get_one() ); + + $class = FrmStylesController::get_form_style_class( ' with_frm_style', $deleted_style_id ); + + $this->assertSame( ' with_frm_style frm_style_' . $default_style->post_name, $class ); + } }