-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditor.php
More file actions
226 lines (197 loc) · 7.72 KB
/
editor.php
File metadata and controls
226 lines (197 loc) · 7.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<?php
// Exit if accessed directly
if (!defined('ABSPATH')) {
exit;
}
/**
* ----------------------------
* Gutenberg Block
* ----------------------------
*/
function sucf_register_gutenberg_block() {
if (!function_exists('register_block_type')) return;
register_block_type('sucf/contact-form', [
'editor_script' => 'sucf-editor-script', // enqueue separately
'render_callback' => 'sucf_render_form',
'attributes' => [
'show_name' => ['type' => 'boolean', 'default' => true],
'show_email' => ['type' => 'boolean', 'default' => true],
'show_phone' => ['type' => 'boolean', 'default' => true],
'show_message' => ['type' => 'boolean', 'default' => true],
'button_text' => ['type' => 'string', 'default' => 'Send Message'],
'layout' => ['type' => 'string', 'default' => 'block'],
'columns' => ['type' => 'number', 'default' => 1],
'gap' => ['type' => 'number', 'default' => 15],
],
]);
}
add_action('init', 'sucf_register_gutenberg_block');
/**
* ----------------------------
* Elementor Widget
* ----------------------------
*/
function sucf_register_elementor_widget($widgets_manager) {
if (!class_exists('Elementor\Widget_Base')) return;
class SUCF_Elementor_Widget extends \Elementor\Widget_Base {
public function get_name() {
return 'sucf_contact_form';
}
public function get_title() {
return 'Simple Contact Form';
}
public function get_icon() {
return 'eicon-mail';
}
public function get_categories() {
return ['general'];
}
protected function register_controls() {
// ---------------- Fields Section ----------------
$this->start_controls_section('section_fields', ['label' => 'Form Fields']);
$fields = ['show_name', 'show_email', 'show_phone', 'show_message'];
foreach ($fields as $field) {
$this->add_control(
$field,
[
'label' => ucfirst(str_replace('_', ' ', $field)),
'type' => \Elementor\Controls_Manager::SWITCHER,
'label_on' => 'Show',
'label_off' => 'Hide',
'return_value' => 'yes',
'default' => 'yes',
]
);
}
$this->add_control(
'button_text',
[
'label' => 'Button Text',
'type' => \Elementor\Controls_Manager::TEXT,
'default' => 'Send Message',
]
);
$this->end_controls_section();
// ---------------- Layout Section ----------------
$this->start_controls_section('section_layout', ['label' => 'Layout']);
$this->add_control(
'layout',
[
'label' => 'Layout Type',
'type' => \Elementor\Controls_Manager::SELECT,
'default' => 'block',
'options' => [
'block' => 'Block',
'flex' => 'Flex',
'grid' => 'Grid',
],
]
);
$this->add_control(
'columns',
[
'label' => 'Columns (for Grid)',
'type' => \Elementor\Controls_Manager::NUMBER,
'min' => 1,
'max' => 4,
'default' => 1,
]
);
$this->add_control(
'gap',
[
'label' => 'Gap (px)',
'type' => \Elementor\Controls_Manager::SLIDER,
'range' => ['px' => ['min'=>0,'max'=>50]],
'default' => ['size'=>15],
'selectors' => [],
]
);
$this->end_controls_section();
// ---------------- Style Section ----------------
$this->start_controls_section('section_style', [
'label' => 'Style',
'tab' => \Elementor\Controls_Manager::TAB_STYLE,
]);
$this->add_control(
'field_color',
[
'label' => 'Field Text Color',
'type' => \Elementor\Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .sucf-form input, {{WRAPPER}} .sucf-form textarea' => 'color: {{VALUE}};',
],
]
);
$this->add_control(
'field_bg',
[
'label' => 'Field Background',
'type' => \Elementor\Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .sucf-form input, {{WRAPPER}} .sucf-form textarea' => 'background-color: {{VALUE}};',
],
]
);
$this->add_control(
'border_color',
[
'label' => 'Border Color',
'type' => \Elementor\Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .sucf-form input, {{WRAPPER}} .sucf-form textarea' => 'border-color: {{VALUE}};',
],
]
);
$this->add_control(
'border_radius',
[
'label' => 'Border Radius (px)',
'type' => \Elementor\Controls_Manager::SLIDER,
'range' => ['px' => ['min'=>0,'max'=>50]],
'selectors' => [
'{{WRAPPER}} .sucf-form input, {{WRAPPER}} .sucf-form textarea, {{WRAPPER}} .sucf-form button' => 'border-radius: {{SIZE}}px;',
],
]
);
$this->add_control(
'button_bg',
[
'label' => 'Button Background',
'type' => \Elementor\Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .sucf-form button' => 'background-color: {{VALUE}};',
],
]
);
$this->add_control(
'button_color',
[
'label' => 'Button Text Color',
'type' => \Elementor\Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .sucf-form button' => 'color: {{VALUE}};',
],
]
);
$this->end_controls_section();
}
protected function render() {
$settings = $this->get_settings_for_display();
$atts = [
'show_name' => $settings['show_name'] === 'yes',
'show_email' => $settings['show_email'] === 'yes',
'show_phone' => $settings['show_phone'] === 'yes',
'show_message' => $settings['show_message'] === 'yes',
'button_text' => $settings['button_text'],
'layout' => $settings['layout'],
'columns' => $settings['columns'],
'gap' => $settings['gap']['size'] ?? 15,
'form_id' => 'sucf_elementor_' . $this->get_id(),
];
sucf_render_form($atts);
}
}
$widgets_manager->register(new SUCF_Elementor_Widget());
}
add_action('elementor/widgets/register', 'sucf_register_elementor_widget');