Package that simplifies registration of WordPress Model-like objects - Custom Post Types and Custom Taxonomies. Automatically generates name, slug and all required labels of Models.
composer require micropackage/models
Classname of Post Types should ends with
PostType
.
<?php
use Micropackage\Models\PostType;
class TestimonialPostType extends PostType
{
/**
* Define icon, whether post type should be public and other attributes.
* Labels will be generated automatically.
*
* @see https://developer.wordpress.org/reference/functions/register_post_type/
*/
protected static function getArgs(): array
{
return [
'menu_icon' => 'dashicons-cart',
'public' => true,
];
}
}
new TestimonialPostType();
Classname of Taxonomies should ends with
Taxonomy
.
<?php
use Micropackage\Models\Taxonomy;
class PlaceTaxonomy extends Taxonomy
{
/**
* Define to which post types taxonomy should belongs.
*
* You can use slug of any post types or classname of post types created
* using this package.
*/
protected static array $objectTypes = [
'product',
TestimonialPostType::class,
];
/**
* Define whether taxonomy should be hierarchical and other attributes.
* Labels will be generated automatically.
*
* @see https://developer.wordpress.org/reference/functions/register_taxonomy/
*/
protected static function getArgs(): array
{
return [
'hierarchical' => true,
];
}
}
new PlaceTaxonomy();
Micropackages - as the name suggests - are micro packages with a tiny bit of reusable code, helpful particularly in WordPress development.
The aim is to have multiple packages which can be put together to create something bigger by defining only the structure.
Micropackages are maintained by BracketSpace.
GNU General Public License (GPL) v3.0. See the LICENSE file for more information.