This repository has been archived by the owner on Jun 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
SimpleFieldsQuickConfig.class.php
326 lines (312 loc) · 10.1 KB
/
SimpleFieldsQuickConfig.class.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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
<?php
/**
* Contains SimpleFieldsQuickConfig class definition
*/
/**
* Perform a quick configuration for Simple Fields plugin
*
* It uses the default values used by FastBooking
* By default you only need to call in functions.php:
* <code>new SimpleFieldsQuickConfig();</code>
* @author etessore
* @version 1.0
* @package classes
*/
class SimpleFieldsQuickConfig{
/**
* @var string the post type
*/
private $post_type;
/**
* @var array stores the Simple Fields groups
*/
private $groups;
/**
* @var array Simple Fields connectors
*/
private $connectors;
/**
* Initializes the default values
*/
public function __construct(){
$post_type = array ( "0" => '', "page" => '__inherit__', ) ;
$groups = array (
"1" => array (
"id" => '1',
"name" => 'Map Data',
"repeatable" => '1',
"fields" => array (
"1" => array (
"name" => 'Center Latitude',
"description" => 'ex: 40.123456',
"type" => 'text',
"type_post_options" => array (
"additional_arguments" => '', ),
"type_taxonomyterm_options" => array (
"enabled_taxonomy" => '',
"additional_arguments" => '', ),
"id" => '1', "deleted" => '0', ),
"2" => array (
"name" => 'Center Longitude',
"description" => 'ex: 8.123456',
"type" => 'text',
"type_post_options" => array (
"additional_arguments" => '', ),
"type_taxonomyterm_options" => array (
"enabled_taxonomy" => '',
"additional_arguments" => '', ),
"id" => '2', "deleted" => '0', ),
"3" => array (
"name" => 'Latitude',
"description" => 'ex: 40.123456',
"type" => 'text',
"type_post_options" => array (
"additional_arguments" => '', ),
"type_taxonomyterm_options" => array (
"enabled_taxonomy" => '',
"additional_arguments" => '', ),
"id" => '3', "deleted" => '0', ),
"4" => array (
"name" => 'Longitude',
"description" => 'ex: 8.123456',
"type" => 'text',
"type_post_options" => array (
"additional_arguments" => '', ),
"type_taxonomyterm_options" => array (
"enabled_taxonomy" => '',
"additional_arguments" => '', ),
"id" => '4', "deleted" => '0', ),
"5" => array (
"name" => 'Balloon Title',
"description" => 'The title of the pop-up',
"type" => 'text',
"type_post_options" => array (
"additional_arguments" => '', ),
"type_taxonomyterm_options" => array (
"enabled_taxonomy" => '',
"additional_arguments" => '', ),
"id" => '5', "deleted" => '0', ),
"6" => array (
"name" => 'Balloon Text',
"description" => 'The content of the pop-up',
"type" => 'textarea',
"type_textarea_options" => array (
"use_html_editor" => '1', ),
"type_post_options" => array (
"additional_arguments" => '', ),
"type_taxonomyterm_options" => array (
"enabled_taxonomy" => '',
"additional_arguments" => '', ),
"id" => '6', "deleted" => '0', ),
"7" => array (
"name" => 'Zoom',
"description" => 'Zoom of the map',
"type" => 'text',
"type_post_options" => array (
"additional_arguments" => '', ),
"type_taxonomyterm_options" => array (
"enabled_taxonomy" => '',
"additional_arguments" => '', ),
"id" => '7', "deleted" => '0', ),
"8" => array (
"name" => 'Map Type',
"description" => 'Type of the map',
"type" => 'dropdown',
"type_post_options" => array (
"additional_arguments" => '', ),
"type_taxonomyterm_options" => array (
"enabled_taxonomy" => '',
"additional_arguments" => '', ),
"type_dropdown_options" => array(
"dropdown_num_1" => array( "value" => 'ROADMAP', "deleted" => '0'),
"dropdown_num_2" => array( "value" => 'SATELLITE', "deleted" => '0'),
"dropdown_num_3" => array( "value" => 'HYBRID', "deleted" => '0'),
"dropdown_num_4" => array( "value" => 'TERRAIN', "deleted" => '0'),
),
"id" => '8', "deleted" => '0', ),
),
"deleted" => '',
"description" => 'Contains map datas for creating pop-up in the google maps',
"type_textarea_options" => array ( ),
"type_radiobuttons_options" => array ( ),
"type_taxonomy_options" => array ( ),
),
"2" => array (
"id" => '2',
"name" => 'Special Offers',
"repeatable" => '',
"fields" => array (
"1" => array (
"name" => 'Promo Code',
"description" => 'Copy/paste promo code from the BE back-office',
"type" => 'text',
"type_post_options" => array (
"additional_arguments" => '', ),
"type_taxonomyterm_options" => array (
"enabled_taxonomy" => '',
"additional_arguments" => '', ),
"id" => '1', "deleted" => '0', ),
"2" => array (
"name" => 'Offer Subtitle',
"description" => 'Catch phrase of your offer',
"type" => 'textarea',
"type_post_options" => array (
"additional_arguments" => '', ),
"type_taxonomyterm_options" => array (
"enabled_taxonomy" => '',
"additional_arguments" => '', ),
"id" => '2', "deleted" => '0', ), ),
"deleted" => '',
"description" => '(Fill in only if the page is a special offer)',
"type_textarea_options" => array ( ),
"type_radiobuttons_options" => array ( ),
"type_taxonomy_options" => array ( ),
),
"3" => array (
"id" => '3',
"name" => 'Subtitle',
"repeatable" => '',
"fields" => array (
"1" => array (
"name" => 'Subtitle',
"description" => ' ',
"type" => 'textarea',
"type_textarea_options" => array (
"use_html_editor" => '1', ),
"type_post_options" => array (
"additional_arguments" => '', ),
"type_taxonomyterm_options" => array (
"enabled_taxonomy" => '',
"additional_arguments" => '', ),
"id" => '1',
"deleted" => '0',
)
),
"deleted" => '',
"description" => '',
"type_textarea_options" => array ( ),
"type_radiobuttons_options" => array ( ),
"type_taxonomy_options" => array ( ),
)
);
$connectors = array (
"1" => array (
"id" => '1',
"name" => 'Page with Map',
"field_groups" => array (
"1" => array (
"id" => '1',
"name" => 'Map Data',
"deleted" => '0',
"context" => 'advanced',
"priority" => 'high', ), ),
"post_types" => array (
"0" => 'page', ),
"deleted" => '',
"hide_editor" => '', ),
"2" => array (
"id" => '2',
"name" => 'Page with Offer',
"field_groups" => array (
"2" => array (
"id" => '2',
"name" => 'Special Offers',
"deleted" => '0',
"context" => 'advanced',
"priority" => 'high', ),
),
"post_types" => array (
"0" => 'page', ),
"deleted" => '',
"hide_editor" => '', ),
"3" => array (
"id" => '3',
"name" => 'Full Options',
"field_groups" => array (
"2" => array (
"id" => '2',
"name" => 'Special Offers',
"deleted" => '0',
"context" => 'normal',
"priority" => 'low', ),
"1" => array (
"id" => '1',
"name" => 'Map Data',
"deleted" => '0',
"context" => 'normal',
"priority" => 'low', ),
),
"post_types" => array (
"0" => 'page', ),
"deleted" => '',
"hide_editor" => '',
),
"4" => array (
"id" => '4',
"name" => 'Page with Subtitle',
"field_groups" => array (
"3" => array (
"id" => '3',
"name" => 'Subtitle',
"deleted" => '0',
"context" => 'normal',
"priority" => 'low', )
),
"post_types" => array (
"0" => 'page', ),
"deleted" => '',
"hide_editor" => '', )
);
$this
->set_connectors($connectors)
->set_groups($groups)
->set_post_type($post_type)
->check_config();
}
/**
* Set the post type to the given parameter
* @param array $post_type the post type
*/
public function set_post_type($post_type){
$this->post_type = $post_type;
return $this;
}
/**
* Set the post groups to the given parameter
* @param array $groups the groups
*/
public function set_groups($groups){
$this->groups = $groups;
return $this;
}
/**
* Set the post connectors to the given parameter
* @param array $connectors the post connectors
*/
public function set_connectors($connectors){
$this->connectors = $connectors;
return $this;
}
/**
* Check if a config for the Simple Fields plugin exists,
* elsewhere it will add the default one.
* For better performance this check is limited
* only to the admin pages, not to the public pages.
* So if you wanna add the default values you'll have to visit wp-admin
*/
function check_config() {
if( ! is_admin() ){
return $this;
}
if ( ! get_option('simple_fields_post_type_defaults',false)) {
update_option('simple_fields_post_type_defaults', $this->post_type);
}
if ( ! get_option('simple_fields_groups',false)) {
update_option('simple_fields_groups', $this->groups);
}
if ( ! get_option('simple_fields_post_connectors',false)) {
update_option('simple_fields_post_connectors', $this->connectors);
}
return $this;
}
}