PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 6.2.9
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v6.2.9
6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 All 196 releases
fluentform / app / Modules / Form / DefaultStyleApplicator.php

DefaultStyleApplicator.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 6.2.9, at app/Modules/Form/DefaultStyleApplicator.php

84 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentForm\App\Modules\Form;
4
5 defined('ABSPATH') or die;
6
7 use FluentForm\App\Helpers\Helper;
8 use FluentForm\Framework\Helpers\ArrayHelper as Arr;
9
10 class DefaultStyleApplicator
11 {
12 public function __construct()
13 {
14 add_action('fluentform/inserted_new_form', [$this, 'applyDefaultStyles'], 10, 2);
15 }
16
17 /**
18 * Apply default style template to newly created forms
19 *
20 * @param int $formId The ID of the newly created form
21 * @param array $formData The form data
22 *
23 * @return void
24 */
25 public function applyDefaultStyles($formId, $formData)
26 {
27 $defaultTemplate = get_option('_fluentform_default_style_template');
28
29 if (!$defaultTemplate || !is_array($defaultTemplate) || Arr::get($defaultTemplate, 'enabled') !== 'yes') {
30 return;
31 }
32
33 $customCss = Arr::get($defaultTemplate, 'custom_css', '');
34 if ($customCss) {
35 // Replace FF_ID and {form_id} placeholders with actual form ID
36 $customCss = str_replace('{form_id}', $formId, $customCss);
37 $customCss = str_replace('FF_ID', $formId, $customCss);
38 Helper::setFormMeta($formId, '_custom_form_css', $customCss);
39 }
40
41 $stylerEnabled = Arr::get($defaultTemplate, 'styler_enabled', 'no');
42 $stylerTheme = Arr::get($defaultTemplate, 'styler_theme', '');
43 if ($stylerTheme) {
44 Helper::setFormMeta($formId, '_ff_selected_style', $stylerTheme);
45 }
46
47 if ($stylerEnabled === 'yes') {
48 if ($stylerTheme) {
49 Helper::setFormMeta($formId, '_ff_selected_style', $stylerTheme);
50 }
51
52 $stylerStyles = Arr::get($defaultTemplate, 'styler_styles', []);
53 if ($stylerStyles && is_array($stylerStyles) && !empty($stylerStyles)) {
54 Helper::setFormMeta($formId, '_ff_form_styles', $stylerStyles);
55 } elseif ($stylerTheme) {
56 $presets = [];
57 if (class_exists('\FluentFormPro\classes\FormStyler')) {
58 $formStyler = new \FluentFormPro\classes\FormStyler();
59 $presets = $formStyler->getPresets();
60 } else {
61 $presets = [
62 'ffs_default' => [
63 'label' => __('Default', 'fluentform'),
64 'style' => '[]',
65 ],
66 'ffs_inherit_theme' => [
67 'label' => __('Inherit Theme Style', 'fluentform'),
68 'style' => '{}',
69 ],
70 ];
71 }
72
73 if (isset($presets[$stylerTheme])) {
74 $styles = json_decode($presets[$stylerTheme]['style'], true);
75 if ($styles) {
76 Helper::setFormMeta($formId, '_ff_form_styles', $styles);
77 }
78 }
79 }
80 }
81 }
82 }
83
84