PHPackages                             aurooba/cpt - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. aurooba/cpt

ActiveLibrary

aurooba/cpt
===========

A small helper class for registering Custom Post Types and their taxonomies in WordPress

v1.1.0(5y ago)10261[4 issues](https://github.com/aurooba/cpt/issues)GPL-2.0-or-laterPHPPHP &gt;=7.0.0

Since Mar 4Pushed 5y ago2 watchersCompare

[ Source](https://github.com/aurooba/cpt)[ Packagist](https://packagist.org/packages/aurooba/cpt)[ RSS](/packages/aurooba-cpt/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (3)Used By (0)

[![Packagist Downloads](https://camo.githubusercontent.com/b670e800c9f910d7c35f458e086108c626e11a880ef14195edae6e83fec77cc5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6175726f6f62612f6370743f636f6c6f723d253233623264333863266c6f676f3d5061636b6167697374266c6f676f436f6c6f723d253233623264333863267374796c653d666f722d7468652d6261646765)](https://camo.githubusercontent.com/b670e800c9f910d7c35f458e086108c626e11a880ef14195edae6e83fec77cc5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6175726f6f62612f6370743f636f6c6f723d253233623264333863266c6f676f3d5061636b6167697374266c6f676f436f6c6f723d253233623264333863267374796c653d666f722d7468652d6261646765)

[![Packagist PHP Version Support](https://camo.githubusercontent.com/b789627e28387a8662a08f74b8fe2a408b9226228eff031b0c1f78cd49af1cb0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6175726f6f62612f6370743f636f6c6f723d253233623264333863267374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/b789627e28387a8662a08f74b8fe2a408b9226228eff031b0c1f78cd49af1cb0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6175726f6f62612f6370743f636f6c6f723d253233623264333863267374796c653d666c61742d737175617265)[![Packagist License](https://camo.githubusercontent.com/0b4ef72353831ece8089827237a73debc6733bcefdf2aac4cd410437999beb08/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6175726f6f62612f6370743f636f6c6f723d253233623264333863267374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/0b4ef72353831ece8089827237a73debc6733bcefdf2aac4cd410437999beb08/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6175726f6f62612f6370743f636f6c6f723d253233623264333863267374796c653d666c61742d737175617265)

Custom Post Type and Taxonomies Generator
=========================================

[](#custom-post-type-and-taxonomies-generator)

Quickly register custom post types and associated taxonomies with intelligent defaults in your WordPress projects.

For complete documentation of Custom Post Type registration, see [https://developer.wordpress.org/reference/functions/register\_post\_type/](https://developer.wordpress.org/reference/functions/register_post_type/)

For complete documentation of Taxonomy registration, see [https://developer.wordpress.org/reference/functions/register\_taxonomy/](https://developer.wordpress.org/reference/functions/register_taxonomy/)

Minimum Requirements
====================

[](#minimum-requirements)

- **PHP:** 7.0
    - PHP 7.4+ is recommended
- **WordPress:** 5.0
    - Tested up to WP 5.6.2

Installation
============

[](#installation)

The easiest way is to install this through Composer with:

```
composer require aurooba/cpt
```

Make sure you have composer autoload set up where you are adding the package.

For themes, in your `functions.php` file:

```
require get_template_directory() . '/vendor/autoload.php';
```

For plugins, in your main plugin file, near the top:

```
require plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
```

Usage
=====

[](#usage)

Don't see an option you use often and would love for it to be easier too? Open an issue or pop it into [the Discussion area](https://github.com/aurooba/cpt/discussions), let's make it happen. :)

Have a question about your specific use case? Ask in a [support discussion](https://github.com/aurooba/cpt/discussions).

Basic Usage
-----------

[](#basic-usage)

```
// Yep feel free to use spaces in your name
$custom_post_type = new Aurooba\CPT( 'custom post type' );
```

The class, by default, takes in just one parameter: a singular name, like `resource`. It's smart enough to convert `resource` into `resources`, `country` into `countries`, `potato` into `potatoes`, `goose` into `geese`, and handles some exceptions as well.

At this time, it is *not* smart enough to handle uncountable nouns such as `rice`, `tea`, `knowledge`, etc. This is a planned addition, coming later.

Customized Usage
----------------

[](#customized-usage)

```
$custom_post_type = new Aurooba\CPT(
	'singular name', // singular taxonomy name, human readable
	$args, // an array of custom parameters for the custom post type
	$labels // an array of custom labels for the custom post type
);

$custom_post_type->add_taxonomy(
	'Taxonomy', // singular taxonomy name
	// array of custom parameters for the taxonomy
	array(
		'hierarchical' => false,
	),
	$labels, // array of custom labels for the taxonomy
)
```

Icons
-----

[](#icons)

The default icon, set up in the class is the [`screenoptions` Dashicon](https://developer.wordpress.org/resource/dashicons/#screenoptions), purely because I like it.

Feel free to pass a different Dashicon to your class as shown in this [different icon example](#Register-a-custom-post-type-with-a-different-icon).

You can also pass custom SVG icons, as shown in this [custom svg icon example](#Register-a-custom-post-type-with-a-custom-icon).

Taxonomies
----------

[](#taxonomies)

The class can also [attach existing taxonomies](#Attach-an-existing-taxonomy) to your CPT or [generate a new taxonomy to attach to the CPT](#Register-and-associate-a-basic-taxonomy-with-the-Custom-Post-Type).

Examples
========

[](#examples)

Register a basic Custom Post Type:
----------------------------------

[](#register-a-basic-custom-post-type)

```
/**
 * Initialize a Resource Custom Post Type
 * @return void
 */
function initialize_cpts() {

	$resource = new Aurooba\CPT( 'resource');

}

add_action( 'after_setup_theme', 'initialize_cpts' );
```

Register and associate a basic taxonomy with the Custom Post Type:
------------------------------------------------------------------

[](#register-and-associate-a-basic-taxonomy-with-the-custom-post-type)

```
/**
 * Initialize a Resource Custom Post Type
 * @return void
 */
function initialize_cpts_and_taxonomies() {

	// initialize cpt
	$resource = new Aurooba\CPT( 'resource' );

	// add Resource Type taxonomy
	$resource->add_taxonomy( 'Resource Type' );

}

add_action( 'after_setup_theme', 'initialize_cpts_and_taxonomies' );
```

Register a Custom Post Type with a different icon
-------------------------------------------------

[](#register-a-custom-post-type-with-a-different-icon)

```
$resource = new Aurooba\CPT(
		'resource',
		array( 'menu_icon' => 'dashicons-share-alt' ),
	);
```

Register a Custom Post Type with a custom icon
----------------------------------------------

[](#register-a-custom-post-type-with-a-custom-icon)

```
// Your icon SVG Code. Alternatively, you can pass the path to an SVG file.
$resource_icon = '';

$resource = new Aurooba\CPT(
		'resource',
		array(
			'menu_icon' => 'data:image/svg+xml;base64,' . base64_encode( $resource_icon ) ),
	);
```

Create a customized Custom Post Type:
-------------------------------------

[](#create-a-customized-custom-post-type)

```
/**
 * Initialize a Resource Custom Post Type
 * @return void
 */
function initialize_cpts() {

	// create a block template to include in the custom post type
	$block_template = array(
		array(
			'core/heading',
			array(
				'level'       => 2,
				'placeholder' => __( 'Resource Type', 'textdomain' ),
			),
		),
		array(
			'core/paragraph',
			array(
				'content' => __( 'Places where this resource can be helpful are:>', 'textdomain' ),
			),
		),
	);

	$resource = new Aurooba\CPT(
		'resource',
		array(
			'menu_position' => 26,
			'menu_icon'     => 'dashicons-plus-alt',
			'template'      => $block_template,
			'rewrite'       => true,
			'capability_type' => 'resource',
			'map_meta_cap' => true,
			'supports'      => array(
				'title',
				'editor',
				'thumbnail',
				'author',
				'custom-fields',
			),
		),
	);

}

add_action( 'after_setup_theme', 'initialize_cpts' );
```

Create a customized taxonomy:
-----------------------------

[](#create-a-customized-taxonomy)

```
	$resource->add_taxonomy(
		'Resource Type',
		array(
			'capabilities' => array(
				'manage_terms' => 'manage_resource_type',
				'edit_terms'   => 'edit_resource_type',
				'delete_terms' => 'delete_resource_type',
				'assign_terms' => 'assign_resource_type',
			),
		),
	);
```

Attach an existing taxonomy:
----------------------------

[](#attach-an-existing-taxonomy)

```
$resource->add_taxonomy( 'Post Tag' );
$resource->add_taxonomy( 'Category' );
```

Contributing
============

[](#contributing)

Contributors are welcome! Come help extend, test, and improve this package so it becomes an insanely helpful library. Check out [CONTRIBUTING.md](CONTRIBUTING.md) for more information.

License
=======

[](#license)

Created by Aurooba Ahmed. Licensed under the terms of the GPL v2 or later.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance12

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1898d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/04b92efcd193db5e46da622663670fb4132981f2d306d1de8646ef9568f6c949?d=identicon)[aurooba](/maintainers/aurooba)

---

Top Contributors

[![aurooba](https://avatars.githubusercontent.com/u/6925260?v=4)](https://github.com/aurooba "aurooba (27 commits)")

---

Tags

wordpress

### Embed Badge

![Health badge](/badges/aurooba-cpt/health.svg)

```
[![Health](https://phpackages.com/badges/aurooba-cpt/health.svg)](https://phpackages.com/packages/aurooba-cpt)
```

###  Alternatives

[roots/wordpress

WordPress is open source software you can use to create a beautiful website, blog, or app.

19116.9M258](/packages/roots-wordpress)[aristath/kirki

Extending the WordPress customizer

1.3k73.0k4](/packages/aristath-kirki)[wpreadme2markdown/wpreadme2markdown

Convert WordPress Plugin readme.txt to Markdown

9564.6k4](/packages/wpreadme2markdown-wpreadme2markdown)[wpstarter/framework

The WpStarter Framework - Laravel Framework for WordPress

1810.1k4](/packages/wpstarter-framework)[tacowordpress/tacowordpress

WordPress custom post types that feel like CRUD models

232.2k](/packages/tacowordpress-tacowordpress)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
