\CustomPostTypeCPT

The main CustomPostType Class. You need to extend this class in order to use it.

Summary

Methods
Properties
Constants
__construct()
init()
addMetaBoxes()
addField()
addCustomColumn()
meta_box_cb()
meta_box_html()
meta_box_save()
custom_columns()
custom_columns_sort()
custom_columns_show()
initAdmin()
adminScripts()
adminStyles()
$internal_name
$name
$labels
$cpt_args
$meta_boxes
$meta_fields
$custom_columns
$sortable_columns
$custom_columns_show
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Properties

$internal_name

$internal_name : string

Internal name for the custom post type

Type

string

$name

$name : string

Main display name for the custom post type. It tries to generate all the other labels from this one.

Type

string

$labels

$labels : array<mixed,string>

List of labels for the custom post type.

Type

array<mixed,string>

$cpt_args

$cpt_args : array

Custom post type arguments for register_post_type function

Type

array

$meta_boxes

$meta_boxes : array

Contains meta boxes informations when using addMetaBoxes function

Type

array

$meta_fields

$meta_fields : array

Contains meta fields information

Type

array

$custom_columns

$custom_columns : array

Contains Custom columns

Type

array

$sortable_columns

$sortable_columns : array

Contains sortable Columns

Type

array

$custom_columns_show

$custom_columns_show : array

Containes Columns display

Type

array

Methods

__construct()

__construct() 

Construct CPT

init()

init() : void

Init the register_post_type function

addMetaBoxes()

addMetaBoxes(string  $id, string  $title, integer  $order = 100) 

Add a metabox to the CustomePostType admin editor

Parameters

string $id

Id of the metabox, must be unique

string $title

Tile of the metabox

integer $order

Order for all the custom meta boxes

addField()

addField(string  $id, string  $label, string  $meta_box, string  $type, array  $options = array()) 

Add a field to a custom metabox

Parameters

string $id

Field's id, must be unique. It will be the meta key.

string $label

Label for admin editing

string $meta_box

Custom metaboxe's id

string $type

Field type (editor|text|date|time|file|textarea|select|number)

array $options

List of options for select with key => value

addCustomColumn()

addCustomColumn(string  $id, string  $label, boolean  $sort, boolean  $type = false) 

Add a custom column for the listing page

Parameters

string $id

Column's id, must be unique

string $label

Column's name

boolean $sort

Is the column sortable

boolean $type

The type of the content to display (editor|text|date|time|file|textarea|select|number)

meta_box_cb()

meta_box_cb() 

Register the meta boxes

meta_box_html()

meta_box_html(\CustomPostType\WP_Post  $post, array  $args) 

Display the meta box html

Parameters

\CustomPostType\WP_Post $post

Current post

array $args

Additional arguments

meta_box_save()

meta_box_save(integer  $post_id) 

When the save action is triggered, we save the meta data

Parameters

integer $post_id

Current post id

custom_columns()

custom_columns(array  $columns) : array

Change the columns when listings the custom post

Parameters

array $columns

Contains default columns to display

Returns

array —

Columns to display

custom_columns_sort()

custom_columns_sort(array  $columns) : array

Define the sortable columns

Parameters

array $columns

Array of string for column's name

Returns

array —

Formatted array for sorting columns

custom_columns_show()

custom_columns_show(array  $name) 

Define the content for custom columns

Parameters

array $name

Array of name for columns to display

initAdmin()

initAdmin() 

Init the actions for admin scripts and styles

adminScripts()

adminScripts() 

Enqueue admin scripts

adminStyles()

adminStyles() 

Anqueue admin styles