-
Notifications
You must be signed in to change notification settings - Fork 76
/
event-organiser-manage.php
279 lines (237 loc) · 8.33 KB
/
event-organiser-manage.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
<?php
/**
* Functions altering the CPT Event table
*
* @since 1.0.0
*/
/**
* Adds custom columns to Event CPT table
* @since 1.0.0
* @access private
* @ignore
*/
function eventorganiser_event_add_columns( $columns ) {
unset( $columns['date'] );//Unset unnecessary columns
//Set 'title' column title
$columns['title'] = __( 'Event', 'eventorganiser' );
//If displaying 'author', change title
if ( isset( $columns['author'] ) ) {
$columns['author'] = __( 'Organiser', 'eventorganiser' );
}
if ( isset( $columns['author'] ) && ! eo_is_multi_event_organiser() ) {
unset( $columns['author'] );
}
if ( taxonomy_exists( 'event-venue' ) ) {
$tax = get_taxonomy( 'event-venue' );
$columns['venue'] = $tax->labels->singular_name;
}
$columns['datestart'] = __( 'Start Date/Time', 'eventorganiser' );
$columns['dateend'] = __( 'End Date/Time', 'eventorganiser' );
$columns['reoccurence'] = __( 'Recurrence', 'eventorganiser' );
return $columns;
}
add_filter( 'manage_edit-event_columns', 'eventorganiser_event_add_columns' );
/**
* Registers the custom columns in Event CPT table to be sortable
* @since 1.0.0
* @access private
* @ignore
*/
add_filter( 'manage_edit-event_sortable_columns', 'eventorganiser_event_sortable_columns' );
function eventorganiser_event_sortable_columns( $columns ) {
$columns['datestart'] = 'eventstart';
$columns['dateend'] = 'eventend';
return $columns;
}
/**
* What to display in custom columns of Event CPT table
* @since 1.0.0
* @access private
* @ignore
*/
add_action( 'manage_event_posts_custom_column', 'eventorganiser_event_fill_columns', 10, 2 );
function eventorganiser_event_fill_columns( $column_name, $id ) {
global $post;
$series_id = ( empty( $post->event_id ) ? $id :'' );
$php_format = 'M, j Y';
if ( ! eo_is_all_day( $series_id ) ) {
$php_format .= '\<\b\r\>' . get_option( 'time_format' );
}
switch ( $column_name ) {
case 'venue':
$taxonomy_object = get_taxonomy( 'event-venue' );
$venue_id = eo_get_venue( $post->ID );
$venue_slug = eo_get_venue_slug( $post->ID );
$venue_name = eo_get_venue_name( $venue_id );
if ( $venue_id ) {
printf( '<a href="%s">%s</a>', esc_url( add_query_arg( 'event-venue', $venue_slug ) ), esc_html( $venue_name ) );
printf( '<input type="hidden" value="%d"/>', $venue_id );
} else {
echo '<span aria-hidden="true">—</span><span class="screen-reader-text">' . $taxonomy_object->labels->no_terms . '</span>';
}
break;
case 'datestart':
$schedule = eo_get_event_schedule( $series_id );
echo eo_format_datetime( $schedule['start'], $php_format );
break;
case 'dateend':
$schedule = eo_get_event_schedule( $series_id );
echo eo_format_datetime( $schedule['end'], $php_format );
break;
case 'reoccurence':
echo eo_get_schedule_summary( $series_id );
break;
} // end switch
}
/**
* Adds a drop-down filter to the Event CPT table by category
* @since 1.0.0
*/
add_action( 'restrict_manage_posts', 'eventorganiser_restrict_events_by_category' );
function eventorganiser_restrict_events_by_category() {
global $typenow;
$category_tax = get_taxonomy( 'event-category' );
if ( 'event' == $typenow && $category_tax && wp_count_terms( 'event-category' ) > 0 ) {
eo_taxonomy_dropdown( array(
'taxonomy' => 'event-category',
'selected' => get_query_var( 'event-category' ),
'hide_empty' => false,
'show_option_all' => $category_tax->labels->view_all_items,
) );
}
}
/**
* Adds a drop-down filter to the Event CPT table by venue
* @since 1.0.0
*/
add_action( 'restrict_manage_posts', 'eventorganiser_restrict_events_by_venue' );
function eventorganiser_restrict_events_by_venue() {
global $typenow;
$venue_tax = get_taxonomy( 'event-venue' );
//Only add if CPT is event
if ( 'event' == $typenow && $venue_tax && wp_count_terms( 'event-venue' ) > 0 ) {
eo_taxonomy_dropdown( array(
'taxonomy' => 'event-venue',
'selected' => get_query_var( 'event-venue' ),
'hide_empty' => false,
'show_option_all' => $venue_tax->labels->view_all_items,
) );
}
}
/**
* Adds a drop-down filter to the Event CPT table by intervals
* @since 1.2.0
*/
add_action( 'restrict_manage_posts', 'eventorganiser_display_occurrences' );
function eventorganiser_display_occurrences() {
global $typenow, $wp_query;
if ( 'event' == $typenow ) :
$intervals = array(
'all' => __( 'View all events', 'eventorganiser' ),
'future' => __( 'Future events', 'eventorganiser' ),
'expired' => __( 'Expired events', 'eventorganiser' ),
'P1D' => __( 'Events within 24 hours', 'eventorganiser' ),
'P1W' => __( 'Events within 1 week', 'eventorganiser' ),
'P2W' => sprintf( __( 'Events within %d weeks', 'eventorganiser' ), 2 ),
'P1M' => __( 'Events within 1 month', 'eventorganiser' ),
'P6M' => sprintf( __( 'Events within %d months', 'eventorganiser' ), 6 ),
'P1Y' => __( 'Events within 1 year', 'eventorganiser' ),
);
//@see https://core.trac.wordpress.org/ticket/16471
$current = ( get_query_var( 'eo_interval' ) ? get_query_var( 'eo_interval' ) : 'all' );
?>
<select style="width:150px;" name='eo_interval' id='show-events-in-interval' class='postform'>
<?php foreach ( $intervals as $id => $interval ) : ?>
<option value="<?php echo $id; ?>" <?php selected( $current, $id )?>> <?php echo $interval;?> </option>
<?php endforeach; ?>
</select>
<?php
endif;//End if CPT is event
}
/*
* Bulk and quick editting of venues. Add drop-down menu for quick editing
* @since 3.0.0
* @private
*/
function eventorganiser_quick_bulk_edit_box( $column_name, $post_type ) {
if ( 'venue' != $column_name || 'event' != $post_type ) {
return;
}
$tax = get_taxonomy( 'event-venue' );
$args = array(
'orderby' => 'name',
'hide_empty' => 0,
'name' => 'eo_input[event-venue]',
'taxonomy' => 'event-venue',
);
if ( 'quick_edit_custom_box' == current_filter() ) {
$args['id'] = 'eventorganiser_venue';
$args['show_option_all'] = $tax->labels->no_terms;
} else {
$args['id'] = 'eventorganiser_venue_bulk';
$args['show_option_none'] = __( '— No Change —', 'eventorganiser' );
}
?>
<fieldset class="inline-edit-col-left">
<div class="inline-edit-col">
<?php wp_nonce_field( 'eventorganiser_event_quick_edit_' . get_current_blog_id(), '_eononce' );?>
<label class="">
<span class="title"><?php echo esc_html( $tax->labels->singular_name ); ?></span>
<?php wp_dropdown_categories( $args ); ?>
</label>
</div>
</fieldset>
<?php
}
add_action( 'quick_edit_custom_box', 'eventorganiser_quick_bulk_edit_box', 10, 2 );
add_action( 'bulk_edit_custom_box', 'eventorganiser_quick_bulk_edit_box', 10, 2 );
/*
* Bulk and quick editting of venues. Save venue update.
* @Since 1.3
*/
add_action( 'save_post', 'eventorganiser_quick_edit_save' );
function eventorganiser_quick_edit_save( $post_id ) {
$request = array_merge( $_GET, $_POST );
//make sure data came from our quick/bulk box
if ( ! isset( $request['_eononce'] ) || ! wp_verify_nonce( $request['_eononce'], 'eventorganiser_event_quick_edit_' . get_current_blog_id() ) ) {
return;
}
// verify this is not an auto save routine.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return;
}
//verify this is not a cron job
if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
return;
}
//authentication checks
if ( ! current_user_can( 'edit_event', $post_id ) ) {
return;
}
$venue_id = ( isset( $request['eo_input']['event-venue'] ) ? (int) $request['eo_input']['event-venue'] : - 1 );
if ( $venue_id >= 0 ) {
$r = wp_set_post_terms( $post_id, array( $venue_id ), 'event-venue', false );
}
/**
* Triggered after an event has been updated.
*
* @param int $post_id The ID of the event
*/
do_action( 'eventorganiser_save_event', $post_id );
return;
}
add_action( 'admin_head-edit.php', 'eventorganiser_quick_edit_script' );
function eventorganiser_quick_edit_script() {
?>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery( '#the-list' ).on( 'click', '.editinline', function() {
jQuery( '#eventorganiser_venue option' ).attr("selected", false);
var id = inlineEditPost.getId(this);
var val = parseInt(jQuery( '#post-' + id + ' td.column-venue input' ).val() );
jQuery( '#eventorganiser_venue option[value="'+val+'"]' ).attr( 'selected', 'selected' );
});
});
</script>
<?php
}