Skip to content

Instantly share code, notes, and snippets.

@michaelschofield
Created April 8, 2015 06:00
Show Gist options
  • Save michaelschofield/be81e6b3012e8469ce4d to your computer and use it in GitHub Desktop.
Save michaelschofield/be81e6b3012e8469ce4d to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: ADVWP Library Event Manager
* Plugin URI: http://classes.alaeditions.org/course/view.php?id=225
* Description: A simple library event management system.
* Version: 0.4.0
* Author: Your Name!
* Author URI: http://www.yourwebsite.com
*/
function advwp_create_the_event_post_type() {
// A PHP Array (or collection) of various settings informing how "Events" will work.
$options = array(
// Another PHP Array setting all the "Event" labels.
'labels' => array(
'name' => 'Events', // Name of the Group of Posts. This is the main label in the WordPress menu
'singular_name' => 'Event',
'all_items' => 'All Events',
'add_new' => 'Add New',
'add_new_item' => 'Add New Event',
'edit' => 'Edit',
'edit_item' => 'Edit Event',
'new_item' => 'New Event',
'view_item' => 'View Event',
'search_items' => 'Search Events',
'not_found' => 'Nothing Found',
'not_found_in_trash' => 'Nothing Found in the Trash',
'parent_item_colon' => ''
), // end of labels array
// Describe what this post type is. Often, this isn't displayed, but it doesn't hurt
'description' => 'Library Programs and Events',
// Some things are post types in WordPress you might not be aware of,
// such as menus. This `public` (true or false) option is the difference
// between whether our post type is kind of secret or hidden, used for
// an internal purpose like a menu, or if it behaves more like posts
// and pages and are public facing.
'public' => true,
// Do we want to be able to access this post type on
// the front end?
'publicly_queryable' => true,
// Do we want to prevent people from being able to
// search events?
'exclude_from_search' => false,
// Do we want there to be an "Events" label in the
// WordPress dashboard, so we can add new events and stuff?
'show_ui' => true,
// Do we ever foresee the need to be able to
// pick and choose events from the URL? E.g., have a
// complicated URL like www.example.com/events/?audience=public
'query_var' => true,
// Where do we want "Events" to appear in the menu? This is finnicky
// and may not always appear exactly in the nth position, but we
// can try.
'menu_position' => 6,
// Do we have a special icon to appear next to the menu?
// We don't, right now.
'menu_icon' => '',
// With `rewrite`, we can specify the "slug" of the URL when
// soemone goes to an event. E.g., www.example.com/event/poetry_reading/
'rewrite' => array( 'slug' => 'event', 'with_front' => false ),
// Do we want to be able to go to www.example.com/events/ and see
// all of the events we create? We cam actually specify the plural
// for our collected events.
'has_archive' => 'events',
// This option is used as a base to set which kinds of logged in users
// can create, edit, update, or delete these events. By setting it to
// `post`, we're saying: "treat Events like you treat Posts," so authors
// can create, editors can delete, subscribers can't publish, etc.
'capability_type' => 'post',
// We can set whether our post type is hierarchical. A Page is.
// this means that the "Mission" page can be the child of the
// "About" page. We probably don't need this for Events.
'hierarchical' => false,
// the next one is important, it tells what's enabled in the post editor.
// It is an array that establishes the basic layout of the editor,
// so if we didn't want to, we could totally remove the "Title" field
// - which would be silly for our Events use case, but it's a
// powerful and interesting option.
'supports' => array(
// The "Title" of the Post Type
'title',
// The main WYSIWYG
'editor',
// The featured image of the post type
'thumbnail',
// Version control. E.g., if one person updates an
// event and makes a mistake, can we just roll it back?
'revisions',
// Can authos write an excerpt / summary of the event
'excerpt',
// See or change the event's author
'author'
) // end of supports array
); // the end of the $options array
// register_post_type( 'name_of_post_type', $options );
// refer to http://codex.wordpress.org/Function_Reference/register_post_type
register_post_type( 'event', $options );
} // the end of advwp_create_the_event_post_type()
add_action( 'init', 'advwp_create_the_event_post_type' );
require_once plugin_dir_path( __FILE__ ) . 'advwp_event_manager_taxonomies.php';
function advwp_create_single_event_view( $single ) {
global $wp_query, $post;
if ( $post->post_type == 'event' ) {
return plugin_dir_path( __FILE__ ) . 'public/templates/single-event.php';
}
return $single;
}
add_filter( 'single_template', 'advwp_create_single_event_view' );
function advwp_create_archive_event_view( $archive ) {
global $post;
if ( is_post_type_archive( 'event' ) ) {
return plugin_dir_path( __FILE__ ) . 'public/templates/archive-event.php';
}
return $archive;
}
add_filter( 'archive_template', 'advwp_create_archive_event_view' );
function advwp_create_series_template( $archive ) {
global $post;
if ( is_tax( array( 'series', 'event_type', 'location', 'patron_type' ) ) ) {
return plugin_dir_path( __FILE__ ) . 'public/templates/taxonomy.php';
}
return $archive;
}
add_filter( 'archive_template', 'advwp_create_series_template' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment