<commit_before># PostTypes v2.0.1

[![Build Status](https://travis-ci.org/jjgrainger/PostTypes.svg?branch=master)](https://travis-ci.org/jjgrainger/PostTypes) [![Total Downloads](https://poser.pugx.org/jjgrainger/posttypes/downloads)](https://packagist.org/packages/jjgrainger/posttypes) [![Latest Stable Version](https://poser.pugx.org/jjgrainger/posttypes/v/stable)](https://packagist.org/packages/jjgrainger/posttypes) [![License](https://poser.pugx.org/jjgrainger/posttypes/license)](https://packagist.org/packages/jjgrainger/posttypes)

> Simple WordPress custom post types.

## Installation

#### Install with composer

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

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

As PostTypes uses [PSR-4](http://www.php-fig.org/psr/psr-4/) autoloading you will need to use Composers autoloader. Below is a basic example of getting started with the class, though your setup maybe different depending on how you are using composer.

```php
require __DIR__ . '/vendor/autoload.php';

use PostTypes\PostType;

$books = new PostType('book');

$books->register();
```

See Composers [basic usage](https://getcomposer.org/doc/01-basic-usage.md#autoloading) guide for details on working Composer and autoloading.

## Post Types

#### Create a new Post Type

A new post type can be created by simply passing the post types name to the class constructor. To register the post type to WordPress you must call the `register()` method.

```php
// Create a book post type
$books = new PostType('book');

// Register the post type to WordPress
$books->register();
```

#### Defining names

The post type labels and slugs are automatically generated from the post type name, however, if you need to define these manually pass an array of names to the post types constructor.

```php
$names = [
    'name' => 'book',
    'singular' => 'Book',
    'plural' => 'Books',
    'slug' => 'books'
];

$books = new PostType($names);

$books->register();
```

It can accept the following names:

* `name` is the post type name (*required*, singular, lowercase, underscores)
* `singular` is the singular label for the post type (Book, Person)
* `plural` is the plural label for the post type (Books, People)
* `slug` is the post type slug used in the permalinks (plural, lowercase, hyphens)

The only required name is the post types `name`.

#### Adding options

You can define the options for the post type by passing an array as the second argument in the class constructor.

```php
$options = [
    'has_archive' => false
];

$books = new PostType('book', $options);

$books->register();
```

All available options are on the [WordPress Codex](https://codex.wordpress.org/Function_Reference/register_post_type)

#### Adding labels

You can define the labels for the post type by passing an array as the third argument in the class constructor.

```php
$labels = [
    'featured_image' => __( 'Book Cover Image' ),
];

$books = new PostType('book', $options, $labels);

$books->register();
```

Alternatively, you can use the `labels()` method to set the labels for the post type.

```php
$books = new PostType('books');

$books->labels([
    'add_new_item' => __('Add new Book')
]);

$books->register();
```

All available labels are on the [WordPress Codex](https://codex.wordpress.org/Function_Reference/register_post_type)

#### Exisiting Post Types

To work with exisiting post types simple pass the post type name into the object. Be careful using global variables (i.e `$post`) which can lead to unwanted results.

```php
// Create a PostType object for an existing post type in WordPress
$blog = new PostType('post');

// Make changes to the post type...

// You still need to register the changes to WordPress
$blog->register();
```

## Taxonomies

Taxonomies are created using the `Taxonomy` class. This works indetically to the `PostType` class and holds similar methods.

#### Create new taxonomy

To create a new taxonomy simply pass the taxonomy name to the `Taxonomy` class constructor. Labels and the taxonomy slug are generated from the taxonomy name.

```php
// Create a new taxonomy
$genres = new Taxonomy('genre');

// Register the taxonomy to WordPress
$genres->register();
```

#### Defining names

You can define names by passing an array as the first argument. Only the `name` is required.

* `name` is the post type name
* `singular` is the singular label for the post type
* `plural` is the plural label for the post type
* `slug` is the post type slug used in the permalinks

```php
$names = [
    'name' => 'genre',
    'singular' => 'Genre',
    'plural' => 'Genres',
    'slug' => 'genres'
];

$genres = new Taxonomy($names);

$genres->register();
```

#### Adding options<commit_msg>Add a note about including the Taxonomy class<commit_after># PostTypes v2.0.1

[![Build Status](https://travis-ci.org/jjgrainger/PostTypes.svg?branch=master)](https://travis-ci.org/jjgrainger/PostTypes) [![Total Downloads](https://poser.pugx.org/jjgrainger/posttypes/downloads)](https://packagist.org/packages/jjgrainger/posttypes) [![Latest Stable Version](https://poser.pugx.org/jjgrainger/posttypes/v/stable)](https://packagist.org/packages/jjgrainger/posttypes) [![License](https://poser.pugx.org/jjgrainger/posttypes/license)](https://packagist.org/packages/jjgrainger/posttypes)

> Simple WordPress custom post types.

## Installation

#### Install with composer

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

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

As PostTypes uses [PSR-4](http://www.php-fig.org/psr/psr-4/) autoloading you will need to use Composers autoloader. Below is a basic example of getting started with the class, though your setup maybe different depending on how you are using composer.

```php
require __DIR__ . '/vendor/autoload.php';

use PostTypes\PostType;

$books = new PostType('book');

$books->register();
```

See Composers [basic usage](https://getcomposer.org/doc/01-basic-usage.md#autoloading) guide for details on working Composer and autoloading.

## Post Types

#### Create a new Post Type

A new post type can be created by simply passing the post types name to the class constructor. To register the post type to WordPress you must call the `register()` method.

```php
// Create a book post type
$books = new PostType('book');

// Register the post type to WordPress
$books->register();
```

#### Defining names

The post type labels and slugs are automatically generated from the post type name, however, if you need to define these manually pass an array of names to the post types constructor.

```php
$names = [
    'name' => 'book',
    'singular' => 'Book',
    'plural' => 'Books',
    'slug' => 'books'
];

$books = new PostType($names);

$books->register();
```

It can accept the following names:

* `name` is the post type name (*required*, singular, lowercase, underscores)
* `singular` is the singular label for the post type (Book, Person)
* `plural` is the plural label for the post type (Books, People)
* `slug` is the post type slug used in the permalinks (plural, lowercase, hyphens)

The only required name is the post types `name`.

#### Adding options

You can define the options for the post type by passing an array as the second argument in the class constructor.

```php
$options = [
    'has_archive' => false
];

$books = new PostType('book', $options);

$books->register();
```

All available options are on the [WordPress Codex](https://codex.wordpress.org/Function_Reference/register_post_type)

#### Adding labels

You can define the labels for the post type by passing an array as the third argument in the class constructor.

```php
$labels = [
    'featured_image' => __( 'Book Cover Image' ),
];

$books = new PostType('book', $options, $labels);

$books->register();
```

Alternatively, you can use the `labels()` method to set the labels for the post type.

```php
$books = new PostType('books');

$books->labels([
    'add_new_item' => __('Add new Book')
]);

$books->register();
```

All available labels are on the [WordPress Codex](https://codex.wordpress.org/Function_Reference/register_post_type)

#### Exisiting Post Types

To work with exisiting post types simple pass the post type name into the object. Be careful using global variables (i.e `$post`) which can lead to unwanted results.

```php
// Create a PostType object for an existing post type in WordPress
$blog = new PostType('post');

// Make changes to the post type...

// You still need to register the changes to WordPress
$blog->register();
```

## Taxonomies

Taxonomies are created using the `Taxonomy` class. This works indetically to the `PostType` class and holds similar methods.

#### Create new taxonomy

To create a new taxonomy simply pass the taxonomy name to the `Taxonomy` class constructor. Labels and the taxonomy slug are generated from the taxonomy name.

```php
// Make sure to load the Taxonomy class
use PostTypes\Taxonomy;

// Create a new taxonomy
$genres = new Taxonomy('genre');

// Register the taxonomy to WordPress
$genres->register();
```

#### Defining names

You can define names by passing an array as the first argument. Only the `name` is required.

* `name` is the post type name
* `singular` is the singular label for the post type
* `plural` is the plural label for the post type
* `slug` is the post type slug used in the permalinks

```php
$names = [
    'name' => 'genre',
    'singular' => 'Genre',
    'plural' => 'Genres',
    'slug' => 'genres'
];

$genres = new Taxonomy($names);

$genres->register();
```

#### Adding options
{'fraction_non_alphanumeric': 0.12661632357504915, 'fraction_numerical': 0.001448225923244026, 'mean_word_length': 4.455981941309255, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 47, 'https://': 24, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3643224', 'n_tokens_mistral': 2932, 'n_tokens_neox': 2857, 'n_words': 1123}