Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Helper function to generate post type labels
<?php
/**
* Generates the post type labels
*
* @param string $single Singular name of the post type.
* @param string $plural Plural name of the post type.
* @param array $overrides Override any generated labels.
* @return array The post type labels
*/
function cameronjonesweb_generate_post_type_labels( $single, $plural, $overrides = [] ) {
$labels = [
'name' => $plural,
'singular_name' => $single,
'add_new' => 'Add New',
'add_new_item' => 'Add New ' . $single,
'edit_item' => 'Edit ' . $single,
'new_item' => 'New ' . $single,
'view_item' => 'View ' . $single,
'view_items' => 'View ' . $plural,
'search_items' => 'Search ' . $plural,
'not_found' => 'No ' . strtolower( $plural ) . ' found.',
'not_found_in_trash' => 'No ' . strtolower( $plural ) . ' found in Trash.',
'parent_item_colon' => 'Parent ' . $single . ':',
'all_items' => 'All ' . $plural,
'archives' => $single . ' Archives',
'attributes' => $single . ' Attributes',
'insert_into_item' => 'Insert into ' . strtolower( $single ),
'uploaded_to_this_item' => 'Uploaded to this ' . strtolower( $single ),
'filter_items_list' => 'Filter ' . strtolower( $plural ) . ' list',
'items_list_navigation' => $plural . ' list navigation',
'items_list' => $plural . 'Posts list',
'item_published' => $single . ' published.',
'item_published_privately' => $single . ' published privately.',
'item_reverted_to_draft' => $single . ' reverted to draft.',
'item_scheduled' => $single . ' scheduled.',
'item_updated' => $single . ' updated.',
];
return wp_parse_args( $overrides, $labels );
}
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.