| @@ -8,9 +8,9 @@ | ||
| 8 | 8 | */ |
| 9 | 9 | class FrmStylesPreviewHelper { |
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | - * @param int $form_id | |
| 12 | + * @var int | |
| 13 | 13 | */ |
| 14 | 14 | private $form_id; |
| 15 | 15 | |
| 16 | 16 | /** |
| @@ -31,13 +31,13 @@ | ||
| 31 | 31 | */ |
| 32 | 32 | private $default_label_position_field_ids; |
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | - * @param string|int $form_id | |
| 35 | + * @param int|string $form_id | |
| 36 | 36 | * @return void |
| 37 | 37 | */ |
| 38 | 38 | public function __construct( $form_id ) { |
| 39 | - $this->form_id = (int) $form_id; | |
| 39 | + $this->form_id = (int) $form_id; | |
| 40 | 40 | $this->default_label_position_field_ids = array(); |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
| @@ -47,10 +47,13 @@ | ||
| 47 | 47 | * |
| 48 | 48 | * @return void |
| 49 | 49 | */ |
| 50 | 50 | public function adjust_form_for_preview() { |
| 51 | - add_filter( 'frm_run_antispam', '__return_false', 99 ); // Don't bother including the antispam token in the preview as the form isn't submitted. | |
| 52 | - add_filter( 'frm_run_honeypot', '__return_false' ); // We don't need the honeypot in the preview so leave it out. | |
| 51 | + // Don't bother including the antispam token in the preview as the form isn't submitted. | |
| 52 | + add_filter( 'frm_run_antispam', '__return_false', 99 ); | |
| 53 | + | |
| 54 | + // We don't need the honeypot in the preview so leave it out. | |
| 55 | + add_filter( 'frm_run_honeypot', '__return_false' ); | |
| 53 | 56 | $this->hide_captcha_fields(); |
| 54 | 57 | $this->disable_javascript_validation(); |
| 55 | 58 | $this->add_a_div_class_for_default_label_positions(); |
| 56 | 59 | } |
| @@ -67,12 +70,12 @@ | ||
| 67 | 70 | add_filter( |
| 68 | 71 | 'frm_html_label_position', |
| 69 | 72 | /** |
| 70 | 73 | * @param string $position |
| 71 | - * @param object|array $field | |
| 74 | + * @param array|object $field | |
| 72 | 75 | * @return string |
| 73 | 76 | */ |
| 74 | - function( $position, $field ) { | |
| 77 | + function ( $position, $field ) { | |
| 75 | 78 | if ( is_array( $field ) ) { |
| 76 | 79 | $this->default_label_position_field_ids[] = (int) $field['id']; |
| 77 | 80 | } |
| 78 | 81 | return $position; |
| @@ -84,12 +87,12 @@ | ||
| 84 | 87 | add_filter( |
| 85 | 88 | 'frm_field_div_classes', |
| 86 | 89 | /** |
| 87 | 90 | * @param string $classes |
| 88 | - * @param object|array $field | |
| 91 | + * @param array|object $field | |
| 89 | 92 | * @return string |
| 90 | 93 | */ |
| 91 | - function( $classes, $field ) { | |
| 94 | + function ( $classes, $field ) { | |
| 92 | 95 | if ( is_array( $field ) && in_array( (int) $field['id'], $this->default_label_position_field_ids, true ) ) { |
| 93 | 96 | $classes .= ' frm-default-label-position'; |
| 94 | 97 | } |
| 95 | 98 | return $classes; |
| @@ -114,9 +117,9 @@ | ||
| 114 | 117 | * @param string $field_type |
| 115 | 118 | * @param string $target_field_type |
| 116 | 119 | * @return bool |
| 117 | 120 | */ |
| 118 | - function( $show, $field_type ) { | |
| 121 | + function ( $show, $field_type ) { | |
| 119 | 122 | if ( 'captcha' === $field_type ) { |
| 120 | 123 | $show = false; |
| 121 | 124 | } |
| 122 | 125 | return $show; |
| @@ -137,10 +140,17 @@ | ||
| 137 | 140 | */ |
| 138 | 141 | private function disable_javascript_validation() { |
| 139 | 142 | add_filter( |
| 140 | 143 | 'frm_form_object', |
| 141 | - function( $form ) { | |
| 142 | - $form->options['js_validate'] = false; | |
| 144 | + /** | |
| 145 | + * @param stdClass|null $form | |
| 146 | + * @param int $form_id | |
| 147 | + * @return stdClass|null | |
| 148 | + */ | |
| 149 | + function ( $form ) { | |
| 150 | + if ( is_object( $form ) && is_array( $form->options ) ) { | |
| 151 | + $form->options['js_validate'] = false; | |
| 152 | + } | |
| 143 | 153 | return $form; |
| 144 | 154 | } |
| 145 | 155 | ); |
| 146 | 156 | } |
| @@ -147,9 +157,8 @@ | ||
| 147 | 157 | |
| 148 | 158 | /** |
| 149 | 159 | * @since 6.0 |
| 150 | 160 | * |
| 151 | - * @param string|int $form_id | |
| 152 | 161 | * @return string |
| 153 | 162 | */ |
| 154 | 163 | public function get_html_for_form_preview() { |
| 155 | 164 | // Force is_admin to false so the "Entry Key" field doesn't render in the preview. |
| @@ -186,9 +195,9 @@ | ||
| 186 | 195 | } |
| 187 | 196 | |
| 188 | 197 | $frm_settings = FrmAppHelper::get_settings(); |
| 189 | 198 | if ( 'none' === $frm_settings->load_style ) { |
| 190 | - $notes[] = function() { | |
| 199 | + $notes[] = function () { | |
| 191 | 200 | printf( |
| 192 | 201 | // translators: %1$s: Anchor tag open, %2$s: Anchor tag close. |
| 193 | 202 | esc_html__( 'Formidable styles are disabled. This needs to be enabled in %1$sGlobal Settings%2$s.', 'formidable' ), |
| 194 | 203 | '<a href="' . esc_url( admin_url( 'admin.php?page=formidable-settings' ) ) . '">', |
| @@ -215,35 +224,18 @@ | ||
| 215 | 224 | |
| 216 | 225 | /** |
| 217 | 226 | * @since 6.0 |
| 218 | 227 | * |
| 219 | - * @return string|false | |
| 228 | + * @return string | |
| 220 | 229 | */ |
| 221 | 230 | private function get_disabled_features_note() { |
| 222 | - $disabled_features = array(); | |
| 223 | - | |
| 224 | - if ( $this->form_includes_captcha ) { | |
| 225 | - $disabled_features[] = __( 'Captcha fields are hidden.', 'formidable' ); | |
| 226 | - } | |
| 227 | - | |
| 228 | - if ( is_callable( 'FrmProStylesController::get_disabled_javascript_features' ) ) { | |
| 229 | - $disabled_pro_features = FrmProStylesController::get_disabled_javascript_features(); | |
| 230 | - if ( is_string( $disabled_pro_features ) ) { | |
| 231 | - $disabled_features[] = $disabled_pro_features; | |
| 232 | - } | |
| 233 | - } | |
| 234 | - | |
| 235 | - if ( $disabled_features ) { | |
| 236 | - return __( 'Not all JavaScript is loaded in this preview.', 'formidable' ) . ' ' . implode( ' ', $disabled_features ); | |
| 237 | - } | |
| 238 | - | |
| 239 | - return false; | |
| 231 | + return __( 'Not all JavaScript is loaded in this preview. Some features will appear differently on the front end.', 'formidable' ); | |
| 240 | 232 | } |
| 241 | 233 | |
| 242 | 234 | /** |
| 243 | 235 | * @since 6.0 |
| 244 | 236 | * |
| 245 | - * @return string|false | |
| 237 | + * @return false|string | |
| 246 | 238 | */ |
| 247 | 239 | private function get_fallback_form_note() { |
| 248 | 240 | if ( ! FrmAppHelper::simple_get( 'form', 'absint' ) ) { |
| 249 | 241 | return __( 'This form is being previewed because no form was selected. Use the form dropdown to select a new preview target.', 'formidable' ); |
| @@ -255,9 +247,9 @@ | ||
| 255 | 247 | * Get all warnings to display above the visual styler preview. |
| 256 | 248 | * |
| 257 | 249 | * @since 6.0 |
| 258 | 250 | * |
| 259 | - * @param WP_Post|stdClass $style A new style is not a WP_Post object. | |
| 251 | + * @param stdClass|WP_Post $style A new style is not a WP_Post object. | |
| 260 | 252 | * @param WP_Post $default_style |
| 261 | 253 | * @param string $view Either 'list' or 'edit'. |
| 262 | 254 | * @return array<string> |
| 263 | 255 | */ |
| @@ -328,8 +320,54 @@ | ||
| 328 | 320 | } |
| 329 | 321 | |
| 330 | 322 | // Remove the edit dependency from wp-admin so it still loads, just without edit.css. |
| 331 | 323 | self::remove_wp_admin_dependency( $styles, 'edit' ); |
| 324 | + } | |
| 325 | + | |
| 326 | + /** | |
| 327 | + * Provides few fixes for style preview. | |
| 328 | + * Fix the "Width" from Fields Settings to get reflected on each style preview ajax update. | |
| 329 | + * Fix the Radio & Checkbox "Single Row" or "Multiple Row" to get reflected in style preview ajax update. | |
| 330 | + * | |
| 331 | + * @since 6.14 | |
| 332 | + * | |
| 333 | + * @param array $settings The style options. | |
| 334 | + * @param bool $is_preview | |
| 335 | + * | |
| 336 | + * @return void | |
| 337 | + */ | |
| 338 | + public static function get_additional_preview_style( $settings, $is_preview = false ) { | |
| 339 | + if ( ! $is_preview ) { | |
| 340 | + return; | |
| 341 | + } | |
| 342 | + $radio_display_type = 'inline' === $settings['radio_align'] ? 'inline-block' : 'block'; | |
| 343 | + $check_display_type = 'inline' === $settings['check_align'] ? 'inline-block' : 'block'; | |
| 344 | + | |
| 345 | + $style = '#frm_style_preview .with_frm_style input[type=text], | |
| 346 | + #frm_style_preview .with_frm_style input[type=password], | |
| 347 | + #frm_style_preview .with_frm_style input[type=email], | |
| 348 | + #frm_style_preview .with_frm_style input[type=number], | |
| 349 | + #frm_style_preview .with_frm_style input[type=url], | |
| 350 | + #frm_style_preview .with_frm_style input[type=tel], | |
| 351 | + #frm_style_preview .with_frm_style input[type=phone], | |
| 352 | + #frm_style_preview .with_frm_style input[type=search], | |
| 353 | + #frm_style_preview .with_frm_style textarea, | |
| 354 | + #frm_style_preview .frm_form_fields_style, | |
| 355 | + #frm_style_preview .with_frm_style .frm_scroll_box .frm_opt_container, | |
| 356 | + #frm_style_preview .frm_form_fields_active_style, | |
| 357 | + #frm_style_preview .frm_form_fields_error_style, | |
| 358 | + #frm_style_preview .with_frm_style .frm-card-element.StripeElement, | |
| 359 | + #frm_style_preview .with_frm_style .frm_slimselect.ss-main { | |
| 360 | + width: var(--field-width); | |
| 361 | + } | |
| 362 | + #frm_style_preview .with_frm_style .frm_radio { | |
| 363 | + display:' . $radio_display_type . '; | |
| 364 | + } | |
| 365 | + #frm_style_preview .with_frm_style .frm_checkbox { | |
| 366 | + display:' . $check_display_type . '; | |
| 367 | + }'; | |
| 368 | + | |
| 369 | + echo esc_html( $style ); | |
| 332 | 370 | } |
| 333 | 371 | |
| 334 | 372 | /** |
| 335 | 373 | * @since 6.0 |