Thread Starter
Will
(@wlanni)
OK, I’m making the attempt to hack the calendar to add my own meta data in. If anyone else has done this, or has input, I’d appreciate it. I’ve got a teeny bit of experience hacking plugins to do my bidding, but this is a bit more than I’ve ever done.
Here’s my plan:
- Find the meta tag array (DONE: Line 32 in the-events-calendar.php)
- TO DO: Add the meta tags I need (I need to finalize out all the info the club needs, basically most of it is listed in my previous post)
- TO DO: Update the calendar’s interface function to add input fields when a new post is being created to account for info being added for those new meta tags
- TO DO: Update the calendar’s grid, list and single event display pages grab the meta data and display it for users
Question: Best practice on editing WordPress plugins? I figure I should NOT alter the original the-events-calendar.php. Should I use the Edit Plugins area to make these edits? And document so when the next upgrade happens, I can go back in and re-apply my edits? Or do I copy over the the-events-calendar.php file to the events directory in my theme to make these changes?
Thread Starter
Will
(@wlanni)
OK Progress! I would love feedback on how to do this so that when the next update happens I don’t lose all this work. Currently, only the public viewable files live in my themes folder. I tried copying events-meta-box.php into my theme/events but the calendar didn’t register any changes to it.
So basically the-events-calendar.php and events-meta-box.php still reside in the plugin directory, and I’m assuming updates will wipe my changes. GRRR! I have suggestions on that, I’ll post them after this:
I’ll run through what I did:
- Added custom meta data to the array in the-events-calendar.php at line 46:
///** CUSTOM!*/
'_EventAdvCost', //advanced ticket cost
'_EventAdvURL', // advanced ticket url
'_EventAge', //event age (21 or over? all ages?)
- Added functions to initialize and return the meta as strings at line 1497 (I created blank spaces):
/** CUSTOM!
* Returns Advanced Cost
*
* @return string advanced cost
*/
function the_event_advanced_cost( $postID = null) {
if ( $postId === null || !is_numeric( $postId ) ) {
global $post;
$postId = $post->ID;
}
return get_post_meta( $postId, '_EventAdvCost', true );
}
/** CUSTOM!
* Returns Advanced URL
*
* @return string advanced url
*/
function the_event_advanced_url( $postID = null) {
if ( $postId === null || !is_numeric( $postId ) ) {
global $post;
$postId = $post->ID;
}
return get_post_meta( $postId, '_EventAdvURL', true );
}
/** CUSTOM!
* Returns Age
*
* @return string Age
*/
function the_event_age( $postID = null) {
if ( $postId === null || !is_numeric( $postId ) ) {
global $post;
$postId = $post->ID;
}
return get_post_meta( $postId, '_EventAge', true );
}
- Updated the interface in events-meta-box.php at about line 357 (created new line) to add my custom advanced cost meta (at the moment I’ve only done advanced ticket cost, as the advanced url will have all kinds of special characters, and the age is going to be a radial, so I don’t know how that is going to work yet):
<!-- !CUSTOM -->
<tr>
<td><?php _e('Advanced Ticket Cost:',$this->pluginDomain); ?></td>
<td><input tabindex="2029" type='text' name='EventAdvCost' size='6' value='<?php echo $_EventAdvCost; ?>' /></td>
</tr>
<tr>
<td></td>
<td><small><?php _e('Leave blank to hide the field. Enter a 0 for events that are free.', $this->pluginDomain); ?></small></td>
</tr>
<!-- /!CUSTOM -->
- Updated /themes/[my theme directory]/events/single.php to add the advanced ticket cost information, line 26:
<!--CUSTOM!-->
<?php if ( the_event_advanced_cost() ) : ?>
<dt><?php _e('Adv. Tix:', $spEvents->pluginDomain) ?></dt>
<dd><?php echo the_event_advanced_cost(); ?></dd>
<?php endif; ?>
<!--/Custom!-->
So, again, I haven’t added in the other fields (the url for advanced ticket url, or the age restriction), and if I need to do anything weird to get them to work I’ll post back here. Otherwise, follow the example above.
Thread Starter
Will
(@wlanni)
FEATURE REQUEST/SUGGESTION!
Please make it so any of the files we move from /plugins/wp-events-calendar/views into /themes/[my theme]/events to custom edit are read into the plugin. Specifically events-meta-box.php, in my case, but any file for future customization.
Please allow for a check against a custom functions.php in the /themes/[my theme]/events that uses hooks or filters? I am using Thematic, and all of my theme customizations are done in a functions.php that modifies Thematic’s built in functions, all using hooks and filters. This way all my customizations are kept separate from the theme’s files, keeping updating safe.
I’ll post these into new feature request posts as well.
We have been debating how to allow people to add custom meta fields. My preference would be to integrate with a custom meta plugin (there are a bunch).
Nice work! For the short term, you did the only thing you can do, and you will have to manually upgrade come 1.6. Not terrible but not beautiful.