Created
April 23, 2017 17:07
-
-
Save tomatillodesign/e97f9691f91ee2b2f7c014ba2115a7e0 to your computer and use it in GitHub Desktop.
Custom Post Types plugin
This file contains 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 & Functionality | |
Description: Site specific code changes for WordCamp 2017 Test Site | |
Author: Chris Liu-Beers | Tomatillo Design | |
Author URI: http://www.tomatillodesign.com | |
Version: 1.1 | |
*/ | |
/* Start Adding Functions Below this Line */ | |
//Create Custom Post Types | |
add_action( 'init', 'clb_add_posts' ); | |
function clb_add_posts() { | |
// clb_create_post_types($singular, $plural, $slug, $dashicon = 'admin-post', $supports = array( 'title', 'editor', 'thumbnail', 'genesis-cpt-archives-settings', 'page-attributes', 'excerpt', 'author' )) | |
// clb_create_post_types('Book', 'Books', 'book', 'controls-repeat', array('title', 'editor')); | |
clb_create_post_types('Resource', 'Resources', 'resources', 'analytics'); | |
clb_create_post_types('Event', 'Events', 'events', 'calendar'); | |
} | |
//Create Custom Taxonomies | |
add_action( 'init', 'clb_add_taxonomies' ); | |
function clb_add_taxonomies() { | |
// clb_create_taxonomies($singular, $plural, $slug, $hierarchical = true, $post_types = array()) | |
// clb_create_taxonomies('Genre', 'Genres', 'genre', true, array( 'movie', 'post' )); | |
clb_create_taxonomies('Resource Type', 'Resource Types', 'resource-types', true, array( 'resources' )); | |
} | |
//Loops through and creates the post types | |
function clb_create_post_types($singular, $plural, $slug, $dashicon = 'admin-post', $supports = array( 'title', 'editor', 'thumbnail', 'genesis-cpt-archives-settings', 'page-attributes', 'excerpt', 'author' )) { | |
register_post_type( $slug, | |
array( | |
'labels' => array( | |
'name' => __( $plural ), | |
'singular_name' => __( $singular ), | |
'add_new' => _x('Add new ' . $singular, $plural), | |
'add_new_item' => __('Add new ' . $singular), | |
'edit_item' => __('Edit ' . $singular), | |
'new_item' => __('New ' . $singular), | |
'view_item' => __('View ' . $singular), | |
'all_items' => __( 'All ' . $plural), | |
'search_items' => __( 'Search ' . $plural), | |
'not_found' => __( 'No ' . $plural . ' found.' ), | |
), | |
'has_archive' => true, | |
'public' => true, | |
'menu_icon' => 'dashicons-' . $dashicon, // see full list of dashicons here: http://www.kevinleary.net/dashicons-custom-post-type/ | |
'show_ui' => true, // defaults to true so don't have to include | |
'show_in_menu' => true, // defaults to true so don't have to include | |
'menu_position' => 20, // set default position in left-hand WP menu | |
'rewrite' => array( 'slug' => $slug ), | |
'supports' => $supports, | |
'show_in_rest' => true, | |
) | |
); | |
} | |
//Loops through and creates the custom taxonomies | |
function clb_create_taxonomies($singular, $plural, $slug, $hierarchical = true, $post_types = array('post')) { | |
// Add new taxonomy, make it hierarchical (like categories) | |
$labels = array( | |
'name' => __( $plural ), | |
'singular_name' => __( $singular ), | |
'search_items' => __( 'Search ' . $plural ), | |
'all_items' => __( 'All ' . $plural ), | |
'parent_item' => __( 'Parent ' . $plural ), | |
'parent_item_colon' => __( 'Parent ' . $singular . ':' ), | |
'edit_item' => __( 'Edit ' . $plural ), | |
'update_item' => __( 'Update ' . $singular ), | |
'add_new_item' => __( 'Add New ' . $singular ), | |
'new_item_name' => __( 'New ' . $singular ), | |
'menu_name' => __( $plural ), | |
'not_found' => __( 'No ' . $plural . ' found.' ), | |
); | |
$args = array( | |
'hierarchical' => $hierarchical, | |
'labels' => $labels, | |
'show_ui' => true, | |
'show_admin_column' => true, | |
'query_var' => true, | |
'rewrite' => array( 'slug' => $slug ), | |
); | |
register_taxonomy( $slug, $post_types, $args ); | |
} | |
//--------- CLB Standard Site Customizations | |
//CLB Add Featured Image to Admin Column | |
add_filter('manage_posts_columns', 'clb_posts_columns', 5); | |
add_action('manage_posts_custom_column', 'clb_posts_custom_columns', 5, 2); | |
function clb_posts_columns($defaults){ | |
$defaults['clb_post_thumbs'] = __('Thumbnail'); | |
return $defaults; | |
} | |
function clb_posts_custom_columns($column_name, $id){ | |
if($column_name === 'clb_post_thumbs'){ | |
echo the_post_thumbnail( 'thumbnail' ); | |
} | |
} | |
//Add a new custom widget to the WordPress Dashboard | |
function clb_register_my_dashboard_widget_info_for_client() { | |
global $wp_meta_boxes; | |
$site_title = get_bloginfo(); | |
$welcome = 'Welcome to ' . $site_title; | |
wp_add_dashboard_widget( | |
'my_dashboard_widget', | |
$welcome, | |
'clb_my_dashboard_widget_display_text' | |
); | |
$dashboard = $wp_meta_boxes['dashboard']['normal']['core']; | |
$my_widget = array( 'my_dashboard_widget' => $dashboard['my_dashboard_widget'] ); | |
unset( $dashboard['my_dashboard_widget'] ); | |
$sorted_dashboard = array_merge( $my_widget, $dashboard ); | |
$wp_meta_boxes['dashboard']['normal']['core'] = $sorted_dashboard; | |
} | |
add_action( 'wp_dashboard_setup', 'clb_register_my_dashboard_widget_info_for_client' ); | |
function clb_my_dashboard_widget_display_text() { | |
?> | |
<p>Congratulations on launching your new website. There are videos and a training manual for common tasks in the upper left, under the "Manual" tab.</p> | |
<p>Please don't hesitate to contact me if you have any questions:<br/> | |
<a href="http://www.tomatillodesign.com" title="Beautiful, Affordable Websites for Nonprofits" target="_blank"><img src="//www.tomatillodesign.com/wp-content/uploads/2011/03/tomatillo_only_190.jpg" style="float:right"></a><a href="mailto:[email protected]" target="_blank">[email protected]</a> | 919.576.0180</p> | |
<p>Thanks for choosing to work with <a href="http://www.tomatillodesign.com" title="Beautiful, Affordable Websites for Nonprofits" target="_blank">Tomatillo Design</a>.</p> | |
<?php | |
} | |
//Set Default Image Link to "None" | |
update_option('image_default_link_type','file'); | |
//* Change the footer text | |
add_filter('genesis_footer_creds_text', 'clb_footer_creds_filter'); | |
function clb_footer_creds_filter( $creds ) { | |
$blog_title = get_bloginfo(); | |
$creds = 'Copyright [footer_copyright] <a href="' . site_url() . '">' . $blog_title . '</a> · All Rights Reserved · Website by <a href="http://www.tomatillodesign.com/" title="Amazing, Affordable Websites for Nonprofits" target="_blank">Tomatillo Design</a>'; | |
return $creds; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment