Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
SMOMS Mailbox CPT
<?php
/**
* This registers the custom post type for the SMOMS mailbox content.
*
* @package SMOMS Custom Content
* @author Marcy Diaz <marcy@amethystwebsitedesign.com>
* @copyright 2018 Marcy Diaz
* @license GPL-2.0+
*/
add_action( 'init', 'smoms_mailbox_register_post_type', 0 );
/**
* Create SMOMS Mailbox custom post type.
*
* @since 1.0.0
*/
function smoms_mailbox_register_post_type() {
$singular = 'Mailbox';
$plural = 'Mailbox';
$labels = array(
'name' => _x( $plural, 'Post Type General Name', 'smoms-cpt' ),
'singular_name' => _x( $singular, 'Post Type Singular Name', 'smoms-cpt' ),
'menu_name' => __( $plural, 'smoms-cpt' ),
'name_admin_bar' => __( $singular, 'smoms-cpt' ),
'archives' => __( $plural. 'Archives', 'smoms-cpt' ),
'parent_item_colon' => __( 'Parent Item:', 'smoms-cpt' ),
'all_items' => __( 'All ' .$plural, 'smoms-cpt' ),
'add_new_item' => __( 'Add New ' .$singular, 'smoms-cpt' ),
'add_new' => __( 'Add New', 'smoms-cpt' ),
'new_item' => __( 'New ' .$singular, 'smoms-cpt' ),
'edit_item' => __( 'Edit ' .$singular, 'smoms-cpt' ),
'update_item' => __( 'Update ' .$singular, 'smoms-cpt' ),
'view_item' => __( 'View '. $singular, 'smoms-cpt' ),
'search_items' => __( 'Search ' . $plural, 'smoms-cpt' ),
'not_found' => __( 'Not found', 'smoms-cpt' ),
'not_found_in_trash' => __( 'Not found in Trash', 'smoms-cpt' ),
);
$rewrite = array(
'slug' => 'mailbox',
'with_front' => false,
'pages' => true, //pagination.
'feeds' => false,
);
$supports = array(
'title',
'editor',
'author',
'thumbnail',
'revisions',
'page-attributes',
'genesis-layouts',
//'genesis-adjacent-entry-nav',
'genesis-cpt-archives-settings',
);
$args = array(
'label' => __( $plural, 'smoms-cpt' ),
'description' => __( 'SMOMS Mailbox Content', 'smoms-cpt' ),
'labels' => $labels,
'supports' => $supports,
'public' => true, //needed for archive.
'show_ui' => true,
'query_var' => true,
'show_in_menu' => true,
'menu_position' => 7,
'menu_icon' => 'dashicons-email',
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true, // Needed for archve.
'rewrite' => $rewrite,
'capability_type' => 'post',
'hierarchical' => false, // Not like Page.
'taxonomies' => array( 'topic', /*'category', 'post_tag'*/ ),
);
register_post_type( 'smoms-mailbox', $args );
}
// Flush rewrite rules on plugin activation.
register_activation_hook( __FILE__, 'smoms_mailbox_cpt_flush_rewrite_rules' );
function smoms_mailbox_cpt_flush_rewrite_rules() {
smoms_mailbox_register_post_type();
flush_rewrite_rules();
}
// Add Topic Taxonomy to Mailbox admin columns.
add_filter( 'manage_taxonomies_for_smoms-mailbox_columns', 'smoms_mailbox__taxonomy_columns' );
function smoms_mailbox__taxonomy_columns( $taxonomies ) {
$taxonomies[] = 'topic';
return $taxonomies;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment