\Fluent_Post_Type

Fluent_Taxonomy simple class for creating post types

Summary

Methods
Properties
Constants
__construct()
remove_add_new()
block_add_new()
locate_template()
register_post_types()
flush_rewrite_rules()
post_update_messages()
$version
$post_types
$post_type
$args
$domain
$url
No constants found
parse_args()
provide()
random_string()
guid()
No protected properties found
N/A
default_args()
default_labels()
No private properties found
N/A

Properties

$version

$version : string

Type

string — Class version.

$post_types

$post_types : array

Type

array — Used to store all to be registered post types.

$post_type

$post_type : string

Type

string — The post type name.

$args

$args : array

Type

array — Class args to be run attached after <code>parse_args</code>.

$domain

$domain : string

Type

string — Class text domain.

$url

$url : string

Type

string — fluent url.

Methods

__construct()

__construct( $post_type,  $args) : \none

Called on class instance creation, adds the new post type to the static $post_types array for registering at the correct points.

Replaces spaces and dashes with underscores in the post type name but doesnt run sanitize_key() as register_post_type() does this already and we would just be adding proccessing time. Trims post type name length to 20 chars at most.

Parameters

$post_type
$args

Returns

\none

remove_add_new()

remove_add_new() : \none

Removes the sub menu item for adding new posts to the post type.

Only called if set, and removes the add new button in the header as well.

Returns

\none

block_add_new()

block_add_new() : \none

Blocks access of adding new posts to the post type.

Only called if set, does a wp_redirect to the overview page.

Returns

\none

locate_template()

locate_template( $template) : string

Returns the set template path if its either not found in the theme, or we want to override it.

Parameters

$template

Returns

string —

$template. The template path.

register_post_types()

register_post_types() : \none

Called during a rewrite flush, and on init to register the post types in the static $post_types array.

Returns

\none

flush_rewrite_rules()

flush_rewrite_rules() : \none

Registers post types from the static $post_types array and flushes the rewrite rules. This is done on admin init, and only if new post types exist in the option.

This is quite neat because it checks for new post types against the saved option, but only flushes if 1 or more hasnt already been added. It then only updates the option if flush == true. Its done on admin init as activation of plugins/themes can only be done via the admin so there is no need to do it on normal init.

Returns

\none

post_update_messages()

post_update_messages( $messages) : array

Returns any custom update messages for the post type notices.

WordPress should really allow you to do this in the labels arg of registering the post type, but hey its easy enough to work round. This function exits if it isnt a framework created post type, or provides the messages from the default array, or user supplied if it is.

Parameters

$messages

Returns

array —

$messages

parse_args()

parse_args(array $a, array $b, string $filter) : array

Recursive array merging from a default and supplied array.

Very similar function to wp_parse_args except it filters through the whole array tree.

Parameters

array $a

supplied value array.

array $b

default value array.

string $filter

optionally run the array through apply_filters before returning.

Returns

array

provide()

provide(string $key) : array

The provide function is just a shorthand wrapper for suppling a class object and method as array in WordPress actions and filters.

Parameters

string $key

the method name to be added to the array: array( &$this, $key ).

Returns

array

random_string()

random_string(string $length) : string

Helper function used inside the <code>guid()</code> function to generate random strings.

Parameters

string $length

the number of characters to return.

Returns

string

guid()

guid() : string

Guid function used to reformat array index values before sedning them to the fields.

Simply replicates the behaviour found in framework javascript.

Returns

string

default_args()

default_args() : array

Function used across extended classes used in conjunction with <code>parse_args</code> to format supplied arrays and ensure all keys are supplied.

Returns

array

default_labels()

default_labels() : array

Supplied some default labels with placeholders to be replaced during proccessing.

Returns

array