pollen / entity
A modern PHP package for WordPress custom post types and taxonomies
Requires
- php: ^8.1
- johnbillion/extended-cpts: ^5.0
- pollora/wordpress-args: dev-main
This package is auto-updated.
Last update: 2025-05-23 15:44:52 UTC
README
A modern PHP 8.2+ library for easily managing WordPress custom post types and taxonomies with a hexagonal architecture.
Test Structure
The unit tests use PestPHP and simulate WordPress functions to test the code without requiring a complete WordPress installation.
WordPress Mocks
WordPress mocks are organized as follows:
tests/helpers.php
: Global WordPress functions (global namespace)tests/ext_cpts_helpers.php
: Functions in theExtCPTs
namespace
helpers.php
File
This file contains simulations of global WordPress functions such as:
add_action
(to intercept and execute callbacks)register_post_type
andregister_taxonomy
register_extended_post_type
andregister_extended_taxonomy
is_admin
did_action
apply_filters
- etc.
ext_cpts_helpers.php
File
This file contains simulations of WordPress functions in the ExtCPTs
namespace used by the johnbillion/extended-cpts
library:
ExtCPTs\apply_filters
ExtCPTs\add_filter
ExtCPTs\get_post_type_object
ExtCPTs\get_taxonomies
ExtCPTs\get_post_types
ExtCPTs\is_wp_error
ExtCPTs\do_action
- etc.
Bootstrap
The tests/bootstrap.php
file loads the Composer autoloader, test helpers, and configures Mockery.
Code Structure
The hexagonal architecture used here separates the code into three layers:
- Domain: Domain models (Entity, PostType, Taxonomy)
- Application: Application services that orchestrate operations
- Adapter: Adapters that allow interaction with WordPress
The Domain layer is at the center and doesn't depend on any other layer. It defines ports (interfaces) that the adapters implement.
The Application layer uses these interfaces to interact with the outside world, without knowing the implementation details.
Usage
// Creating and registering a custom post type use Pollora\Entity\PostType; PostType::make('book', 'Book', 'Books') ->setPublic(true) ->setHasArchive(true) ->setSupports(['title', 'editor', 'thumbnail']) ->setMenuIcon('dashicons-book-alt') ->register(); // Creating and registering a taxonomy use Pollora\Entity\Taxonomy; Taxonomy::make('genre', 'book', 'Genre', 'Genres') ->setHierarchical(true) ->setShowInRest(true) ->register();