Skip to content

Instantly share code, notes, and snippets.

@cameronjonesweb
Last active October 7, 2020 23:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cameronjonesweb/01b0adff0ac3c30168bafcaf7e5f0b29 to your computer and use it in GitHub Desktop.
Save cameronjonesweb/01b0adff0ac3c30168bafcaf7e5f0b29 to your computer and use it in GitHub Desktop.
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