PluginProbe
Themify Event Post / trunk
Themify Event Post vtrunk
1.3.7 trunk 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6
themify-event-post / includes / admin.php

admin.php in Themify Event Post trunk, at includes/admin.php

340 lines 11.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Create the options page for the Event Posts plugin
4 *
5 * @since 1.0.0
6 */
7 class Themify_Event_Post_Admin {
8
9 public $options;
10
11 public function __construct() {
12 add_action( 'admin_menu', array( $this, 'setup_options_page' ), 100 );
13 add_action( 'admin_init', array( $this, 'page_init' ) );
14 add_action( 'updated_option', array( $this, 'updated_option' ), 10, 3 );
15 add_filter( 'manage_edit-event_columns', array( $this, 'type_column_header' ), 10, 2 );
16 add_action( 'manage_event_posts_custom_column', array( $this, 'type_column' ), 10, 3 );
17 add_action( 'restrict_manage_posts', array( $this, 'get_select' ) );
18 }
19
20 public function setup_options_page() {
21 add_submenu_page( 'edit.php?post_type=event', __( 'Event Settings', 'themify-event-post' ), __( 'Event Settings', 'themify-event-post' ), 'manage_options', 'themify-event-post', array( $this, 'create_admin_page' ) );
22 }
23
24 public function create_admin_page() {
25 ?>
26 <div class="wrap">
27 <h2><?php _e( 'Themify Event Post', 'themify-event-post' ); ?></h2>
28 <form method="post" action="options.php">
29 <?php
30 // This prints out all hidden setting fields
31 settings_fields( 'themify_event_post' );
32 do_settings_sections( 'themify-event-post' );
33 submit_button();
34 ?>
35 </form>
36 </div>
37 <?php
38 }
39
40 /**
41 * Register and add settings
42 */
43 public function page_init() {
44 register_setting(
45 'themify_event_post', // Option group
46 'themify_event_post' // Option name
47 );
48
49 add_settings_section(
50 'themify_event_post_archive', // ID
51 __( 'Event Archives', 'themify-event-post' ), // Title
52 null, // Callback
53 'themify-event-post' // Page
54 );
55 add_settings_section(
56 'themify_event_post_price', // ID
57 __( 'Ticket Price', 'themify-event-post' ), // Title
58 null, // Callback
59 'themify-event-post' // Page
60 );
61 add_settings_section(
62 'themify_event_post_integration', // ID
63 __( 'Integration', 'themify-event-post' ), // Title
64 null, // Callback
65 'themify-event-post' // Page
66 );
67 add_settings_section(
68 'themify_event_post_permalink', // ID
69 __( 'Permalink', 'themify-event-post' ), // Title
70 null, // Callback
71 'themify-event-post' // Page
72 );
73
74 add_settings_field(
75 'show', // ID
76 __( 'Show', 'themify-event-post' ), // Title
77 array( $this, 'show' ), // Callback
78 'themify-event-post', // Page
79 'themify_event_post_archive' // Section
80 );
81
82 add_settings_field(
83 'orderby', // ID
84 __( 'Order By', 'themify-event-post' ), // Title
85 array( $this, 'orderby' ), // Callback
86 'themify-event-post', // Page
87 'themify_event_post_archive' // Section
88 );
89
90 add_settings_field(
91 'order', // ID
92 __( 'Order', 'themify-event-post' ), // Title
93 array( $this, 'order' ), // Callback
94 'themify-event-post', // Page
95 'themify_event_post_archive' // Section
96 );
97
98 add_settings_field(
99 'layout', // ID
100 __( 'Layout', 'themify-event-post' ), // Title
101 array( $this, 'layout' ), // Callback
102 'themify-event-post', // Page
103 'themify_event_post_archive' // Section
104 );
105
106 add_settings_field(
107 'google_maps_key', // ID
108 __( 'Google Maps API Key', 'themify-event-post' ), // Title
109 array( $this, 'google_maps_key_callback' ), // Callback
110 'themify-event-post', // Page
111 'themify_event_post_integration' // Section
112 );
113
114 add_settings_field(
115 'single_permalink', // ID
116 __( 'Single Permalink', 'themify-event-post' ), // Title
117 array( $this, 'single_permalink_callback' ), // Callback
118 'themify-event-post', // Page
119 'themify_event_post_permalink' // Section
120 );
121
122 add_settings_field(
123 'category_permalink', // ID
124 __( 'Category Permalink', 'themify-event-post' ), // Title
125 array( $this, 'category_permalink_callback' ), // Callback
126 'themify-event-post', // Page
127 'themify_event_post_permalink' // Section
128 );
129
130 add_settings_field(
131 'currency', // ID
132 __( 'Currency', 'themify-event-post' ), // Title
133 array( $this, 'currency' ), // Callback
134 'themify-event-post', // Page
135 'themify_event_post_price' // Section
136 );
137 add_settings_field(
138 'currency_pos', // ID
139 __( 'Currency Position', 'themify-event-post' ), // Title
140 array( $this, 'currency_pos' ), // Callback
141 'themify-event-post', // Page
142 'themify_event_post_price' // Section
143 );
144 }
145
146 public function orderby() {
147 $value = Themify_Event_Post::get_instance()->get_option( 'orderby' );
148 $options = [
149 'date' => __( 'Date', 'themify-event-post' ),
150 'event_date' => __( 'Event Date', 'themify-event-post' ),
151 'id' => __( 'ID', 'themify-event-post' ),
152 'author' => __( 'Author', 'themify-event-post' ),
153 'title' => __( 'Title', 'themify-event-post' ),
154 'name' => __( 'Name', 'themify-event-post' ),
155 'modified' => __( 'Modified Date', 'themify-event-post' ),
156 'rand' => __( 'Random', 'themify-event-post' ),
157 'comment_count' => __( 'Comments Count', 'themify-event-post' ),
158 ];
159 echo '<select name="themify_event_post[orderby]">';
160 foreach ( $options as $key => $label ) {
161 echo '<option value="' . $key . '" ' . selected( $value, $key, false ) . '>' . $label . '</option>';
162 }
163 echo '</select>';
164 }
165
166 public function order() {
167 $value = Themify_Event_Post::get_instance()->get_option( 'order' );
168 $options = [
169 'desc' => __( 'Descending', 'themify-event-post' ),
170 'asc' => __( 'Ascending', 'themify-event-post' ),
171 ];
172 echo '<select name="themify_event_post[order]">';
173 foreach ( $options as $key => $label ) {
174 echo '<option value="' . $key . '" ' . selected( $value, $key, false ) . '>' . $label . '</option>';
175 }
176 echo '</select>';
177 }
178
179 public function layout() {
180 $value = Themify_Event_Post::get_instance()->get_option( 'layout', 'grid2' );
181 $options = [
182 'list-post' => __( '1 Column Grid', 'themify-event-post' ),
183 'grid2' => __( '2 Columns Grid', 'themify-event-post' ),
184 'grid3' => __( '3 Columns Grid', 'themify-event-post' ),
185 'grid4' => __( '4 Columns Grid', 'themify-event-post' ),
186 ];
187 echo '<select name="themify_event_post[layout]">';
188 foreach ( $options as $key => $label ) {
189 echo '<option value="' . $key . '" ' . selected( $value, $key, false ) . '>' . $label . '</option>';
190 }
191 echo '</select>';
192 }
193
194 public function show() {
195 $value = Themify_Event_Post::get_instance()->get_option( 'show' );
196 $options = [
197 'all' => __( 'All Events', 'themify-event-post' ),
198 'upcoming' => __( 'Upcoming Events', 'themify-event-post' ),
199 'past' => __( 'Past Events', 'themify-event-post' ),
200 ];
201 echo '<select name="themify_event_post[show]">';
202 foreach ( $options as $key => $label ) {
203 echo '<option value="' . $key . '" ' . selected( $value, $key, false ) . '>' . $label . '</option>';
204 }
205 echo '</select>';
206 }
207
208 public function google_maps_key_callback() {
209 $value = Themify_Event_Post::get_instance()->get_option( 'google_maps_key' );
210 printf(
211 '<input type="text" class="regular-text" id="google_maps_key" name="themify_event_post[google_maps_key]" value="%s" />',
212 esc_attr($value)
213 );
214 printf( '<p class="description">' . __( '<a href="https://developers.google.com/maps/documentation/javascript/get-api-key#key" target="_blank">Generate an API</a> key and insert it here. This is required for displaying the event location on a map.', 'themify-event-post' ) . '</p>');
215 }
216
217 public function single_permalink_callback() {
218 $value = Themify_Event_Post::get_instance()->get_option( 'single_permalink', 'event' );
219 printf(
220 '<input type="text" class="regular-text" id="single_permalink" name="themify_event_post[single_permalink]" value="%s" />',
221 esc_attr($value)
222 );
223 }
224
225 public function category_permalink_callback() {
226 $value = Themify_Event_Post::get_instance()->get_option( 'category_permalink', 'event-category' );
227 printf(
228 '<input type="text" class="regular-text" id="category_permalink" name="themify_event_post[category_permalink]" value="%s" />',
229 esc_attr($value)
230 );
231 }
232
233 public function currency() {
234 $value = Themify_Event_Post::get_instance()->get_option( 'currency' );
235 printf(
236 '<input type="text" class="small-text" id="currency" name="themify_event_post[currency]" value="%s" />',
237 esc_attr($value)
238 );
239 }
240
241 public function currency_pos() {
242 $value = Themify_Event_Post::get_instance()->get_option( 'currency_pos', 'right_space' );
243 $options = [
244 'left' => __( 'Left', 'themify-event-post' ),
245 'right' => __( 'Right', 'themify-event-post' ),
246 'left_space' => __( 'Left with space', 'themify-event-post' ),
247 'right_space' => __( 'Right with space', 'themify-event-post' ),
248 ];
249 echo '<select name="themify_event_post[currency_pos]">';
250 foreach ( $options as $key => $label ) {
251 echo '<option value="' . $key . '" ' . selected( $value, $key, false ) . '>' . $label . '</option>';
252 }
253 echo '</select>';
254 }
255
256 /**
257 * Callback for after plugin's options are saved
258 *
259 * Resets the permalinks to save new rewrite slug
260 *
261 * @since 1.0.0
262 */
263 function updated_option( $option_name, $old_value, $value ) {
264 if ( $option_name === 'themify_event_post' ) {
265 /* re-register the post type to set the new rewrite slug */
266 themify_event_post_register_post_type();
267 /* flush permalinks to save the new rewrite slug */
268 flush_rewrite_rules();
269 }
270 }
271
272 /**
273 * Display an additional column in list
274 * @param array
275 * @return array
276 */
277 function type_column_header( $columns ) {
278 unset( $columns['date'] );
279 $columns['icon'] = __( 'Image', 'themify-event-post' );
280 $columns['event_date'] = __( 'Event Date', 'themify-event-post' );
281 $columns['shortcode'] = __( 'Shortcode', 'themify-event-post' );
282 return $columns;
283 }
284
285 /**
286 * Display shortcode, type, size and color in columns in tiles list
287 * @param string $column key
288 * @param number $post_id
289 * @return string
290 */
291 function type_column( $column, $post_id ) {
292 switch ( $column ) {
293 case 'shortcode':
294 echo '<code>[themify_event_post id="' . $post_id . '"]</code>';
295 break;
296
297 case 'event_date':
298 themify_event_post_date();
299 break;
300
301 case 'icon' :
302 $image = '';
303 if ( has_post_thumbnail( $post_id ) ) {
304 $img = wp_get_attachment_image_src( get_post_thumbnail_id( $post_id ), 'thumbnail' );
305 if ( isset( $img[0] ) ) {
306 $image = '<img src="' . $img[0] . '" width="50" height="50">';
307 }
308 }
309
310 echo ! empty( $image ) ? $image : __( 'No Featured Media', 'themify-event-post' );
311 break;
312 }
313 }
314
315 /**
316 * Select form element to filter the post list
317 * @return string HTML
318 */
319 public function get_select() {
320 global $typenow;
321
322 if ( 'event' !== $typenow ) {
323 return;
324 }
325
326 $html = '';
327 foreach ( ['event-category', 'event-tag'] as $tax) {
328 $options = sprintf('<option value="">%s %s</option>', __('View All', 'themify-event-post'),
329 get_taxonomy($tax)->label);
330 $class = is_taxonomy_hierarchical($tax) ? ' class="level-0"' : '';
331 foreach (get_terms( $tax ) as $taxon) {
332 $options .= sprintf('<option %s%s value="%s">%s%s</option>', isset($_GET[$tax]) ? selected($taxon->slug, $_GET[$tax], false) : '', '0' !== $taxon->parent ? ' class="level-1"' : $class, $taxon->slug, '0' !== $taxon->parent ? str_repeat('&nbsp;', 3) : '', "{$taxon->name} ({$taxon->count})");
333 }
334 $html .= sprintf('<select name="%s" id="%s" class="postform">%s</select>', $tax, $tax, $options);
335 }
336 return print $html;
337 }
338
339 }
340