-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfields.php
More file actions
150 lines (142 loc) · 4.99 KB
/
fields.php
File metadata and controls
150 lines (142 loc) · 4.99 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
<?php
/**
* Add custom fields using Advanced Custom Fields
*
* Advanced Custom Fields uses functions to add fields, so this file should
* return if the Advanced Custom Fields plugin is not installed.
*/
add_action(
'acf/init',
function () {
// Generate list of times
$start = mktime(0, 0, 0);
$times = array();
for ($i = 0; $i < 86400; $i += 1800) {
$time = date('H:i', $start + $i);
$times[$time] = $time;
}
// Default map location
$location = apply_filters('cgit_wp_acf_events_default_map_location', [0, 0]);
$center_lat = $location[0];
$center_lng = $location[1];
// If they've installed OpenStreetMap for ACF then let's assume they want to use that
$map_provider = 'google_map';
if (class_exists("ACFFieldOpenstreetmap\Field\OpenStreetMap")) {
$map_provider = 'open_street_map';
}
// Add date and time fields
$date_time_fields = array(
'key' => 'cgit_wp_events_when',
'title' => 'When',
'fields' => array(
array(
'key' => 'start_date',
'name' => 'start_date',
'label' => 'Start date',
'type' => 'date_picker',
'required' => true,
),
array(
'key' => 'start_time',
'name' => 'start_time',
'label' => 'Start time',
'type' => 'select',
'choices' => $times,
'conditional_logic' => array(
array(
array(
'field' => 'all_day',
'operator' => '!=',
'value' => '1',
),
),
),
),
array(
'key' => 'end_date',
'name' => 'end_date',
'label' => 'End date',
'type' => 'date_picker',
),
array(
'key' => 'end_time',
'name' => 'end_time',
'label' => 'End time',
'type' => 'select',
'choices' => $times,
'conditional_logic' => array(
array(
array(
'field' => 'all_day',
'operator' => '!=',
'value' => '1',
),
),
),
),
array(
'key' => 'all_day',
'name' => 'all_day',
'label' => 'All day event?',
'type' => 'true_false',
),
),
'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => CGIT_EVENTS_POST_TYPE,
),
),
),
'position' => 'side',
);
$date_time_fields = apply_filters('cgit_wp_acf_fields_date_time', $date_time_fields);
acf_add_local_field_group($date_time_fields);
// Add location fields
$location_fields = array(
'key' => 'cgit_wp_events_where',
'title' => 'Where',
'fields' => array(
array(
'key' => 'location_name',
'name' => 'location_name',
'label' => 'Location name',
'type' => 'text',
),
array(
'key' => 'location_address',
'name' => 'location_address',
'label' => 'Address',
'type' => 'textarea',
),
array(
'key' => 'location',
'name' => 'location',
'label' => 'Location',
'type' => $map_provider,
'center_lat' => $center_lat,
'center_lng' => $center_lng,
),
array(
'key' => 'price',
'name' => 'price',
'label' => 'Price',
'type' => 'number',
),
),
'location' => array(
array(
array(
'param' => 'post_type',
'operator' => '==',
'value' => CGIT_EVENTS_POST_TYPE,
),
),
),
);
$location_fields = apply_filters('cgit_wp_acf_fields_location', $location_fields);
acf_add_local_field_group($location_fields);
}
);