Created
September 9, 2015 17:48
-
-
Save tomatillodesign/b4001238a9906e0d76d6 to your computer and use it in GitHub Desktop.
Lectionary, People & Resource Custom Post Types
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: Lectionary, People & Resource Custom Post Types | |
Description: Site specific code changes for ncchurches.org | |
Author: Chris Liu-Beers | Tomatillo Design | |
Author URI: http://www.tomatillodesign.com | |
*/ | |
/* Start Adding Functions Below this Line */ | |
//* Add a custom post type: Lectionary | |
//* Ref: http://codex.wordpress.org/Function_Reference/register_post_type | |
add_action( 'init', 'clb_post_type' ); | |
function clb_post_type() { | |
register_post_type( 'lectionary', | |
array( | |
'labels' => array( | |
'name' => __( 'Lectionary' ), | |
'singular_name' => __( 'Lectionary' ), | |
'add_new' => _x('Add new Lectionary', 'Lectionary'), | |
'add_new_item' => __('Add new Lectionary'), | |
'edit_item' => __('Edit Lectionary'), | |
'new_item' => __('New Lectionary'), | |
'view_item' => __('View Lectionary'), | |
), | |
'has_archive' => false, | |
'public' => true, | |
'menu_icon' => 'dashicons-book', // 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' => 'lectionary' ), | |
'supports' => array( 'title', 'editor', 'genesis-seo', 'thumbnail', 'excerpt', 'genesis-cpt-archives-settings' ), | |
) | |
); | |
register_post_type( 'people', | |
array( | |
'labels' => array( | |
'name' => __( 'People' ), | |
'singular_name' => __( 'People' ), | |
'add_new' => _x('Add new Person', 'People'), | |
'add_new_item' => __('Add new Person'), | |
'edit_item' => __('Edit Person'), | |
'new_item' => __('New Person'), | |
'view_item' => __('View Person'), | |
), | |
'has_archive' => false, | |
'public' => true, | |
'menu_icon' => 'dashicons-groups', // 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' => 25, // set default position in left-hand WP menu | |
'rewrite' => array( 'slug' => 'people' ), | |
'supports' => array( 'title', 'editor', 'genesis-seo', 'thumbnail', 'excerpt', 'genesis-cpt-archives-settings', 'page-attributes' ), | |
) | |
); | |
register_post_type( 'resource', | |
array( | |
'labels' => array( | |
'name' => __( 'Resources' ), | |
'singular_name' => __( 'Resource' ), | |
'add_new' => _x('Add new Resource', 'Resources'), | |
'add_new_item' => __('Add new Resource'), | |
'edit_item' => __('Edit Resource'), | |
'new_item' => __('New Resource'), | |
'view_item' => __('View Resource'), | |
), | |
'has_archive' => false, | |
'public' => true, | |
'menu_icon' => 'dashicons-book', // 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' => 25, // set default position in left-hand WP menu | |
'rewrite' => array( 'slug' => 'resource' ), | |
'supports' => array( 'title', 'editor', 'genesis-seo', 'thumbnail', 'excerpt', 'genesis-cpt-archives-settings' ), | |
'taxonomies' => array('post_tag') // this is IMPORTANT | |
) | |
); | |
} | |
//* Change default from "Add New Title" to "Title of Newsletter" in WP title bar | |
function clb_change_default_title( $title ){ | |
$screen = get_current_screen(); | |
if ( 'newsletter' == $screen->post_type ) { | |
$title = 'Title of Newsletter'; | |
} | |
return $title; | |
} | |
add_filter( 'enter_title_here', 'clb_change_default_title' ); | |
//* Change default from "Add New Title" to "Full Name" in WP title bar | |
function clb_change_default_title_people( $title ){ | |
$screen = get_current_screen(); | |
if ( 'people' == $screen->post_type ) { | |
$title = 'First & Last Name'; | |
} | |
return $title; | |
} | |
add_filter( 'enter_title_here', 'clb_change_default_title_people' ); | |
add_action( 'genesis_before_post_content', 'wps_do_post_image_check' ); | |
/* | |
* Remove genesis_do_post_image() action if on post type archive of | |
* a custom post type | |
* | |
* @global stdClass $post Post object | |
* @uses genesis_get_option() Gets the genesis option for content archive thumbnails | |
*/ | |
function wps_do_post_image_check() { | |
global $post; | |
if ( ! is_singular() && genesis_get_option( 'content_archive_thumbnail' ) && is_post_type_archive() && ! in_array( $post->newsletter, array( 'page', 'post', 'attachment' ) ) ) | |
remove_action( 'genesis_post_content', 'genesis_do_post_image' ); | |
} | |
// Create Custom Admin Columns for People | |
function clb_columns_head_only_people($defaults) { | |
$defaults['last_name'] = 'Last Name'; | |
$defaults['position'] = 'Position'; | |
$defaults['email'] = 'Email'; | |
$defaults['thumbnail'] = 'Thumbnail'; | |
return $defaults; | |
} | |
// Display the data in Custom Admin Columns for People | |
function clb_columns_content_only_people($column_name, $post_ID) { | |
if ($column_name == 'last_name') { | |
$last_name = get_field('last_name'); | |
if ($last_name) { | |
echo $last_name; | |
} | |
} | |
if ($column_name == 'position') { | |
$position = get_field('position'); | |
if ($position) { | |
echo $position; | |
} | |
} | |
if ($column_name == 'email') { | |
$email = get_field('email'); | |
if ($email) { | |
echo '<a href="mailto:' . $email . '" target="_blank">' . $email . '</a>'; | |
} | |
} | |
if ($column_name == 'thumbnail') { | |
$thumbnail = get_the_post_thumbnail( $post_id, 'thumbnail' ); | |
if ($thumbnail) { | |
echo $thumbnail; | |
} | |
} | |
} | |
// Implement Custom Columns only for Contact CPT | |
add_filter('manage_people_posts_columns', 'clb_columns_head_only_people', 10); | |
add_action('manage_people_posts_custom_column', 'clb_columns_content_only_people', 10, 2); | |
//Filter Last Name Custom Column | |
add_filter( 'manage_edit-people_sortable_columns', 'my_sortable_people_column' ); | |
function my_sortable_people_column( $columns ) { | |
$columns['last_name'] = 'last_name'; | |
//To make a column 'un-sortable' remove it from the array | |
//unset($columns['date']); | |
return $columns; | |
} | |
//Tell WP how to filter Last Name Column | |
add_action( 'pre_get_posts', 'my_slice_orderby' ); | |
function my_slice_orderby( $query ) { | |
if( ! is_admin() ) | |
return; | |
$orderby = $query->get( 'orderby'); | |
if( 'last_name' == $orderby ) { | |
$query->set('meta_key','last_name'); | |
$query->set('orderby','meta_value'); | |
} | |
} | |
// hook into the init action and call create_book_taxonomies when it fires | |
add_action( 'init', 'create_resource_taxonomy', 0 ); | |
function create_resource_taxonomy() { | |
// Add new taxonomy, make it hierarchical (like categories) | |
$labels = array( | |
'name' => __( 'Resource Categories' ), | |
'singular_name' => __( 'Resource Category' ), | |
'search_items' => __( 'Search Resource Categories' ), | |
'all_items' => __( 'All Resource Categories' ), | |
'parent_item' => __( 'Parent Resource Categories' ), | |
'parent_item_colon' => __( 'Parent Resource Category:' ), | |
'edit_item' => __( 'Edit Resource Category' ), | |
'update_item' => __( 'Update Resource Category' ), | |
'add_new_item' => __( 'Add New Resource Category' ), | |
'new_item_name' => __( 'New Genre Resource Category' ), | |
'menu_name' => __( 'Resource Categories' ), | |
); | |
$args = array( | |
'hierarchical' => true, | |
'labels' => $labels, | |
'show_ui' => true, | |
'show_admin_column' => true, | |
'query_var' => true, | |
'rewrite' => array( 'slug' => 'resource-category' ), | |
); | |
register_taxonomy( 'resource-category', array( 'resource' ), $args ); | |
// Add new taxonomy, make it hierarchical (like categories) | |
$labels = array( | |
'name' => __( 'Roles' ), | |
'singular_name' => __( 'Role' ), | |
'search_items' => __( 'Search Roles' ), | |
'all_items' => __( 'All Roles' ), | |
'parent_item' => __( 'Parent Roles' ), | |
'parent_item_colon' => __( 'Parent Role:' ), | |
'edit_item' => __( 'Edit Role' ), | |
'update_item' => __( 'Update Role' ), | |
'add_new_item' => __( 'Add New Role' ), | |
'new_item_name' => __( 'New Role' ), | |
'menu_name' => __( 'Roles' ), | |
); | |
$args = array( | |
'hierarchical' => true, | |
'labels' => $labels, | |
'show_ui' => true, | |
'show_admin_column' => true, | |
'query_var' => true, | |
'rewrite' => array( 'slug' => 'roles' ), | |
); | |
register_taxonomy( 'roles', array( 'people' ), $args ); | |
// Add new taxonomy, NOT hierarchical (like tags) | |
$labels = array( | |
'name' => _x( 'Book of the Bible', 'taxonomy general name' ), | |
'singular_name' => _x( 'Book of the Bible', 'taxonomy singular name' ), | |
'search_items' => __( 'Search Books of the Bible' ), | |
'popular_items' => __( 'Popular Books of the Bible' ), | |
'all_items' => __( 'All Books of the Bible' ), | |
'parent_item' => null, | |
'parent_item_colon' => null, | |
'edit_item' => __( 'Edit Book of the Bible' ), | |
'update_item' => __( 'Update Book of the Bible' ), | |
'add_new_item' => __( 'Add New Book of the Bible' ), | |
'new_item_name' => __( 'New Book of the Bible' ), | |
'separate_items_with_commas' => __( 'Separate Books of the Bible with commas' ), | |
'add_or_remove_items' => __( 'Add or remove Books of the Bible' ), | |
'choose_from_most_used' => __( 'Choose from the most used Books of the Bible' ), | |
'not_found' => __( 'No Books of the Bible found.' ), | |
'menu_name' => __( 'Book of the Bible' ), | |
); | |
$args = array( | |
'hierarchical' => false, | |
'labels' => $labels, | |
'show_ui' => true, | |
'show_admin_column' => true, | |
'update_count_callback' => '_update_post_term_count', | |
'query_var' => true, | |
'rewrite' => array( 'slug' => 'book_of_the_bible' ), | |
); | |
register_taxonomy( 'book_of_the_bible', array( 'lectionary' ), $args ); | |
} | |
add_action( 'admin_menu', 'my_admin_menu' ); | |
function my_admin_menu() { | |
remove_menu_page('link-manager.php'); | |
} | |
// Add Raleigh Report to top of RR posts automatically | |
add_action('genesis_entry_content', 'clb_show_rr_header', 8); | |
function clb_show_rr_header() { | |
if( is_single() && in_category( 'raleigh-report' )) { | |
echo '<a href="http://www.ncchurches.org/email/"><img class="wp-image-8551 size-full noshadow" src="http://www.ncchurches.org/wp-content/uploads/2012/07/RR-header.jpeg" alt="Click here to sign up to receive the Raleigh Report in your inbox" width="650" height="100" /></a>'; | |
} | |
} | |
//* Remove comment form allowed tags | |
add_filter( 'comment_form_defaults', 'sp_remove_comment_form_allowed_tags' ); | |
function sp_remove_comment_form_allowed_tags( $defaults ) { | |
$defaults['comment_notes_after'] = ''; | |
return $defaults; | |
} | |
//Customize Admin Columns for People Section | |
/* | |
// GET FEATURED IMAGE | |
function clb_get_featured_image($post_ID) { | |
$post_thumbnail_id = get_post_thumbnail_id($post_ID); | |
if ($post_thumbnail_id) { | |
$post_thumbnail_img = wp_get_attachment_image_src($post_thumbnail_id, 'thumbnail', 'featured_preview'); | |
return $post_thumbnail_img[0]; | |
} | |
} | |
// SHOW THE FEATURED IMAGE | |
function clb_columns_content($column_name, $post_ID) { | |
if ($column_name == 'featured_image') { | |
$post_featured_image = clb_get_featured_image($post_ID); | |
if ($post_featured_image) { | |
echo '<img src="' . $post_featured_image . '" />'; | |
} | |
} | |
} | |
// ADD NEW COLUMN | |
function clb_columns_head($defaults) { | |
$defaults['position'] = 'Position'; | |
// $defaults['featured_image'] = 'Thumbnail-2'; | |
return $defaults; | |
} | |
// GET POSITION | |
function clb_get_people_position($post_ID) { | |
$people_position = get_field('position', $post_id); | |
if ($people_position) { | |
$people_position = get_field('position', $post_id); | |
return $people_position[0]; | |
} | |
} | |
// SHOW THE POSITION | |
function clb_columns_content_position($column_name, $post_ID) { | |
if ($column_name == 'position') { | |
$post_position = clb_get_people_position($post_ID); | |
if ($post_position) { | |
echo '<p>' . $people_position . '</p>'; | |
} | |
} | |
} | |
// ONLY PEOPLE CUSTOM TYPE POSTS | |
add_filter('manage_people_posts_columns', 'clb_columns_head', 10); | |
add_action('manage_people_posts_custom_column', 'clb_columns_content', 10, 2); | |
add_action('manage_people_posts_custom_column', 'clb_columns_content_position', 10, 2); | |
*/ | |
// Create Custom Admin Columns for Lectionary | |
function clb_columns_head_only_lectionary($defaults) { | |
$defaults['lectionary_year'] = 'Lectionary Year'; | |
$defaults['calendar_date'] = 'Calendar Date'; | |
$defaults['focus_text'] = 'Focus Text'; | |
$defaults['thumbnail'] = 'Thumbnail'; | |
return $defaults; | |
} | |
// Display the data in Custom Admin Columns for Lectionary | |
function clb_columns_content_only_lectionary($column_name, $post_ID) { | |
if ($column_name == 'lectionary_year') { | |
$lectionary_year = get_field('lectionary_year'); | |
if ($lectionary_year) { | |
echo $lectionary_year; | |
} | |
} | |
if ($column_name == 'calendar_date') { | |
$calendar_date = get_field('calendar_date'); | |
if ($calendar_date) { | |
echo $calendar_date; | |
} | |
} | |
if ($column_name == 'focus_text') { | |
$focus_text = get_field('focus_text'); | |
$lectionary_text = get_field('lectionary_text'); | |
if ($focus_text) { | |
echo '<span title="' . strip_tags($lectionary_text) . '" style="text-decoration: underline;">' . $focus_text . '</span>'; | |
} | |
} | |
if ($column_name == 'thumbnail') { | |
$thumbnail = get_the_post_thumbnail( $post_id, 'thumbnail' ); | |
if ($thumbnail) { | |
echo $thumbnail; | |
} | |
} | |
} | |
// Implement Custom Columns only for Lectionary | |
add_filter('manage_lectionary_posts_columns', 'clb_columns_head_only_lectionary', 10); | |
add_action('manage_lectionary_posts_custom_column', 'clb_columns_content_only_lectionary', 10, 2); | |
//Filter Lectionary Year Custom Column | |
add_filter( 'manage_edit-lectionary_sortable_columns', 'my_sortable_lectionary_columns' ); | |
function my_sortable_lectionary_columns( $columns ) { | |
$columns['lectionary_year'] = 'lectionary_year'; | |
//To make a column 'un-sortable' remove it from the array | |
//unset($columns['date']); | |
return $columns; | |
} | |
//Allow Custom Post Types to appear in taxonomy results | |
function add_custom_types_to_tax( $query ) { | |
if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) { | |
// Get all your post types | |
$post_types = get_post_types(); | |
$query->set( 'post_type', $post_types ); | |
return $query; | |
} | |
} | |
add_filter( 'pre_get_posts', 'add_custom_types_to_tax' ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment