v2.0 contains a lot of changes, fixes and features. For those of you upgrading from v1.1.2 here are some of the key changes to consider.
The register method
When creating post types and taxonomies you will now need to register them to WordPress using the register() method. This method calls all WordPress hooks responsible for registering a custom post type to WordPress.
// Create a PostType object for books
$books = new PostType('books');
// Register the books post type to WordPress
$books->register();
Taxonomies
Taxonomies are now created with the Taxonomy class and has the same methods and properties as PostTypes, including columns.
// Create a Taxonomy object for genres
$genres = new Taxonomy('genre');
// Add the genre taxonomy to the books post type
$genres->posttype('book');
// Create a custom column for the taxonomy list table
$genres->columns()->add([
'popularity' => __('Popularity')
]);
// Register the taxonomy to WordPress
$genres->register();
Translations
Previously, PostTypes used a variable to set the textdomain for translatable strings. Based on the WordPress documentation, this vairable has been removed and PostTypes no longer uses any gettext functions.
To translate strings when using PostTypes, you can use WordPress gettext functions when setting any names or labels.
v2.0 contains a lot of changes, fixes and features. For those of you upgrading from v1.1.2 here are some of the key changes to consider.
The register method
When creating post types and taxonomies you will now need to register them to WordPress using the
register()
method. This method calls all WordPress hooks responsible for registering a custom post type to WordPress.Taxonomies
Taxonomies are now created with the Taxonomy class and has the same methods and properties as PostTypes, including columns.
Translations
Previously, PostTypes used a variable to set the textdomain for translatable strings. Based on the WordPress documentation, this vairable has been removed and PostTypes no longer uses any gettext functions.
To translate strings when using PostTypes, you can use WordPress gettext functions when setting any names or labels.
Changelog
columns()
to Taxonomy classexamples/books.php