Skip to content

Commit fa7076f

Browse files
authored
Merge pull request #102 from jjgrainger/feature/documentation-updates
v3.0 Documentation updates
2 parents e18ceba + edd0aae commit fa7076f

28 files changed

Lines changed: 999 additions & 310 deletions

README.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
# PostTypes v2.2.1
1+
# PostTypes v3.0
22

33
[![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)
44

5-
> Simple WordPress custom post types.
5+
> Modern PHP abstractions for WordPress post types and taxonomies.
6+
7+
## Migrating from v2 to v3
8+
9+
> **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.
610
711
## Requirements
812

@@ -58,7 +62,7 @@ class Book extends PostType {
5862
'view_item' => __( 'View Book', 'text-domain' ),
5963
'search_items' => __( 'Search Books', 'text-domain' ),
6064
'not_found' => __( 'No Books found', 'text-domain' ),
61-
'not_found_in_trash' => __( 'No Books found in Trash', 'text-domain'),
65+
'not_found_in_trash' => __( 'No Books found in Trash', 'text-domain' ),
6266
'parent_item_colon' => __( 'Parent Book', 'text-domain' ),
6367
];
6468
}
@@ -71,7 +75,7 @@ class Book extends PostType {
7175
'title',
7276
'editor',
7377
'thumbnail',
74-
'custom-fields'
78+
'custom-fields',
7579
];
7680
}
7781

@@ -80,7 +84,7 @@ class Book extends PostType {
8084
*/
8185
public function taxonomies(): array {
8286
return [
83-
'genre'
87+
'genre',
8488
'category',
8589
];
8690
}
@@ -98,7 +102,7 @@ class Book extends PostType {
98102
public function filters(): array {
99103
return [
100104
'genre',
101-
'category'
105+
'category',
102106
];
103107
}
104108

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

129133
```php
130-
// Instantiate the Books PostType class.
131-
$books = new Books;
134+
// Instantiate the Book PostType class.
135+
$book = new Book;
132136

133-
// Register the books PostType to WordPress.
134-
$books->register();
137+
// Register the Book PostType to WordPress.
138+
$book->register();
135139
```
136140

137141
## Notes

docs/SUMMARY.md

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
# Table of Contents
22

33
* [PostTypes v3.0](../README.md)
4-
* [Getting Started](Getting-started.md)
4+
* [Migrating from v2 to v3](migrating-from-v2-v3.md)
5+
* [Getting Started](getting-started.md)
56
* [PostTypes](post-types/README.md)
6-
* [Create a Post Type](post-types/Create-a-post-type.md)
7-
* [Defining Labels](post-types/Defining-labels.md)
8-
* [Defining Options](post-types/Defining-options.md)
9-
* [Defining taxonomies](post-types/Defining-taxonomies.md)
10-
* [Defining feature supports](post-types/Defining-feature-supports.md)
11-
* [Defining an icon](post-types/Defining-an-icon.md)
12-
* [Defining filters](post-types/Defining-filters.md)
13-
* [Modifying columns](post-types/Modifying-columns.md)
14-
* [Creating columns](post-types/Creating-columns.md)
15-
* [Defining hooks](post-types/Defining-hooks.md)
7+
* [Create a Post Type](post-types/create-a-post-type.md)
8+
* [Define Labels](post-types/define-labels.md)
9+
* [Define Options](post-types/define-options.md)
10+
* [Define taxonomies](post-types/define-taxonomies.md)
11+
* [Define feature supports](post-types/define-feature-supports.md)
12+
* [Define an icon](post-types/define-icon.md)
13+
* [Define filters](post-types/define-filters.md)
14+
* [Modify columns](post-types/modify-columns.md)
15+
* [Create columns](post-types/create-columns.md)
16+
* [Define hooks](post-types/define-hooks.md)
1617
* [Taxonomies](taxonomies/README.md)
17-
* [Create a Taxonomy](taxonomies/Create-a-taxonomy.md)
18-
* [Defining Labels](taxonomies/Defining-labels.md)
19-
* [Defining Options](taxonomies/Defining-options.md)
20-
* [Defining Post Types](taxonomies/Defining-post-types.md)
21-
* [Modifying Columns](taxonomies/Modifying-columns.md)
22-
* [Defining Hooks](taxonomies/Defining-hooks.md)
18+
* [Create a Taxonomy](taxonomies/create-a-taxonomy.md)
19+
* [Define Labels](taxonomies/define-labels.md)
20+
* [Define Options](taxonomies/define-options.md)
21+
* [Define Post Types](taxonomies/define-post-types.md)
22+
* [Modify Columns](taxonomies/modify-columns.md)
23+
* [Define Hooks](taxonomies/define-hooks.md)
2324
* [Contributing](../CONTRIBUTING.md)
2425
* [Changelog](../Changelog.md)
Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Book extends PostType {
5454
'view_item' => __( 'View Book', 'text-domain' ),
5555
'search_items' => __( 'Search Books', 'text-domain' ),
5656
'not_found' => __( 'No Books found', 'text-domain' ),
57-
'not_found_in_trash' => __( 'No Books found in Trash', 'text-domain'),
57+
'not_found_in_trash' => __( 'No Books found in Trash', 'text-domain' ),
5858
'parent_item_colon' => __( 'Parent Book', 'text-domain' ),
5959
];
6060
}
@@ -67,7 +67,7 @@ class Book extends PostType {
6767
'title',
6868
'editor',
6969
'thumbnail',
70-
'custom-fields'
70+
'custom-fields',
7171
];
7272
}
7373

@@ -76,7 +76,7 @@ class Book extends PostType {
7676
*/
7777
public function taxonomies(): array {
7878
return [
79-
'genre'
79+
'genre',
8080
'category',
8181
];
8282
}
@@ -94,7 +94,7 @@ class Book extends PostType {
9494
public function filters(): array {
9595
return [
9696
'genre',
97-
'category'
97+
'category',
9898
];
9999
}
100100

@@ -105,13 +105,21 @@ class Book extends PostType {
105105
// Remove the author and date column.
106106
$columns->remove( [ 'author', 'date' ] );
107107

108-
// Add a Rating column.
109-
$columns->add( 'rating', __( 'Rating', 'post-types' ) );
110-
111-
// Populate the rating column.
112-
$columns->populate( 'rating', function( $post_id ) {
113-
echo get_post_meta( $post_id, 'rating', true );
114-
} );
108+
// Add a new price column.
109+
$columns->add( 'price' )
110+
// Set the label.
111+
->label( __( 'Price', 'my-text-domain' ) )
112+
// Position the column after the title column.
113+
->after( 'title' )
114+
// Set the populate callback.
115+
->populate( function( $post_id ) {
116+
echo '$' . get_post_meta( $post_id, '_price', true );
117+
} )
118+
// Set the sort callback.
119+
->sort( function( WP_Query $query ) {
120+
$query->set( 'meta_key', 'price' );
121+
$query->set( 'orderby', 'meta_value_num' );
122+
} );
115123

116124
return $columns;
117125
}
@@ -123,9 +131,9 @@ class Book extends PostType {
123131
Once the custom post type class is created it can be registered to WordPress by instantiating and call the register method.
124132

125133
```php
126-
// Instantiate the Books PostType class.
127-
$books = new Books;
134+
// Instantiate the Book PostType class.
135+
$book = new Book;
128136

129-
// Register the books PostType to WordPress.
130-
$books->register();
137+
// Register the Book PostType to WordPress.
138+
$book->register();
131139
```

0 commit comments

Comments
 (0)