Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
class SermonPostType {
/**
* Permalink slug for this post type
*
* @var string $slug Permalink prefix
* @since NEXT
*/
private $slug = 'cc_sermons';
/**
* Post ID of this post type.
*
* @var int $post_id Id of Post.
* @since NEXT
*/
private $post_id;
/**
* Construct
*
* @since 0.1.0
* @author Scott Anderson <scott@church.agency>
*/
public function __construct() {
$this->hooks();
}
/**
* Register Hooks
*
* @author Scott Anderson <scott@church.agency>
* @since NEXT
*/
private function hooks() : void {
add_action( 'init', [ $this, 'register_post' ] );
}
/**
* Post Labels
*
* @author Scott Anderson <scott@church.agency>
* @since NEXT
* @return array
*/
private function post_labels() : array {
return [
'name' => _x( 'Sermons', 'Post type general name', 'Sermon' ),
'singular_name' => _x( 'Sermon', 'Post type singular name', 'Sermon' ),
'menu_name' => _x( 'Sermons', 'Admin Menu text', 'Sermon' ),
'name_admin_bar' => _x( 'Sermon', 'Add New on Toolbar', 'Sermon' ),
'add_new' => __( 'Add New', 'Sermon' ),
'add_new_item' => __( 'Add New Sermon', 'Sermon' ),
'new_item' => __( 'New Sermon', 'Sermon' ),
'edit_item' => __( 'Edit Sermon', 'Sermon' ),
'view_item' => __( 'View Sermon', 'Sermon' ),
'all_items' => __( 'All Sermons', 'Sermon' ),
'search_items' => __( 'Search Sermons', 'Sermon' ),
'parent_item_colon' => __( 'Parent Sermons:', 'Sermon' ),
'not_found' => __( 'No Sermons found.', 'Sermon' ),
'not_found_in_trash' => __( 'No Sermons found in Trash.', 'Sermon' ),
'featured_image' => _x( 'Sermon Cover Image', 'Overrides the “Featured Image” phrase for this post type. Added in 4.3', 'Sermon' ),
'set_featured_image' => _x( 'Set cover image', 'Overrides the “Set featured image” phrase for this post type. Added in 4.3', 'Sermon' ),
'remove_featured_image' => _x( 'Remove cover image', 'Overrides the “Remove featured image” phrase for this post type. Added in 4.3', 'Sermon' ),
'use_featured_image' => _x( 'Use as cover image', 'Overrides the “Use as featured image” phrase for this post type. Added in 4.3', 'Sermon' ),
'archives' => _x( 'Sermon archives', 'The post type archive label used in nav menus. Default “Post Archives”. Added in 4.4', 'Sermon' ),
'insert_into_item' => _x( 'Insert into Sermon', 'Overrides the “Insert into post”/”Insert into page” phrase (used when inserting media into a post). Added in 4.4', 'Sermon' ),
'uploaded_to_this_item' => _x( 'Uploaded to this Sermon', 'Overrides the “Uploaded to this post”/”Uploaded to this page” phrase (used when viewing media attached to a post). Added in 4.4', 'Sermon' ),
'filter_items_list' => _x( 'Filter Sermons list', 'Screen reader text for the filter links heading on the post type listing screen. Default “Filter posts list”/”Filter pages list”. Added in 4.4', 'Sermon' ),
'items_list_navigation' => _x( 'Sermons list navigation', 'Screen reader text for the pagination heading on the post type listing screen. Default “Posts list navigation”/”Pages list navigation”. Added in 4.4', 'Sermon' ),
'items_list' => _x( 'Sermons list', 'Screen reader text for the items list heading on the post type listing screen. Default “Posts list”/”Pages list”. Added in 4.4', 'Sermon' ),
];
}
/**
* Post Arguments
*
* @author Scott Anderson <scott@church.agency>
* @since NEXT
* @return array
*/
private function post_arguments() : array {
return [
'labels' => $this->post_labels(),
'description' => 'Sermon custom post type.',
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'sermon' ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => 20,
'supports' => array( 'title', 'editor', 'author', 'thumbnail' ),
'taxonomies' => array( 'category', 'post_tag' ),
'show_in_rest' => true,
];
}
/**
* Register Post Type
*
* @author Scott Anderson <scott@church.agency>
* @since NEXT
*/
public function register_post() : void {
register_post_type( $this->slug, $this->post_arguments() );
}
}
new SermonPostType();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.