Created
August 27, 2016 10:56
-
-
Save DustinHartzler/54d34802aca06ab606f9cc90f657d825 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| Plugin Name: Custom Post Types | |
| Description: Add on plugin that adds custom post types to theme | |
| Version: 1.0 | |
| Plugin URI: http://yourwebsiteengineer.com | |
| Author: Dustin Hartzler | |
| */ | |
| #----------------------------------------------------------------- | |
| # Add support for Custom Post Type | |
| #----------------------------------------------------------------- | |
| function dh_custom_posttypes() { | |
| //Webinars | |
| $labels = array( | |
| 'name' => _x( 'Webinars', 'post type general name' ), | |
| 'singular_name' => _x( 'Webinar', 'post type singular name' ), | |
| 'add_new' => _x( 'Add New', 'book' ), | |
| 'add_new_item' => __( 'Add New Webinar' ), | |
| 'edit_item' => __( 'Edit Webinar' ), | |
| 'new_item' => __( 'New Webinar' ), | |
| 'all_items' => __( 'All Webinars' ), | |
| 'view_item' => __( 'View Webinar' ), | |
| 'search_items' => __( 'Search All Webinars' ), | |
| 'not_found' => __( 'Nothing found' ), | |
| 'not_found_in_trash' => __( 'Nothing found in the Trash' ), | |
| 'parent_item_colon' => '', | |
| 'menu_name' => 'Webinars' | |
| ); | |
| $args = array( | |
| 'labels' => $labels, | |
| 'description' => 'Holds all Webinars', | |
| 'public' => true, | |
| 'menu_position' => 5, | |
| 'menu_icon' => 'dashicons-welcome-learn-more', | |
| 'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments', 'revisions', 'custom-fields' ), | |
| 'has_archive' => true, | |
| ); | |
| register_post_type( 'Webinars', $args ); | |
| } | |
| add_action( 'init', 'dh_custom_posttypes' ); | |
| /** | |
| * Add custom taxonomies | |
| * | |
| * Additional custom taxonomies can be defined here | |
| * http://codex.wordpress.org/Function_Reference/register_taxonomy | |
| */ | |
| function add_custom_taxonomies() { | |
| // Add new "Webinar Category" taxonomy to Custom Post Type | |
| register_taxonomy('webinar_categories', 'webinars', array( | |
| // Hierarchical taxonomy (like categories) | |
| 'hierarchical' => true, | |
| // This array of options controls the labels displayed in the WordPress Admin UI | |
| 'labels' => array( | |
| 'name' => _x( 'Webinars', 'taxonomy general name' ), | |
| 'singular_name' => _x( 'Webinar', 'taxonomy singular name' ), | |
| 'search_items' => __( 'Search Webinars' ), | |
| 'all_items' => __( 'All Webinars' ), | |
| 'parent_item' => __( 'Parent Webinar' ), | |
| 'parent_item_colon' => __( 'Parent Webinar:' ), | |
| 'edit_item' => __( 'Edit Webinar' ), | |
| 'update_item' => __( 'Update Webinar' ), | |
| 'add_new_item' => __( 'Add New Webinar Category' ), | |
| 'new_item_name' => __( 'New Webinar Name' ), | |
| 'menu_name' => __( 'Categories' ), | |
| ), | |
| // Control the slugs used for this taxonomy | |
| 'rewrite' => array( | |
| 'slug' => 'webinar', // This controls the base slug that will display before each term | |
| 'with_front' => false, // Don't display the category base before "/tips/" | |
| 'hierarchical' => true // This will allow URL's like "/tips/boston/cambridge/" | |
| ), | |
| )); | |
| } | |
| add_action( 'init', 'add_custom_taxonomies', 0 ); | |
| function metaboxes(){ | |
| add_action('add_meta_boxes', function(){ | |
| //This connects the webinar meta boxes to the Custom Post Types | |
| add_meta_box ('webinar_resources', 'Webinar Assets', 'webinar_assets', 'webinars'); | |
| }); | |
| function webinar_assets($post){ | |
| $video = get_post_meta($post->ID, 'webinar_video', true); | |
| $audio = get_post_meta($post->ID, 'webinar_audio', true); | |
| $pdf = get_post_meta($post->ID, 'webinar_pdf', true); | |
| ?> | |
| <p> | |
| <table> | |
| <tr> | |
| <label for="webinar_video">Video File: </label> | |
| <input type="text" class="widefat" name="webinar_video" id="webinar_video" | |
| value="<?php echo esc_attr($video); ?>"?> | |
| </tr> | |
| <tr> | |
| <label for="webinar_audio">Audio File: </label> | |
| <input type="text" class="widefat" name="webinar_audio" id="webinar_audio" | |
| value="<?php echo esc_attr($audio); ?>"?> | |
| </tr> | |
| <tr> | |
| <label for="webinar_pdf">PDF File: </label> | |
| <input type="text" class="widefat" name="webinar_pdf" id="webinar_pdf" | |
| value="<?php echo esc_attr($pdf); ?>"?> | |
| </tr> | |
| </table> | |
| </p> | |
| <?php | |
| } | |
| add_action('save_post', function($id){ | |
| if (isset($_POST['webinar_video'])){ | |
| update_post_meta($id, 'webinar_video', strip_tags($_POST['webinar_video'])); | |
| } | |
| if (isset($_POST['webinar_audio'])){ | |
| update_post_meta($id, 'webinar_audio', strip_tags($_POST['webinar_audio'])); | |
| } | |
| if (isset($_POST['webinar_pdf'])){ | |
| update_post_meta($id, 'webinar_pdf', strip_tags($_POST['webinar_pdf'])); | |
| } | |
| }); | |
| } | |
| add_action( 'init', 'metaboxes', 0 ); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment