Last active
August 29, 2015 14:07
-
-
Save philbirnie/a70aacb7d4fc76e3bd15 to your computer and use it in GitHub Desktop.
Custom Post Boilerplate
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: BBB - Videos | |
Plugin Uri: URI | |
Description: Custom Field Type Video | |
Author: Phil Birnie | |
Version 0.9 | |
Author Uri: http://mindstreaminteractive.com | |
*/ | |
/** | |
* Set up plugin | |
*/ | |
function videoPostTypeRegister() | |
{ | |
register_post_type( | |
'bbb-video', | |
array( | |
'labels' => array( | |
'name' => __('Videos'), | |
'singular_name' => __('Video'), | |
'add_new' => __('Add new Video'), | |
'add_new_item' => __('Add new Video'), | |
'edit' => __('Edit'), | |
'edit_item' => __('Edit Video'), | |
'new_item' => __('New Video'), | |
'view' => __('View Video'), | |
'view_item' => __('View Video'), | |
'search_items' => __('Search Videos'), | |
'not_found' => __('No Video'), | |
'not_found_in_trash' => __('No Video in trash') | |
), | |
'hierarchical' => false, | |
'public' => true, | |
'menu_position' => 20, | |
'menu_icon' => 'dashicons-video-alt', | |
'has_archive' => true, | |
'description' => "A Video", | |
'taxonomies' => array('post_tag', 'category'), | |
'supports' => array('title', 'thumbnail', 'comments', 'excerpt') | |
) | |
); | |
} | |
/** | |
* Add a few custom columns to make this more usable | |
* | |
* @param array $columns Array of current menu items | |
* | |
* @return array | |
*/ | |
function setCustomVideoColumns($columns) | |
{ | |
unset($columns['comments']); | |
unset($columns['post_type']); | |
$columns['video_url'] = __('Video URL', 'bbb-video'); | |
return $columns; | |
} | |
/** | |
* Sets column contents | |
* | |
* @param string $column Column slug | |
* @param int $post_id Post Id | |
* | |
* @return void | |
*/ | |
function customVideoColumn($column, $post_id) | |
{ | |
switch ($column) { | |
case 'video_url' : | |
echo get_post_meta($post_id, 'video_url', true); | |
break; | |
} | |
} | |
add_filter('manage_edit-bbb-video_columns', 'setCustomVideoColumns'); | |
add_action('manage_bbb-video_posts_custom_column', 'customVideoColumn', 10, 2); | |
add_action('init', 'videoPostTypeRegister'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment