PHP Snippet 1:
function create_post_type( string $singular = 'Customer',
string $plural = 'Customers',
string $menu_icon = 'dashicons-carrot',
bool $hierarchical = FALSE,
bool $has_archive = TRUE,
string $description = '' ) {
//Here, the default post type if no argument is passed to create_post_type() will be Customer CPT
register_post_type( $singular, array(
'public' => TRUE,
'show_in_rest' => TRUE,
'description' => $description,
'menu_icon' => $menu_icon,
'hierarchical' => $hierarchical,
'has_archive' => $has_archive,
'supports' => array('title', 'editor', 'author', 'excerpt', 'page-attributes', 'thumbnail', 'custom-fields', 'comments'),
'labels' => array(
'name' => $plural,
'singular_name' => $singular,
'add_new' => 'Add New '.$singular,
'add_new_item' => 'New '.$singular,
'edit_item' => 'Edit '.$singular,
'view_item' => 'View '.$singular,
'view_items' => 'View '.$plural,
'search_items' => 'Search '.$plural,
'not_found' => 'No '.$plural.' Found',
'all_items' => 'All '.$plural,
'archives' => $plural.' Archives',
'attributes' => $singular.' Attributes',
'insert_into_item' => 'Insert into '.$singular,
'uploaded_to_this_item' => 'Uploaded to this '.$singular,
'featured_image' => $singular.' Featured image',
'set_featured_image' => 'Set '.$singular.' featured image',
'remove_featured_image' => 'Remove '.$singular.' featured image',
'use_featured_image' => 'Use as '.$singular.' featured image',
'filter_items_list' => 'Filter '.$plural.' list',
'filter_by_date' => 'Filter '.$plural.' by date',
'items_list_navigation' => $plural.' list navigation',
'items_list' => $plural.' list',
'item_published' => $singular.' published.',
'item_published_privately' => $singular.' published privately.',
'item_reverted_to_draft' => $singular.' reverted to draft.',
'item_scheduled' => $singular.' scheduled.',
'item_updated' => $singular.' updated.',
'item_link' => $singular.' link'
),
'rewrite' => array(
'slug' => strtolower($plural),
'pages' => TRUE,
)
));
}
function custom_cpts() {
create_post_type('Project', 'Projects','dashicons-excerpt-view');
create_post_type('Release', 'Releases', 'dashicons-unlock');
create_post_type('Event', 'Events','dashicons-calendar');
}
add_action( 'init', 'custom_cpts' );
?>