: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
used to help create custom post types for Wordpress
http://github.com/jjgrainger/wp-custom-post-type-class/
@url http://jjgrainger.co.uk
@license http://www.opensource.org/licenses/mit-license.html MIT License
@var string $post_type_name
Public variable that holds the name of the post type
assigned on __contstruct()
Public variable that holds the singular name of the post type
This is a human friendly name, capitalized with spaces
assigned on __contstruct()
Public variable that holds the plural name of the post type
This is a human friendly name, capitalized with spaces
assigned on __contstruct()
Public variable that holds the slug name of the post type
This is a robot friendly name, all lowercase and uses hyphens
assigned on __contstruct()
public variable that holds the user submited options of the post type
assigined on __construct()
public variable that holds an array of the taxonomies associated with the post type
assigined on register_taxonomy()
@var array $taxonomy_settings
public variable that holds an array of the taxonomies associated with the post type and their options
used when registering the taxonomies
assigined on register_taxonomy()
public $taxonomy_settings;
use to define which filters are to appear on admin edit screen
used in add_taxonmy_filters()
use to define which columns are to appear on admin edit screen
used in add_admin_columns()
@var array $custom_populate_columns
an array of user defined functions to populate admin columns
public $custom_populate_columns;
use to define which columns are to sortable on admin edit screen
@function __contructor(@post_type_name, @options)
@param mixed $post_type_names The name(s) of the post type, accepts (post type name, slug, plural, singluar)
@param array $options User submitted options
function __construct($post_type_names, $options = array()) {
// check if post type names is string or array
if(is_array($post_type_names)) {
// set the post type name
$this->post_type_name = $post_type_names['post_type_name'];
// cycle through possible names
foreach($names as $name) {
// if the name has been set by user
if(isset($post_type_names[$name])) {
$this->$name = $post_type_names[$name];
// else generate the name
// define the method to be used
$this->$name = $this->{'get_'.$name}();
// else the post type name is only supplied
// apply to post type name
$this->post_type_name = $post_type_names;
$this->slug = $this->get_slug();
// set the plural name label
$this->plural = $this->get_plural();
// set the singular name label
$this->singular = $this->get_singular();
// set the user submitted options to the object
$this->options = $options;
// register the post type
//$this->add_action('init', array(&$this, 'register_post_type'));
$this->register_post_type();
//$this->add_action('init', array(&$this, 'register_taxonomies'));
$this->register_taxonomies();
// add taxonomy to admin edit columns
$this->add_filter('manage_edit-' . $this->post_type_name . '_columns', array($this, 'add_admin_columns'));
// populate the taxonomy columns with the posts terms
$this->add_action('manage_' . $this->post_type_name . '_posts_custom_column', array($this, 'populate_admin_columns'), 10, 2);
// add filter select option to admin edit
$this->add_action('restrict_manage_posts', array($this, 'add_taxonomy_filters'));
used to get an object variable
@param string $var the variable you would like to retrieve
@return mixed returns the value on sucess, bool (false) when fails
// if the variable exisits
// on success return the value
used to set an object variable
can overwrite exisiting variables and create new ones
cannot overwrite reserved variables
@param mixed $var the variable you would like to create/overwrite
@param mixed $value the value you would like to set to the variable
function set($var, $value) {
// an array of reserved variables that cannot be overwritten
// if the variable is not a reserved variable
if(!in_array($var, $reserved,true)) {
// write variable and value
helper function add_action
used to create add_action wordpress filter
http://codex.wordpress.org/Function_Reference/add_action
@param string $action name of the action to hook to, e.g 'init'
@param string $function function to hook that will run on @action
@param int $priority order in which to execute the function, relation to other function hooked to this action
@param int $accepted_args the number of arguements the function accepts
function add_action($action, $function, $priority = 10, $accepted_args = 1) {
// pass variables into Wordpress add_action function
add_action($action, $function, $priority, $accepted_args);
helper function add_filter
used to create add_filter wordpress filter
http://codex.wordpress.org/Function_Reference/add_filter
@param string $action name of the action to hook to, e.g 'init'
@param string $function function to hook that will run on @action
@param int $priority order in which to execute the function, relation to other function hooked to this action
@param int $accepted_args the number of arguements the function accepts
function add_filter($action, $function, $priority = 10, $accepted_args = 1) {
// pass variables into Wordpress add_action function
add_filter($action, $function, $priority, $accepted_args);
creates url friendly slug
@param string $name name to slugify
@return string $name returns the slug
function get_slug($name = null) {
// if no name set use the post type name
$name = $this->post_type_name;
// replace spaces with hyphen
return str_replace(array(' ','_'), '-', strtolower($name));
helper function get_plural
returns the friendly plural name
strtolower makes string lowercase before capitalizing
str_replace replace all instances of _ to space
@param string $name the slug name you want to pluralize
@return string the friendly pluralized name
function get_plural($name = null) {
// if no name is passed the post_type_name is used
$name = $this->post_type_name;
// return the plural name
return $this->get_human_friendly($name) . 's';
helper function get_singular
returns the friendly singular name
strtolower makes string lowercase before capitalizing
str_replace replace all instances of _ to space
@param string $name the slug name you want to unpluralize
@return string the friendly singular name
function get_singular($name = null) {
// if no name is passed the post_type_name is used
$name = $this->post_type_name;
return $this->get_human_friendly($name);
helper function get_human_friendly
returns the human friendly name
strtolower makes string lowercase before capitalizing
str_replace replace all instances of hyphens and underscores to spaces
@param string $name the name you want to make friendly
@return string the human friendly name
function get_human_friendly($name = null) {
// if no name is passed the post_type_name is used
$name = $this->post_type_name;
// return human friendly name
return ucwords(strtolower(str_replace('-', ' ', str_replace('_', ' ', $name))));
register_post_type function
object function to register the post type
http://codex.wordpress.org/Function_Reference/register_post_type
function register_post_type() {
// friendly post type names
$singular = $this->singular;
'singular_name' => $singular,
'add_new' => __('Add New', 'themify'),
'add_new_item' => sprintf( __('Add new %s', 'themify'), $singular ),
'edit_item' => sprintf( __('Edit %s', 'themify'), $singular ),
'new_item' => sprintf( __('New %s', 'themify'), $singular ),
'view_item' => sprintf( __('View %s', 'themify'), $singular ),
'search_items' => sprintf( __('Search %s', 'themify'), $plural ),
'not_found' => sprintf( __('No %s found', 'themify'), $plural ),
'not_found_in_trash' => sprintf( __('No %s found in Trash', 'themify'), $plural ),
'parent_item_colon' => sprintf( __('Parent %s:', 'themify'), $singular )
// merge user submitted options with defaults
$options = wp_parse_args( $this->options, $defaults );
// set the object options as full options passed
$this->options = $options;
// check that the post type doesn't already exist
if(!post_type_exists($this->post_type_name)) {
// register the post type
register_post_type($this->post_type_name, $options);
function register_taxonomy
register a taxonomy to a post type
@param string $taxonomy_name the slug for the taxonomy
@param array $options taxonomy options
http://codex.wordpress.org/Function_Reference/register_taxonomy
function register_taxonomy($taxonomy_names, $options = array()) {
// an array of the names required excluding taxonomy_name
// if an array of names are passed
if(is_array($taxonomy_names)) {
$taxonomy_name = $taxonomy_names['taxonomy_name'];
// cycle through possible names
foreach($names as $name) {
// if the user has set the name
if(isset($taxonomy_names[$name])) {
// use user submitted name
$$name = $taxonomy_names[$name];
// else generate the name
// define the fnction to be used
$$name = $this->{'get_'.$name}( $taxonomy_name );
// else if only the taxonomy_name has been supplied
// create user friendly names
$taxonomy_name = $taxonomy_names;
$singular = $this->get_singular($taxonomy_name);
$plural = $this->get_plural($taxonomy_name);
$slug = $this->get_slug($taxonomy_name);
'singular_name' => $singular,
'all_items' => sprintf( __('All %s', 'themify'), $plural ),
'edit_item' => sprintf( __('Edit %s', 'themify'), $singular ),
'view_item' => sprintf( __('View %s', 'themify'), $singular ),
'update_item' => sprintf( __('Update %s', 'themify'), $singular ),
'add_new_item' => sprintf( __('Add New %s', 'themify'), $singular ),
'new_item_name' => sprintf( __('New %s', 'themify'), $singular ),
'parent_item' => sprintf( __('Parent %s', 'themify'), $plural ),
'parent_item_colon' => sprintf( __('Parent %s:', 'themify'), $plural ),
'search_items' => sprintf( __('Search %s', 'themify'), $plural ),
'popular_items' => sprintf( __('Popular %s', 'themify'), $plural ),
'separate_items_with_commas' => sprintf( __('Separate %s with commas', 'themify'), $plural ),
'add_or_remove_items' => sprintf( __('Add or remove %s', 'themify'), $plural ),