-
Notifications
You must be signed in to change notification settings - Fork 0
/
gp-gravityforms.php
305 lines (284 loc) · 9.68 KB
/
gp-gravityforms.php
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
<?php
/**
* Plugin Name: Unsemantic Grid for Gravity Forms
* Plugin URI: https://github.com/WestCoastDigital/gp-gravityforms
* Description: Applies GeneratePress customisations & styles to Gravity Forms
* Version: 0.1
* Author: Jon Mather
* Author URI: https://westcoastdigital.com.au
*/
defined('ABSPATH') or die("These aren't the droids you're looking for");
// Enable Gravity Forms field label visibility
add_filter('gform_enable_field_label_visibility_settings', '__return_true');
class gpGfStyle
{
public static function gp_gf_add_unsemantic_classes($classes, $field, $form)
{
// Turn field classes into array
$field_classes = explode(' ', $classes);
$skip_classes = ['gform_validation_container', 'gform_hidden'];
// Skip validation container
if (count(array_intersect($skip_classes, $field_classes)) != 0) {
return $classes;
}
// Get the unsemantic classes
$bsClasses = apply_filters('gp-gf-us-classes', gpGfStyle::gp_gf_default_classes());
// Fixed sizes array size => field type
$fixedSizes = [
'name' => 'large',
'fileupload' => 'large'
];
// Set specific fields to certain size and add field type as extra class
if (array_key_exists($field->type, $fixedSizes)) {
$field->size = $fixedSizes[$field->type];
$field_classes[] = 'gfield_type_' . $field->type;
}
// Merge unsemantic classes based on field size
$classes = array_merge($field_classes, $bsClasses[$field->size], ['gfield-us']);
return implode(' ', $classes);
}
// Set default classes
public static function gp_gf_default_classes()
{
return [
'small' => [
get_theme_mod('gp_gf_small_mobile', 'mobile-grid-100'),
get_theme_mod('gp_gf_small_tablet', 'tablet-grid-50'),
get_theme_mod('gp_gf_small_desktop', 'grid-33')
],
'medium' => [
get_theme_mod('gp_gf_medium_mobile', 'mobile-grid-100'),
get_theme_mod('gp_gf_medium_tablet', 'tablet-grid-50'),
get_theme_mod('gp_gf_medium_desktop', 'grid-50')
],
'large' => [
get_theme_mod('gp_gf_large_mobile', 'mobile-grid-100'),
get_theme_mod('gp_gf_large_tablet', 'tablet-grid-100'),
get_theme_mod('gp_gf_large_desktop', 'grid-100')
]
];
}
// Add custom styles
public static function gp_gf_default_style()
{
wp_register_style('gp-gravityforms', plugin_dir_url(__FILE__) . "/style.css");
wp_enqueue_style('gp-gravityforms');
}
// Add customizer controls to change default classes
public static function gp_gf_customizer_settings($wp_customize)
{
$wp_customize->add_panel(
'gp_gf_panel',
array(
'title' => __('Gravity Forms'),
)
);
$wp_customize->add_section(
'gp_gf_small_class',
array(
'title' => __('Small Field Classes'),
'description' => esc_html__('These are the default classes when a GF field is set to small.'),
'panel' => 'gp_gf_panel',
)
);
$wp_customize->add_section(
'gp_gf_medium_class',
array(
'title' => __('Medium Field Classes'),
'description' => esc_html__('These are the default classes when a GF field is set to medium.'),
'panel' => 'gp_gf_panel',
)
);
$wp_customize->add_section(
'gp_gf_large_class',
array(
'title' => __('Large Field Classes'),
'description' => esc_html__('These are the default classes when a GF field is set to large.'),
'panel' => 'gp_gf_panel',
)
);
// small mobile class
$wp_customize->add_setting(
'gp_gf_small_mobile',
array(
'default' => 'mobile-grid-100',
'transport' => 'refresh',
)
);
$wp_customize->add_control(
'gp_gf_small_mobile',
array(
'label' => __('Mobile Class'),
'section' => 'gp_gf_small_class',
'priority' => 10,
'type' => 'text',
'input_attrs' => array(
'placeholder' => __('mobile-grid-100'),
),
)
);
// small tablet class
$wp_customize->add_setting(
'gp_gf_small_tablet',
array(
'default' => 'tablet-grid-50',
'transport' => 'refresh',
)
);
$wp_customize->add_control(
'gp_gf_small_tablet',
array(
'label' => __('Tablet Class'),
'section' => 'gp_gf_small_class',
'priority' => 10,
'type' => 'text',
'input_attrs' => array(
'placeholder' => __('tablet-grid-50'),
),
)
);
// small desktop class
$wp_customize->add_setting(
'gp_gf_small_desktop',
array(
'default' => 'grid-33',
'transport' => 'refresh',
)
);
$wp_customize->add_control(
'gp_gf_small_desktop',
array(
'label' => __('Desktop Class'),
'section' => 'gp_gf_small_class',
'priority' => 10,
'type' => 'text',
'input_attrs' => array(
'placeholder' => __('grid-33'),
),
)
);
// medium mobile class
$wp_customize->add_setting(
'gp_gf_medium_mobile',
array(
'default' => 'mobile-grid-100',
'transport' => 'refresh',
)
);
$wp_customize->add_control(
'gp_gf_medium_mobile',
array(
'label' => __('Mobile Class'),
'section' => 'gp_gf_medium_class',
'priority' => 10,
'type' => 'text',
'input_attrs' => array(
'placeholder' => __('mobile-grid-100'),
),
)
);
// medium tablet class
$wp_customize->add_setting(
'gp_gf_medium_tablet',
array(
'default' => 'tablet-grid-50',
'transport' => 'refresh',
)
);
$wp_customize->add_control(
'gp_gf_medium_tablet',
array(
'label' => __('Tablet Class'),
'section' => 'gp_gf_medium_class',
'priority' => 10,
'type' => 'text',
'input_attrs' => array(
'placeholder' => __('tablet-grid-50'),
),
)
);
// medium desktop class
$wp_customize->add_setting(
'gp_gf_medium_desktop',
array(
'default' => 'grid-50',
'transport' => 'refresh',
)
);
$wp_customize->add_control(
'gp_gf_medium_desktop',
array(
'label' => __('Desktop Class'),
'section' => 'gp_gf_medium_class',
'priority' => 10,
'type' => 'text',
'input_attrs' => array(
'placeholder' => __('grid-50'),
),
)
);
// large mobile class
$wp_customize->add_setting(
'gp_gf_large_mobile',
array(
'default' => 'mobile-grid-100',
'transport' => 'refresh',
)
);
$wp_customize->add_control(
'gp_gf_large_mobile',
array(
'label' => __('Mobile Class'),
'section' => 'gp_gf_large_class',
'priority' => 10,
'type' => 'text',
'input_attrs' => array(
'placeholder' => __('mobile-grid-100'),
),
)
);
// large tablet class
$wp_customize->add_setting(
'gp_gf_large_tablet',
array(
'default' => 'tablet-grid-100',
'transport' => 'refresh',
)
);
$wp_customize->add_control(
'gp_gf_large_tablet',
array(
'label' => __('Tablet Class'),
'section' => 'gp_gf_large_class',
'priority' => 10,
'type' => 'text',
'input_attrs' => array(
'placeholder' => __('tablet-grid-100'),
),
)
);
// large desktop class
$wp_customize->add_setting(
'gp_gf_large_desktop',
array(
'default' => 'grid-100',
'transport' => 'refresh',
)
);
$wp_customize->add_control(
'gp_gf_large_desktop',
array(
'label' => __('Desktop Class'),
'section' => 'gp_gf_large_class',
'priority' => 10,
'type' => 'text',
'input_attrs' => array(
'placeholder' => __('grid-100'),
),
)
);
}
}
add_filter('gform_field_css_class', 'gpGfStyle::gp_gf_add_unsemantic_classes', 10, 3);
add_action('wp_enqueue_scripts', 'gpGfStyle::gp_gf_default_style');
add_action('customize_register', 'gpGfStyle::gp_gf_customizer_settings');