forked from stephenharris/Event-Organiser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent-organiser-manage.php
239 lines (200 loc) · 7.86 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
<?php
/**
* Functions altering the CPT Event table
*
* @since 1.0.0
*/
/**
* Adds custom columns to Event CPT table
* @since 1.0.0
*/
add_filter('manage_edit-event_columns', 'eventorganiser_event_add_columns');
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');
$columns['venue'] = __('Venue','eventorganiser');
$columns['eventcategories'] = __('Categories');
$columns['datestart'] = __('Start Date/Time','eventorganiser');
$columns['dateend'] = __('End Date/Time', 'eventorganiser');
$columns['reoccurence'] = __('Reoccurrence','eventorganiser');
return $columns;
}
/**
* Registers the custom columns in Event CPT table to be sortable
* @since 1.0.0
*/
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
*/
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 :'');
;
$phpFormat = 'M, jS Y';
if(!eo_is_all_day($series_id))
$phpFormat .= '\<\/\b\r\>'. get_option('time_format');
switch ($column_name) {
case 'venue':
$terms = get_the_terms($post->ID, 'event-venue');
if ( !empty($terms) ) {
foreach ( $terms as $term )
$post_terms[] = "<a href='".add_query_arg( 'event-venue', $term->slug)."'>".esc_html(sanitize_term_field('name', $term->name, $term->term_id,'event-venue', 'display'))."</a>";
echo join( ', ', $post_terms );
echo "<input type='hidden' value='".$term->term_id."'/>";
}
break;
case 'datestart':
eo_the_start($phpFormat,$series_id );
break;
case 'dateend':
eo_the_end($phpFormat,$series_id );
break;
case 'reoccurence':
eo_display_reoccurence($series_id );
break;
case 'eventcategories':
$terms = get_the_terms($post->ID, 'event-category');
if ( !empty($terms) ) {
foreach ( $terms as $term )
$post_terms[] = "<a href='".add_query_arg( 'event-category', $term->slug)."'>".esc_html(sanitize_term_field('name', $term->name, $term->term_id,'event-category', 'display'))."</a>";
echo join( ', ', $post_terms );
}
break;
default:
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() {
// only display these taxonomy filters on desired custom post_type listings
global $typenow,$wp_query;
if ($typenow == 'event') {
eo_event_category_dropdown(array('hide_empty'=>false,'show_option_all' => __('View all categories')));
}
}
/**
* 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;
//Only add if CPT is event
if ($typenow=='event') :
eo_event_venue_dropdown(array('hide_empty'=>false,'show_option_all' => __('View all venues','eventorganiser')));
endif;
}
/**
* 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 ($typenow == 'event'):
$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'),
);
$current = (!empty($wp_query->query_vars['eo_interval']) ? $wp_query->query_vars['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 1.3
*/
add_action('quick_edit_custom_box', 'eventorganiser_quick_edit_box', 10, 2);
function eventorganiser_quick_edit_box($column_name, $post_type) {
if ($column_name != 'venue' || $post_type !='event') return;?>
<fieldset class="inline-edit-col-left"><div class="inline-edit-col">
<?php wp_nonce_field('eventorganiser_event_quick_edit','_eononce');?>
<label class="">
<span class="title">Event Venue</span><?php
$args = array('show_option_all' =>'No venue','orderby'=> 'name','hide_empty' => 0, 'name'=> 'eo_input[event-venue]','id'=> 'eventorganiser_venue','taxonomy'=> 'event-venue');
wp_dropdown_categories( $args ); ?>
</label>
</div></fieldset>
<?php
}
/*
* Bulk and quick editting of venues. Add drop-down menu for bulk editing
* @Since 1.3
*/
add_action('bulk_edit_custom_box', 'eventorganiser_bulk_edit_box', 10, 2);
function eventorganiser_bulk_edit_box($column_name, $post_type) {
if ($column_name != 'venue' || $post_type !='event') return;?>
<fieldset class="inline-edit-col-left"><div class="inline-edit-col">
<?php wp_nonce_field('eventorganiser_event_quick_edit','_eononce');?>
<label class="">
<span class="title">Event Venue</span><?php
$args = array('show_option_none' => __( '— No Change —' ),'orderby'=> 'name','hide_empty' => 0, 'name'=> 'eo_input[event-venue]','id'=> 'eventorganiser_venue_bulk','taxonomy'=> 'event-venue');
wp_dropdown_categories( $args ); ?>
</label>
</div></fieldset>
<?php
}
/*
* 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) {
global $wpdb,$eventorganiser_events_table;
// verify this is not an auto save routine.
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE ) return $post_id;
//make sure data came from our quick/bulk box
if(!isset($_REQUEST['_eononce']) || !wp_verify_nonce($_REQUEST['_eononce'],'eventorganiser_event_quick_edit' ))
return;
//authentication checks
if (!current_user_can('edit_event', $post_id)) return $post_id;
$venue_id =(isset($_REQUEST['eo_input']['event-venue']) ? (int) $_REQUEST['eo_input']['event-venue'] : -1);
if($venue_id < 0) return;
//Update venue
$r = wp_set_post_terms( $post_id, array($venue_id), 'event-venue', false );
$upd = $wpdb->update( $eventorganiser_events_table, array('Venue'=>$venue_id), array( 'post_id' => $post_id ));
}
add_action('admin_head-edit.php', 'eventorganiser_quick_edit_script');
function eventorganiser_quick_edit_script() { ?>
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('a.editinline').live('click', function() {
jQuery('#eventorganiser_venue option[value=0]').attr('selected', 'selected');
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
}
?>