-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathrsvpmaker-types.php
347 lines (233 loc) · 8.84 KB
/
rsvpmaker-types.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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
<?php
function rsvpmaker_create_post_type() {
global $rsvp_options;
$menu_label = ( isset( $rsvp_options['menu_label'] ) ) ? $rsvp_options['menu_label'] : __( 'RSVP Events', 'rsvpmaker' );
$rewrite = array('slug' => 'rsvpmaker','with_front' => false);
$supports = array( 'title', 'editor', 'author', 'excerpt', 'custom-fields', 'thumbnail', 'revisions' );
register_post_type(
'rsvpmaker',
array(
'labels' => array(
'name' => $menu_label,
'add_new_item' => __( 'Add New RSVP Event', 'rsvpmaker' ),
'edit_item' => __( 'Edit RSVP Event', 'rsvpmaker' ),
'new_item' => __( 'RSVP Events', 'rsvpmaker' ),
'singular_name' => __( 'RSVP Event', 'rsvpmaker' ),
),
'menu_icon' => 'dashicons-calendar-alt',
'public' => true,
'can_export' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => $rewrite,
'capability_type' => 'rsvpmaker',
'map_meta_cap' => true,
'has_archive' => true,
'hierarchical' => false,
'menu_position' => 15,
'supports' => $supports,
'show_in_rest' => true,
'taxonomies' => array( 'rsvpmaker-type', 'post_tag' ),
)
);
register_post_type(
'rsvpmaker_template',
array(
'labels' => array(
'name' => 'Event Templates',
'add_new_item' => __( 'Add New RSVP Template', 'rsvpmaker' ),
'edit_item' => __( 'Edit RSVP Template', 'rsvpmaker' ),
'new_item' => __( 'RSVP Template', 'rsvpmaker' ),
'singular_name' => __( 'RSVP Template', 'rsvpmaker' ),
),
'menu_icon' => 'dashicons-calendar-alt',
'exclude_from_search' => true,
'public' => true,
'can_export' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => 'edit.php?post_type=rsvpmaker', //make submenu
'query_var' => true,
'rewrite' => array(
'slug' => 'rsvpmaker_template',
'with_front' => false,
),
'capability_type' => 'rsvpmaker',
'map_meta_cap' => true,
'has_archive' => true,
'hierarchical' => false,
'menu_position' => 15,
'supports' => $supports,
'show_in_rest' => true,
'taxonomies' => array( 'rsvpmaker-type', 'post_tag' ),
)
);
register_post_type(
'rsvpmaker_form',
array(
'labels' => array(
'name' => 'Forms',
'add_new_item' => __( 'Add New RSVP Form', 'rsvpmaker' ),
'edit_item' => __( 'Edit RSVP Form', 'rsvpmaker' ),
'new_item' => __( 'RSVP Form', 'rsvpmaker' ),
'singular_name' => __( 'RSVP Form', 'rsvpmaker' ),
),
'menu_icon' => 'dashicons-clipboard',
'public' => true,
'can_export' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => 'edit.php?post_type=rsvpmaker', //make submenu
'query_var' => true,
'rewrite' => array(
'slug' => 'rsvpmaker_form',
'with_front' => false,
),
'capability_type' => 'rsvpmaker',
'map_meta_cap' => true,
'has_archive' => false,
'hierarchical' => false,
'menu_position' => 16,
'supports' => array( 'title', 'editor', 'author', 'custom-fields', 'revisions' ),
'show_in_rest' => true,
)
);
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
'name' => _x( 'Event Types', 'taxonomy general name', 'rsvpmaker' ),
'singular_name' => _x( 'Event Type', 'taxonomy singular name', 'rsvpmaker' ),
'search_items' => __( 'Search Event Types', 'rsvpmaker' ),
'all_items' => __( 'All Event Types', 'rsvpmaker' ),
'parent_item' => __( 'Parent Event Type', 'rsvpmaker' ),
'parent_item_colon' => __( 'Parent Event Type:', 'rsvpmaker' ),
'edit_item' => __( 'Edit Event Type', 'rsvpmaker' ),
'update_item' => __( 'Update Event Type', 'rsvpmaker' ),
'add_new_item' => __( 'Add New Event Type', 'rsvpmaker' ),
'new_item_name' => __( 'New Event Type', 'rsvpmaker' ),
'menu_name' => __( 'Event Type', 'rsvpmaker' ),
);
register_taxonomy(
'rsvpmaker-type',
array( 'rsvpmaker','rsvpmaker_template' ),
array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_in_rest' => true,
'query_var' => true,
)
);
global $rsvp_options;
if ( isset( $rsvp_options['flush'] ) && $rsvp_options['flush'] ) {
flush_rewrite_rules();
}
// if there is a logged in user, set editing roles
global $current_user;
if ( isset( $current_user ) ) {
rsvpmaker_roles();
}
$model_version = 1;
if(empty($rsvp_options['model_version']) || $rsvp_options['model_version'] < $model_version) {
global $wpdb;
$wpdb->query("update $wpdb->posts set post_type='rsvpmaker_form' WHERE post_type='rsvpmaker' AND post_content LIKE '%wp:rsvpmaker/formfield%' ");
$rsvp_options['model_version'] = $model_version;
update_option('RSVPMAKER_Options',$rsvp_options);
}
}
add_filter('the_content','rsvpmaker_form_single');
function rsvpmaker_form_single($content) {
global $post, $rsvp_options;
if(!isset($post->post_type) && ('rsvpmaker_form' != $post->post_type))
return $content.' failed check '.var_export($_REQUEST,true);
if(strpos($post->post_content,'wp:rsvpmaker/formfield')) {
if(current_user_can('edit_post',$post->ID)) {
return '<p><em>This form is meant for use as part of an event, but you can edit it here.</em></p><div id="rsvpmaker-single-form" form_id="'.$post->ID.'">Loading form editor ...</div>';
}
$add_to_top = '<div><h2>Form Preview</h2></div>';
$content = $add_to_top."\n".$content;
}
elseif(isset($_POST['rsvpmultievent']))
{
ob_start();
$currency = $rsvp_options['paypal_currency'];
$currency_symbol = '';
if ( $currency == 'USD' ) {
$currency_symbol = '$';
} elseif ( $currency == 'EUR' ) {
$currency_symbol = '€';
}
$blanks = 0;
$events = [];
if(count($_POST['rsvpmultievent']) != count(array_unique($_POST['rsvpmultievent'])))
return '<p>Error: Duplicate events selected</p>';
foreach($_POST['rsvpmultievent'] as $post_id) {
if(intval($post_id)) {
$event = get_post($post_id);
$events[] = $event->post_title;
}
else
$blanks++;
}
if($blanks)
return sprintf('<p>%d %s</p>',$blanks,__('events left blank','rsvpmaker'));
$postdata = $_POST;
$atts['discount_price'] = floatval($_POST['discount_price']);
$rsvpmulti = 'rsvpmulti'.time();
$party = 1;
if($_POST['guest'])
{
foreach($_POST['guest']['first'] as $first)
{
if(!empty($first))
$party++;
}
}
$events_count = sizeof($events);
$postdata['multi_event_price'] = $party * $atts['discount_price'];
$atts['rsvpmulti'] = $rsvpmulti;
$atts['amount'] = $postdata['multi_event_price'] * $events_count;
$priceline = $currency_symbol.number_format($atts['discount_price'], 2, $rsvp_options['currency_decimal'], $rsvp_options['currency_thousands']).' '.$currency;
$atts['description'] = __('Registration for a party of','rsvpmaker').' '.$party.', '.$events_count.' events: '.implode(', ',$events).' @ '.$priceline.' '.__('per person, per event','rsvpmaker');
$atts['showdescription'] = 'yes';
echo rsvpmaker_paypay_button_embed($atts);
set_transient($rsvpmulti, $postdata, time() + HOUR_IN_SECONDS);
return ob_get_clean().$content.'<div style="margin-top:500px;"></div>';
}
return $content;
}
function create_rsvpemail_post_type() {
global $rsvp_options;
register_post_type( 'rsvpemail',
array(
'labels' => array(
'name' => __( 'RSVP Email Newsletters and Notifications','rsvpmaker' ),
'add_new_item' => __( 'Add New Email','rsvpmaker' ),
'edit_item' => __( 'Edit Email','rsvpmaker' ),
'new_item' => __( 'RSVP Emails','rsvpmaker' ),
'singular_name' => __( 'RSVP Email','rsvpmaker' )
),
'public' => true,
'exclude_from_search' => true,
'can_export' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => true,
'capabilities' => array(
'edit_post' => 'edit_rsvpemail',
'edit_posts' => 'edit_rsvpemails',
'edit_others_posts' => 'edit_others_rsvpemails',
'publish_posts' => 'publish_rsvpemails',
'read_post' => 'read_rsvpemail',
'read_private_posts' => 'read_private_rsvpemails',
'delete_post' => 'delete_rsvpemail'
),
'hierarchical' => false,
'menu_position' => 15,
'menu_icon' => 'dashicons-email-alt',
'supports' => array('title','editor'),
'show_in_rest' => true,
)
);
}