Download the PHP package whodunit/post-type-handler without Composer
On this page you can find all versions of the php package whodunit/post-type-handler. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download whodunit/post-type-handler
More information about whodunit/post-type-handler
Files in whodunit/post-type-handler
Package post-type-handler
Short Description Helper class to quickly manage PostType and Taxonomy declarations
License
Informations about the package post-type-handler
PostTypeHandler
Helper class to quickly manage PostType and Taxonomy declarations
Features
- Easily add new Post Types or update existing ones
- Easily add new Taxonomies
- Easily link Post Types to Taxonomies & vice versa
- Easily add new columns to the admin and manage them ( populate, sort, reorder )
- Easily add admin taxonomy filters
Installation
Install with composer
Run the following in your terminal to install the package with composer
The package use the autoloader, so don't forget to register the autoloader. If you don't know how see the basic example below.
Basic Usage
Below is a basic example of setting up a simple PostType.
You can set the dashicon like that :
You can add custom $options and $labels to the PostType declaration.
You can also set the taxonomies for the PostType if they are previously registered.
Otherwise you can register a new Taxonomy and then even add it to the PostType declaration.
Or you can set the taxonomy to a Post Type that is already registered.
You can give the Taxonomy object itself to the PostType.
You can do the same with an existing CPT, like Post :
You can also remove a taxonomy from a Post Type.
Manage Post Types columns
I will explain some examples of how to manage the columns for a Post Type.
- Register the Post Type.
- Manipulate the columns.
- Save the changes by re-registering the Post Type.
Add a new column
To add new columns to a Post Type you can do the following
Hide a column
To hide a column you can do the following
Set all columns
You can set all columns at once By doing this you must take a look at the Manage columns hook to prevent unwanted columns
Populate a column
To populate a column you can do the following
- You can only populate one column at once
- You must display the content and not return it
- You can't use this to populate a built-in column
You can also add new columns to existing and built in post types
Make a column sortable
To make a column sortable you can do the following
- You must make the column slug in key and value of the array
- The value must be the meta key to sort using
- Don't forget to populate the column before you make it sortable!
Order the columns
You may want to order the columns, even the native ones, do the following
- Set the final position, starting from 0
- Avoid duplicate and negative positions in your array!
Adding taxonomy filters to the edit screen
To add taxonomy filters to the edit screen you can do the following
- Add a list of taxonomies slugs
- The order is important because the filters will be displayed that order!
Hooks
Hook type | Hook name | Params | Description |
---|---|---|---|
Filter | gt_posttype{$post_type}_labels | array $labels | Custom the labels for the post type |
Filter | gt_posttype{$post_type}_options | array $options | Custom the options for the post type |
Filter | gt_posttype{$post_type}_check_slug_conflict | boolean $check | Check for slug conflicts. Requires DB query. |
Filter | gttaxonomy{$post_type}_labels | array $labels | Custom the labels for the taxonomy |
Filter | gttaxonomy{$post_type}_options | array $options | Custom the options for the taxonomy |
TODOS
Can also add taxonomy by sending the object itself ( by the object itself, maybe with a __tostring method )Adding a way to manage ColumnsHide columns and defaults for each post typeAdding new columns to the admin screenSet columns orderSet the entire columns arrayPopulate any column with a custom functionCan sort each columns with their values ( numerically / alphabetically )
Adding a function to easily add icon without using the $options arrayAdding a way to manage the Filters on screen adminSet an array to order them and keep an order
Add a class to manage the taxonomiesAdding new Taxonomies- Can work on existing taxonomies ( post_tag & category )
Can be registered on a post type directly ( by the slug or the object itself, maybe with a __tostring method )
Can work on existing post types ( update options and labels )Add the @link/author/license to the main class- Same columns but for the taxonomies
- Can delete row actions ( edit, view, trash, delete ) from the admin screen ( 'post_row_actions' )
- Check if we can do the same for adding ones
- Check to add/remove bulk edit actions
- Check if we can add/update/remove the list above the bulk actions ( all / published etc ... )