PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/helpers/FrmStylesPreviewHelper.php +64 -14 6.25 → trunk View file →
@@ -32,8 +32,9 @@
32 32 private $default_label_position_field_ids;
33 33
34 34 /**
35 35 * @param int|string $form_id
36 + *
36 37 * @return void
37 38 */
38 39 public function __construct( $form_id ) {
39 40 $this->form_id = (int) $form_id;
@@ -55,15 +56,57 @@
55 56 add_filter( 'frm_run_honeypot', '__return_false' );
56 57 $this->hide_captcha_fields();
57 58 $this->disable_javascript_validation();
58 59 $this->add_a_div_class_for_default_label_positions();
60 + $this->add_a_div_class_for_style_driven_alignment();
59 61 }
60 62
61 63 /**
64 + * Add a marker class to radio and checkbox fields that use the style's option
65 + * alignment setting rather than a field level override.
66 + *
67 + * Only fields with this class change when the radio or checkbox alignment style
68 + * setting is updated in the styler preview. Fields with their own alignment
69 + * override are left untouched.
70 + *
71 + * @since 6.32
72 + *
73 + * @return void
74 + */
75 + private function add_a_div_class_for_style_driven_alignment() {
76 + add_filter(
77 + 'frm_field_div_classes',
78 + /**
79 + * @param string $classes
80 + * @param array|object $field
81 + *
82 + * @return string
83 + */
84 + function ( $classes, $field ) {
85 + if ( ! FrmField::is_radio( $field ) && ! FrmField::is_checkbox( $field ) ) {
86 + return $classes;
87 + }
88 +
89 + // Mirror FrmFieldType::get_container_class(): an override only exists in Pro.
90 + $align = FrmAppHelper::pro_is_installed() ? FrmField::get_option( $field, 'align' ) : '';
91 +
92 + if ( ! $align ) {
93 + $classes .= ' frm-default-option-align';
94 + }
95 +
96 + return $classes;
97 + },
98 + 10,
99 + 2
100 + );
101 + }
102 +
103 + /**
62 104 * Add a frm-default-label-position class to any field with a default label position.
63 105 * A field with a custom label position shouldn't ever change in the styler preview.
64 106 *
65 107 * @since 6.0.1
108 + *
66 109 * @return void
67 110 */
68 111 private function add_a_div_class_for_default_label_positions() {
69 112 // Only fields with no label position set hit this filter, so track those for the frm_field_div_classes filter.
@@ -71,8 +114,9 @@
71 114 'frm_html_label_position',
72 115 /**
73 116 * @param string $position
74 117 * @param array|object $field
118 + *
75 119 * @return string
76 120 */
77 121 function ( $position, $field ) {
78 122 if ( is_array( $field ) ) {
@@ -88,8 +132,9 @@
88 132 'frm_field_div_classes',
89 133 /**
90 134 * @param string $classes
91 135 * @param array|object $field
136 + *
92 137 * @return string
93 138 */
94 139 function ( $classes, $field ) {
95 140 if ( is_array( $field ) && in_array( (int) $field['id'], $this->default_label_position_field_ids, true ) ) {
@@ -115,15 +160,13 @@
115 160 /**
116 161 * @param bool $show
117 162 * @param string $field_type
118 163 * @param string $target_field_type
164 + *
119 165 * @return bool
120 166 */
121 167 function ( $show, $field_type ) {
122 - if ( 'captcha' === $field_type ) {
123 - $show = false;
124 - }
125 - return $show;
168 + return 'captcha' === $field_type ? false : $show;
126 169 },
127 170 10,
128 171 2
129 172 );
@@ -143,8 +186,9 @@
143 186 'frm_form_object',
144 187 /**
145 188 * @param stdClass|null $form
146 189 * @param int $form_id
190 + *
147 191 * @return stdClass|null
148 192 */
149 193 function ( $form ) {
150 194 if ( is_object( $form ) && is_array( $form->options ) ) {
@@ -166,8 +210,9 @@
166 210
167 211 $target_form_preview_html = FrmFormsController::show_form( $this->form_id, '', 'auto', 'auto' );
168 212
169 213 $this->form_includes_captcha = wp_script_is( 'captcha-api', 'enqueued' );
214 +
170 215 if ( $this->form_includes_captcha ) {
171 216 // If a form includes a CAPTCHA field, don't try to load the CAPTCHA scripts for the visual styler preview.
172 217 wp_dequeue_script( 'captcha-api' );
173 218 }
@@ -181,21 +226,20 @@
181 226
182 227 /**
183 228 * @since 6.0
184 229 *
185 - * @todo Only show the note once for a form per user per month or something.
186 - *
187 230 * @return array<string>
188 231 */
189 232 public function get_notes_for_styler_preview() {
190 - $notes = array();
233 + $notes = array();
234 + $fallback_form_note = $this->get_fallback_form_note();
191 235
192 - $fallback_form_note = $this->get_fallback_form_note();
193 236 if ( is_string( $fallback_form_note ) ) {
194 237 $notes[] = $fallback_form_note;
195 238 }
196 239
197 240 $frm_settings = FrmAppHelper::get_settings();
241 +
198 242 if ( 'none' === $frm_settings->load_style ) {
199 243 $notes[] = function () {
200 244 printf(
201 245 // translators: %1$s: Anchor tag open, %2$s: Anchor tag close.
@@ -205,17 +249,14 @@
205 249 );
206 250 };
207 251 }
208 252
209 - if ( class_exists( 'FrmProStylesController' ) && ! class_exists( 'FrmProStylesPreviewHelper' ) ) {
210 - $notes[] = __( 'You are using an outdated version of Formidable Pro. Please update to version 6.0 to get access to all styler features.', 'formidable' );
211 - }
212 -
213 253 if ( is_callable( 'FrmProStylesController::get_notes_for_styler_preview' ) ) {
214 254 $notes = array_merge( $notes, FrmProStylesController::get_notes_for_styler_preview() );
215 255 }
216 256
217 257 $disabled_features_note = $this->get_disabled_features_note();
258 +
218 259 if ( is_string( $disabled_features_note ) ) {
219 260 $notes[] = $disabled_features_note;
220 261 }
221 262
@@ -250,8 +291,9 @@
250 291 *
251 292 * @param stdClass|WP_Post $style A new style is not a WP_Post object.
252 293 * @param WP_Post $default_style
253 294 * @param string $view Either 'list' or 'edit'.
295 + *
254 296 * @return array<string>
255 297 */
256 298 public function get_warnings_for_styler_preview( $style, $default_style, $view ) {
257 299 $warnings = array();
@@ -267,8 +309,9 @@
267 309 * @since 6.0
268 310 *
269 311 * @param int $style_id
270 312 * @param int $default_style_id
313 + *
271 314 * @return bool
272 315 */
273 316 private function should_show_multiple_forms_warning( $style_id, $default_style_id ) {
274 317 $is_default_style = $style_id === $default_style_id;
@@ -275,8 +318,9 @@
275 318
276 319 if ( ! $is_default_style ) {
277 320 // Also check for the conversational default.
278 321 $conversational_style_id = FrmDb::get_var( 'posts', array( 'post_name' => 'lines-no-boxes' ), 'ID' );
322 +
279 323 if ( $conversational_style_id && (int) $conversational_style_id === $style_id ) {
280 324 $is_default_style = true;
281 325 }
282 326 }
@@ -303,8 +347,9 @@
303 347 /**
304 348 * @since 6.0
305 349 *
306 350 * @param WP_Styles $styles
351 + *
307 352 * @return void
308 353 */
309 354 public static function disable_conflicting_wp_admin_css( $styles ) {
310 355 if ( ! is_callable( array( $styles, 'remove' ) ) || ! array_key_exists( 'wp-admin', $styles->registered ) ) {
@@ -313,9 +358,10 @@
313 358
314 359 $styles->remove( 'edit' );
315 360
316 361 $wp_admin_dependencies = $styles->registered['wp-admin']->deps;
317 - $edit_key = array_search( 'edit', $wp_admin_dependencies );
362 + $edit_key = array_search( 'edit', $wp_admin_dependencies, true );
363 +
318 364 if ( false === $edit_key ) {
319 365 return;
320 366 }
321 367
@@ -338,8 +384,9 @@
338 384 public static function get_additional_preview_style( $settings, $is_preview = false ) {
339 385 if ( ! $is_preview ) {
340 386 return;
341 387 }
388 +
342 389 $radio_display_type = 'inline' === $settings['radio_align'] ? 'inline-block' : 'block';
343 390 $check_display_type = 'inline' === $settings['check_align'] ? 'inline-block' : 'block';
344 391
345 392 $style = '#frm_style_preview .with_frm_style input[type=text],
@@ -373,13 +420,16 @@
373 420 * @since 6.0
374 421 *
375 422 * @param WP_Styles $styles
376 423 * @param string $key
424 + *
377 425 * @return void
378 426 */
379 427 private static function remove_wp_admin_dependency( $styles, $key ) {
380 428 $dependencies = $styles->registered['wp-admin']->deps;
381 - $index = array_search( $key, $dependencies );
429 + // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
430 + $index = array_search( $key, $dependencies );
431 +
382 432 if ( false === $index ) {
383 433 return;
384 434 }
385 435