Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
# PostTypes v2.2.1
# PostTypes v3.0

[![tests](https://github.com/jjgrainger/PostTypes/actions/workflows/tests.yml/badge.svg)](https://github.com/jjgrainger/PostTypes/actions/workflows/tests.yml) [![codecov](https://codecov.io/gh/jjgrainger/PostTypes/branch/master/graph/badge.svg?token=SGrK2xDF46)](https://codecov.io/gh/jjgrainger/PostTypes) [![Latest Stable Version](https://flat.badgen.net/github/release/jjgrainger/PostTypes/stable)](https://packagist.org/packages/jjgrainger/posttypes) [![Total Downloads](https://flat.badgen.net/packagist/dt/jjgrainger/PostTypes)](https://packagist.org/packages/jjgrainger/posttypes) [![License](https://flat.badgen.net/github/license/jjgrainger/PostTypes)](https://packagist.org/packages/jjgrainger/posttypes)

> Simple WordPress custom post types.
> Modern PHP abstractions for WordPress post types and taxonomies.

## Migrating from v2 to v3

> **Important**: v3.0 is a breaking release. Existing v2 post type and taxonomy definitions will not work without modification. Please review the migration guide in the [documentation](https://posttypes.jjgrainger.co.uk) on how to upgrade to version 3.

## Requirements

Expand Down Expand Up @@ -58,7 +62,7 @@ class Book extends PostType {
'view_item' => __( 'View Book', 'text-domain' ),
'search_items' => __( 'Search Books', 'text-domain' ),
'not_found' => __( 'No Books found', 'text-domain' ),
'not_found_in_trash' => __( 'No Books found in Trash', 'text-domain'),
'not_found_in_trash' => __( 'No Books found in Trash', 'text-domain' ),
'parent_item_colon' => __( 'Parent Book', 'text-domain' ),
];
}
Expand All @@ -71,7 +75,7 @@ class Book extends PostType {
'title',
'editor',
'thumbnail',
'custom-fields'
'custom-fields',
];
}

Expand All @@ -80,7 +84,7 @@ class Book extends PostType {
*/
public function taxonomies(): array {
return [
'genre'
'genre',
'category',
];
}
Expand All @@ -98,7 +102,7 @@ class Book extends PostType {
public function filters(): array {
return [
'genre',
'category'
'category',
];
}

Expand Down Expand Up @@ -127,11 +131,11 @@ class Book extends PostType {
Once the custom post type class is created it can be registered to WordPress by instantiating and call the register method.

```php
// Instantiate the Books PostType class.
$books = new Books;
// Instantiate the Book PostType class.
$book = new Book;

// Register the books PostType to WordPress.
$books->register();
// Register the Book PostType to WordPress.
$book->register();
```

## Notes
Expand Down
14 changes: 7 additions & 7 deletions docs/Getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class Book extends PostType {
'view_item' => __( 'View Book', 'text-domain' ),
'search_items' => __( 'Search Books', 'text-domain' ),
'not_found' => __( 'No Books found', 'text-domain' ),
'not_found_in_trash' => __( 'No Books found in Trash', 'text-domain'),
'not_found_in_trash' => __( 'No Books found in Trash', 'text-domain' ),
'parent_item_colon' => __( 'Parent Book', 'text-domain' ),
];
}
Expand All @@ -76,8 +76,8 @@ class Book extends PostType {
*/
public function taxonomies(): array {
return [
'genre'
'category',
'genre',
'category'
];
}

Expand Down Expand Up @@ -123,9 +123,9 @@ class Book extends PostType {
Once the custom post type class is created it can be registered to WordPress by instantiating and call the register method.

```php
// Instantiate the Books PostType class.
$books = new Books;
// Instantiate the Book PostType class.
$book = new Book;

// Register the books PostType to WordPress.
$books->register();
// Register the Book PostType to WordPress.
$book->register();
```
35 changes: 18 additions & 17 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
# Table of Contents

* [PostTypes v3.0](../README.md)
* [Getting Started](Getting-started.md)
* [Migrating from v2 to v3](migrating-from-v2-v3.md)
* [Getting Started](getting-started.md)
* [PostTypes](post-types/README.md)
* [Create a Post Type](post-types/Create-a-post-type.md)
* [Defining Labels](post-types/Defining-labels.md)
* [Defining Options](post-types/Defining-options.md)
* [Defining taxonomies](post-types/Defining-taxonomies.md)
* [Defining feature supports](post-types/Defining-feature-supports.md)
* [Defining an icon](post-types/Defining-an-icon.md)
* [Defining filters](post-types/Defining-filters.md)
* [Modifying columns](post-types/Modifying-columns.md)
* [Creating columns](post-types/Creating-columns.md)
* [Defining hooks](post-types/Defining-hooks.md)
* [Create a Post Type](post-types/create-a-post-type.md)
* [Define Labels](post-types/define-labels.md)
* [Define Options](post-types/define-options.md)
* [Define taxonomies](post-types/define-taxonomies.md)
* [Define feature supports](post-types/define-feature-supports.md)
* [Define an icon](post-types/define-icon.md)
* [Define filters](post-types/define-filters.md)
* [Modify columns](post-types/modify-columns.md)
* [Create columns](post-types/create-columns.md)
* [Define hooks](post-types/define-hooks.md)
* [Taxonomies](taxonomies/README.md)
* [Create a Taxonomy](taxonomies/Create-a-taxonomy.md)
* [Defining Labels](taxonomies/Defining-labels.md)
* [Defining Options](taxonomies/Defining-options.md)
* [Defining Post Types](taxonomies/Defining-post-types.md)
* [Modifying Columns](taxonomies/Modifying-columns.md)
* [Defining Hooks](taxonomies/Defining-hooks.md)
* [Create a Taxonomy](taxonomies/create-a-taxonomy.md)
* [Define Labels](taxonomies/define-labels.md)
* [Define Options](taxonomies/define-options.md)
* [Define Post Types](taxonomies/define-post-types.md)
* [Modify Columns](taxonomies/modify-columns.md)
* [Define Hooks](taxonomies/define-hooks.md)
* [Contributing](../CONTRIBUTING.md)
* [Changelog](../Changelog.md)
131 changes: 131 additions & 0 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Getting Started

## Requirements

* PHP >=8.1
* [Composer](https://getcomposer.org/)
* [WordPress](https://wordpress.org) >=6.3

## Installation

#### Install with composer

Run the following in your terminal to install PostTypes with [Composer](https://getcomposer.org/).

```
$ composer require jjgrainger/posttypes
```

PostTypes uses [PSR-4](https://www.php-fig.org/psr/psr-4/) autoloading and can be used with the Composer's autoloader. See Composer's [basic usage](https://getcomposer.org/doc/01-basic-usage.md#autoloading) guide for details on working with Composer and autoloading.

## Basic Usage

#### Create a custom post type

Custom post types are defined as classes that extend the base `PostType` class. At a minimum, the `name` method must be implemented to define the post type slug. All other methods are optional and allow you to configure labels, options, taxonomies, admin columns, filters, and more as needed.

```php
<?php

use PostTypes\PostType;
use PostTypes\Columns;

class Book extends PostType {
/**
* Define the Post Type name.
*/
public function name(): string {
return 'book';
}

/**
* Define the Post Type labels.
*/
public function labels(): array {
return [
'name' => __( 'Book', 'text-domain' ),
'singular_name' => __( 'Book', 'text-domain' ),
'menu_name' => __( 'Books', 'text-domain' ),
'all_items' => __( 'Books', 'text-domain' ),
'add_new' => __( 'Add New', 'text-domain' ),
'add_new_item' => __( 'Add New Book', 'text-domain' ),
'edit_item' => __( 'Edit Book', 'text-domain' ),
'new_item' => __( 'New Book', 'text-domain' ),
'view_item' => __( 'View Book', 'text-domain' ),
'search_items' => __( 'Search Books', 'text-domain' ),
'not_found' => __( 'No Books found', 'text-domain' ),
'not_found_in_trash' => __( 'No Books found in Trash', 'text-domain' ),
'parent_item_colon' => __( 'Parent Book', 'text-domain' ),
];
}

/**
* Define Post Type feature supports.
*/
public function supports(): array {
return [
'title',
'editor',
'thumbnail',
'custom-fields'
];
}

/**
* Define Taxonomies associated with the Post Type.
*/
public function taxonomies(): array {
return [
'genre',
'category'
];
}

/**
* Set the menu icon for the Post Type.
*/
public function icon(): string {
return 'dashicons-book';
}

/**
* Set the admin post table filters.
*/
public function filters(): array {
return [
'genre',
'category'
];
}

/**
* Define the columns for the admin post table.
*/
public function columns(Columns $columns): Columns {
// Remove the author and date column.
$columns->remove( [ 'author', 'date' ] );

// Add a Rating column.
$columns->add( 'rating', __( 'Rating', 'post-types' ) );

// Populate the rating column.
$columns->populate( 'rating', function( $post_id ) {
echo get_post_meta( $post_id, 'rating', true );
} );

return $columns;
}
}
```

### Register a custom post type

Once the custom post type class is created it can be registered to WordPress by instantiating and call the register method.

```php
// Instantiate the Book PostType class.
$book = new Book;

// Register the Book PostType to WordPress.
$book->register();
```
Loading