Skip to content
Carlos Moreira edited this page Jun 2, 2020 · 1 revision

The labels parameter will contain all messages and texts that will display when managing your Custom Post Type in the administration. If you don't include this parameter, the framework will create these labels based on the name parameter of your model.

We recommend you use at least the following options:

return [
	'active'       => true,
	'type'         => 'cpt',
	'name'         => 'book',
	'labels' => [
		'has_one'        => 'Book',
		'has_many'       => 'Books',
		'featured_image' => 'Book Cover',
	],
];

The following options above are enough for the framework to automatically build all other labels. However, if you plan to make your plugin more compatible with translation, we advise you to define all the labels individually, so that automatic translation softwares will pick them up. All labels that you want to control will be inside the overrides parameter, which accepts 4 different values:

Parameter Description
labels Labels mostly used in the add/edit screen of your custom post type
messages Messages that display when you perform actions with your custom post type, such as delete, save, publish among others
bulk_messages Messages that display when you perform bulk messages
ui Other labels that might display in the user interface when managing your custom post type

For the messages and bulk_messages you can use the placeholders {permalink}, {preview_url} and {date} in your values, they will be automatically replaced by the framework by the proper values.

Example:

return [
	'active'       => true,
	'type'         => 'cpt',
	'name'         => 'book',
	'labels' => [
		'has_one'        => 'Book',
		'has_many'       => 'Books',
		'featured_image' => 'Book Cover',
		'overrides' => [
			'labels' => [],
			'messages => [],
			'bulk_messages => [],
			'ui' => [],
		],
	],
];

Below is an example containing all available parameters for the labels overrides:

return [
	'active'       => true,
	'type'         => 'cpt',
	'name'         => 'book',
	'labels'       => [
		'has_one'        => 'Book',
		'has_many'       => 'Books',
		'featured_image' => 'Book Cover',
		'text_domain'    => 'framework-demo',

		// optional, but better for translation
		'overrides'      => [
			'labels'        => [
				'name'                  => __( 'Books', 'framework-demo' ),
				'singular_name'         => __( 'Book', 'framework-demo' ),
				'menu_name'             => __( 'Books', 'framework-demo' ),
				'name_admin_bar'        => __( 'Book', 'framework-demo' ),
				'add_new'               => __( 'Add New', 'framework-demo' ),
				'add_new_item'          => __( 'Add New Book', 'framework-demo' ),
				'edit_item'             => __( 'Edit Book', 'framework-demo' ),
				'new_item'              => __( 'New Book', 'framework-demo' ),
				'view_item'             => __( 'View Book', 'framework-demo' ),
				'view_items'            => __( 'View Books', 'framework-demo' ),
				'search_items'          => __( 'Search Books', 'framework-demo' ),
				'not_found'             => __( 'No books found.', 'framework-demo' ),
				'not_found_in_trash'    => __( 'No books found in Trash.', 'framework-demo' ),
				'parent_item-colon'     => __( 'Parent Books:', 'framework-demo' ),
				'all_items'             => __( 'All Books', 'framework-demo' ),
				'archives'              => __( 'Book Archives', 'framework-demo' ),
				'attributes'            => __( 'Book Attributes', 'framework-demo' ),
				'insert_into_item'      => __( 'Insert into book', 'framework-demo' ),
				'uploaded_to_this_item' => __( 'Uploaded to this book', 'framework-demo' ),
				'featured_image'        => __( 'Featured Image', 'framework-demo' ),
				'set_featured_image'    => __( 'Set featured image', 'framework-demo' ),
				'remove_featured_image' => __( 'Remove featured image', 'framework-demo' ),
				'use_featured_image'    => __( 'Use featured image', 'framework-demo' ),
				'filter_items_list'     => __( 'Filter books list', 'framework-demo' ),
				'items_list_navigation' => __( 'Books list navigation', 'framework-demo' ),
				'items_list'            => __( 'Books list', 'framework-demo' ),
				'featured_image'        => __( 'Book Cover Image', 'framework-demo' ),
				'set_featured_image'    => __( 'Set Book Cover Image', 'framework-demo' ),
				'remove_featured_image' => __( 'Remove Book Cover', 'framework-demo' ),
				'use_featured_image'    => __( 'Use as Book Cover', 'framework-demo' ),
			],
			// you can use the placeholders {permalink}, {preview_url}, {date}
			'messages'      => [
				'post_updated'         => __( 'Book information updated. <a href="{permalink}" target="_blank">View Book</a>', 'framework-demo' ),
				'post_updated_short'   => __( 'Book info updated', 'framework-demo' ),
				'custom_field_updated' => __( 'Custom field updated', 'framework-demo' ),
				'custom_field_deleted' => __( 'Custom field deleted', 'framework-demo' ),
				'restored_to_revision' => __( 'Book content restored from revision', 'framework-demo' ),
				'post_published'       => __( 'Book Published', 'framework-demo' ),
				'post_saved'           => __( 'Book information saved.', 'framework-demo' ),
				'post_submitted'       => __( 'Book submitted. <a href="{preview_url}" target="_blank">Preview</a>', 'framework-demo' ),
				'post_schedulled'      => __( 'Book scheduled for {date}. <a href="{preview_url}" target="_blank">Preview</a>', 'framework-demo' ),
				'post_draft_updated'   => __( 'Book draft updated. <a href="{preview_url}" target="_blank">Preview</a>', 'framework-demo' ),
			],
			'bulk_messages' => [
				'updated_singular'   => __( 'Book updated. Yay!', 'framework-demo' ),
				'updated_plural'     => __( '%s Books updated. Yay!', 'framework-demo' ),
				'locked_singular'    => __( 'Book not updated, somebody is editing it', 'framework-demo' ),
				'locked_plural'      => __( '%s Books not updated, somebody is editing them', 'framework-demo' ),
				'deleted_singular'   => __( 'Book permanetly deleted. Fahrenheit 451 team was here?', 'framework-demo' ),
				'deleted_plural'     => __( '%s Books permanently deleted. Why? :(', 'framework-demo' ),
				'trashed_singular'   => __( 'Book moved to the trash. I\'m sad :(', 'framework-demo' ),
				'trashed_plural'     => __( '%s Books moved to the trash. Why? :(', 'framework-demo' ),
				'untrashed_singular' => __( 'Book recovered from trash. Well done!', 'framework-demo' ),
				'untrashed_plural'   => __( '%s Books saved from the enemies!', 'framework-demo' ),
			],
			// overrides some of the available button labels and placeholders
			'ui'            => [
				'enter_title_here' => __( 'Enter book name here', 'framework-demo' ),
			],
		],
	],

Clone this wiki locally