Skip to content

About

Create WordPress post types and taxonomy in a fluent way

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

2 stars

Watchers

2 watching

Forks

Repository files navigation

Entity: fluent WordPress post types and taxonomies

Latest version Total downloads Tests License

Entity declares WordPress custom post types and taxonomies with a fluent, typed interface instead of the long argument arrays of register_post_type() and register_taxonomy(). Each option has its own method, boolean options get dedicated methods (public(), showInRest()…), and registration is hooked to init for you. It is built on Extended CPTs, so labels are generated from the singular and plural names, and admin columns and filters are one method away (adminCols(), adminFilters()).

Part of Pollora, the Laravel framework for WordPress. In a Pollora project it is already installed: declare post types and taxonomies with the #[PostType] and #[Taxonomy] attributes instead, and Pollora registers them through this package.

Installation

composer require pollora/entity

Requires PHP 8.2+ and WordPress.

Quick start

Post types

use Pollora\Entity\PostType;

PostType::make('book', 'Book', 'Books')
    ->public()
    ->showInRest()
    ->hasArchive()
    ->supports(['title', 'editor', 'thumbnail'])
    ->menuIcon('dashicons-book-alt');

Taxonomies

use Pollora\Entity\Taxonomy;

Taxonomy::make('genre', 'book', 'Genre', 'Genres')
    ->hierarchical()
    ->showInRest()
    ->showInQuickEdit();

make() returns the configured object and registers it on the WordPress init hook, so call it before init runs (in a plugin's main file or a theme's functions.php).

Features

  • Typed, fluent methods for the post type and taxonomy arguments, with dedicated methods for boolean options.
  • Built on Extended CPTs.
  • Hexagonal architecture that keeps the domain independent from WordPress.
  • Tested with Pest, with WordPress functions mocked.

Documentation

  • Post types: creating and configuring custom post types.
  • Taxonomies: creating and configuring custom taxonomies.

In a Pollora project, see Post types and Taxonomies on pollora.dev.

Architecture

The package follows hexagonal architecture principles:

  1. Domain layer: the core model (Entity, PostType, Taxonomy).
  2. Application layer: services that orchestrate registration.
  3. Adapter layer: the WordPress integration adapters.

The domain layer has no external dependencies: it defines interfaces (ports) that the adapters implement.

Testing

composer test

This runs the Pest unit tests, PHPStan and Pint. WordPress functions are mocked:

  • tests/Helpers/helpers.php: global WordPress function mocks
  • tests/Helpers/ext_cpts_helpers.php: Extended CPTs namespace function mocks
  • tests/Helpers/wordpress_args_helpers.php: mocks for pollora/wordpress-args
  • tests/bootstrap.php: test environment setup

Contributing

Contributions are welcome: see the contributing guide. Report security issues privately, as described in the security policy.

License

Entity is open-source software licensed under the MIT license. © RuBee group

About

Create WordPress post types and taxonomy in a fluent way

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

2 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages