Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../public_h.../wp-conte.../plugins/themify-.../themify
File: CPT.php
<?php
[0] Fix | Delete
/*
[1] Fix | Delete
Custom Post Type Class
[2] Fix | Delete
used to help create custom post types for Wordpress
[3] Fix | Delete
http://github.com/jjgrainger/wp-custom-post-type-class/
[4] Fix | Delete
[5] Fix | Delete
@author jjgrainger
[6] Fix | Delete
@url http://jjgrainger.co.uk
[7] Fix | Delete
@version 1.2.3
[8] Fix | Delete
@license http://www.opensource.org/licenses/mit-license.html MIT License
[9] Fix | Delete
*/
[10] Fix | Delete
[11] Fix | Delete
class CPT {
[12] Fix | Delete
[13] Fix | Delete
/*
[14] Fix | Delete
@var string $post_type_name
[15] Fix | Delete
Public variable that holds the name of the post type
[16] Fix | Delete
assigned on __contstruct()
[17] Fix | Delete
*/
[18] Fix | Delete
public $post_type_name;
[19] Fix | Delete
[20] Fix | Delete
/*
[21] Fix | Delete
@var string $singular
[22] Fix | Delete
Public variable that holds the singular name of the post type
[23] Fix | Delete
This is a human friendly name, capitalized with spaces
[24] Fix | Delete
assigned on __contstruct()
[25] Fix | Delete
*/
[26] Fix | Delete
public $singular;
[27] Fix | Delete
[28] Fix | Delete
/*
[29] Fix | Delete
@var string $singular
[30] Fix | Delete
Public variable that holds the plural name of the post type
[31] Fix | Delete
This is a human friendly name, capitalized with spaces
[32] Fix | Delete
assigned on __contstruct()
[33] Fix | Delete
*/
[34] Fix | Delete
public $plural;
[35] Fix | Delete
[36] Fix | Delete
/*
[37] Fix | Delete
@var string $slug
[38] Fix | Delete
Public variable that holds the slug name of the post type
[39] Fix | Delete
This is a robot friendly name, all lowercase and uses hyphens
[40] Fix | Delete
assigned on __contstruct()
[41] Fix | Delete
*/
[42] Fix | Delete
public $slug;
[43] Fix | Delete
[44] Fix | Delete
/*
[45] Fix | Delete
@var array $options
[46] Fix | Delete
public variable that holds the user submited options of the post type
[47] Fix | Delete
assigined on __construct()
[48] Fix | Delete
*/
[49] Fix | Delete
public $options;
[50] Fix | Delete
[51] Fix | Delete
/*
[52] Fix | Delete
@var array $taxonomies
[53] Fix | Delete
public variable that holds an array of the taxonomies associated with the post type
[54] Fix | Delete
assigined on register_taxonomy()
[55] Fix | Delete
*/
[56] Fix | Delete
public $taxonomies;
[57] Fix | Delete
[58] Fix | Delete
/*
[59] Fix | Delete
@var array $taxonomy_settings
[60] Fix | Delete
public variable that holds an array of the taxonomies associated with the post type and their options
[61] Fix | Delete
used when registering the taxonomies
[62] Fix | Delete
assigined on register_taxonomy()
[63] Fix | Delete
*/
[64] Fix | Delete
public $taxonomy_settings;
[65] Fix | Delete
[66] Fix | Delete
/*
[67] Fix | Delete
@var array $filters
[68] Fix | Delete
use to define which filters are to appear on admin edit screen
[69] Fix | Delete
used in add_taxonmy_filters()
[70] Fix | Delete
*/
[71] Fix | Delete
public $filters;
[72] Fix | Delete
[73] Fix | Delete
/*
[74] Fix | Delete
@var array $columns
[75] Fix | Delete
use to define which columns are to appear on admin edit screen
[76] Fix | Delete
used in add_admin_columns()
[77] Fix | Delete
*/
[78] Fix | Delete
public $columns;
[79] Fix | Delete
[80] Fix | Delete
/*
[81] Fix | Delete
@var array $custom_populate_columns
[82] Fix | Delete
an array of user defined functions to populate admin columns
[83] Fix | Delete
*/
[84] Fix | Delete
public $custom_populate_columns;
[85] Fix | Delete
[86] Fix | Delete
/*
[87] Fix | Delete
@var array $sortable
[88] Fix | Delete
use to define which columns are to sortable on admin edit screen
[89] Fix | Delete
*/
[90] Fix | Delete
public $sortable;
[91] Fix | Delete
[92] Fix | Delete
/*
[93] Fix | Delete
@function __contructor(@post_type_name, @options)
[94] Fix | Delete
[95] Fix | Delete
@param mixed $post_type_names The name(s) of the post type, accepts (post type name, slug, plural, singluar)
[96] Fix | Delete
@param array $options User submitted options
[97] Fix | Delete
*/
[98] Fix | Delete
function __construct($post_type_names, $options = array()) {
[99] Fix | Delete
[100] Fix | Delete
// check if post type names is string or array
[101] Fix | Delete
if(is_array($post_type_names)) {
[102] Fix | Delete
[103] Fix | Delete
// add names to object
[104] Fix | Delete
$names = array(
[105] Fix | Delete
'singular',
[106] Fix | Delete
'plural',
[107] Fix | Delete
'slug'
[108] Fix | Delete
);
[109] Fix | Delete
[110] Fix | Delete
// set the post type name
[111] Fix | Delete
$this->post_type_name = $post_type_names['post_type_name'];
[112] Fix | Delete
[113] Fix | Delete
// cycle through possible names
[114] Fix | Delete
foreach($names as $name) {
[115] Fix | Delete
[116] Fix | Delete
// if the name has been set by user
[117] Fix | Delete
if(isset($post_type_names[$name])) {
[118] Fix | Delete
[119] Fix | Delete
// use the user setting
[120] Fix | Delete
$this->$name = $post_type_names[$name];
[121] Fix | Delete
[122] Fix | Delete
// else generate the name
[123] Fix | Delete
} else {
[124] Fix | Delete
[125] Fix | Delete
// define the method to be used
[126] Fix | Delete
[127] Fix | Delete
// generate the name
[128] Fix | Delete
$this->$name = $this->{'get_'.$name}();
[129] Fix | Delete
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
}
[133] Fix | Delete
[134] Fix | Delete
// else the post type name is only supplied
[135] Fix | Delete
} else {
[136] Fix | Delete
[137] Fix | Delete
// apply to post type name
[138] Fix | Delete
$this->post_type_name = $post_type_names;
[139] Fix | Delete
[140] Fix | Delete
// set the slug name
[141] Fix | Delete
$this->slug = $this->get_slug();
[142] Fix | Delete
[143] Fix | Delete
// set the plural name label
[144] Fix | Delete
$this->plural = $this->get_plural();
[145] Fix | Delete
[146] Fix | Delete
// set the singular name label
[147] Fix | Delete
$this->singular = $this->get_singular();
[148] Fix | Delete
[149] Fix | Delete
}
[150] Fix | Delete
[151] Fix | Delete
// set the user submitted options to the object
[152] Fix | Delete
$this->options = $options;
[153] Fix | Delete
[154] Fix | Delete
// register the post type
[155] Fix | Delete
//$this->add_action('init', array(&$this, 'register_post_type'));
[156] Fix | Delete
$this->register_post_type();
[157] Fix | Delete
[158] Fix | Delete
// register taxonomies
[159] Fix | Delete
//$this->add_action('init', array(&$this, 'register_taxonomies'));
[160] Fix | Delete
$this->register_taxonomies();
[161] Fix | Delete
[162] Fix | Delete
// add taxonomy to admin edit columns
[163] Fix | Delete
$this->add_filter('manage_edit-' . $this->post_type_name . '_columns', array($this, 'add_admin_columns'));
[164] Fix | Delete
[165] Fix | Delete
// populate the taxonomy columns with the posts terms
[166] Fix | Delete
$this->add_action('manage_' . $this->post_type_name . '_posts_custom_column', array($this, 'populate_admin_columns'), 10, 2);
[167] Fix | Delete
[168] Fix | Delete
// add filter select option to admin edit
[169] Fix | Delete
$this->add_action('restrict_manage_posts', array($this, 'add_taxonomy_filters'));
[170] Fix | Delete
[171] Fix | Delete
}
[172] Fix | Delete
[173] Fix | Delete
[174] Fix | Delete
[175] Fix | Delete
/*
[176] Fix | Delete
helper function get
[177] Fix | Delete
used to get an object variable
[178] Fix | Delete
[179] Fix | Delete
@param string $var the variable you would like to retrieve
[180] Fix | Delete
@return mixed returns the value on sucess, bool (false) when fails
[181] Fix | Delete
[182] Fix | Delete
*/
[183] Fix | Delete
[184] Fix | Delete
function get($var) {
[185] Fix | Delete
[186] Fix | Delete
// if the variable exisits
[187] Fix | Delete
if($this->$var) {
[188] Fix | Delete
[189] Fix | Delete
// on success return the value
[190] Fix | Delete
return $this->$var;
[191] Fix | Delete
[192] Fix | Delete
} else {
[193] Fix | Delete
[194] Fix | Delete
// on fail return false
[195] Fix | Delete
return false;
[196] Fix | Delete
[197] Fix | Delete
}
[198] Fix | Delete
}
[199] Fix | Delete
[200] Fix | Delete
/*
[201] Fix | Delete
helper function set
[202] Fix | Delete
used to set an object variable
[203] Fix | Delete
can overwrite exisiting variables and create new ones
[204] Fix | Delete
cannot overwrite reserved variables
[205] Fix | Delete
[206] Fix | Delete
@param mixed $var the variable you would like to create/overwrite
[207] Fix | Delete
@param mixed $value the value you would like to set to the variable
[208] Fix | Delete
[209] Fix | Delete
*/
[210] Fix | Delete
function set($var, $value) {
[211] Fix | Delete
[212] Fix | Delete
// an array of reserved variables that cannot be overwritten
[213] Fix | Delete
$reserved = array(
[214] Fix | Delete
'config',
[215] Fix | Delete
'post_type_name',
[216] Fix | Delete
'singular',
[217] Fix | Delete
'plural',
[218] Fix | Delete
'slug',
[219] Fix | Delete
'options',
[220] Fix | Delete
'taxonomies'
[221] Fix | Delete
);
[222] Fix | Delete
[223] Fix | Delete
// if the variable is not a reserved variable
[224] Fix | Delete
if(!in_array($var, $reserved,true)) {
[225] Fix | Delete
[226] Fix | Delete
// write variable and value
[227] Fix | Delete
$this->$var = $value;
[228] Fix | Delete
[229] Fix | Delete
}
[230] Fix | Delete
[231] Fix | Delete
}
[232] Fix | Delete
[233] Fix | Delete
/*
[234] Fix | Delete
helper function add_action
[235] Fix | Delete
used to create add_action wordpress filter
[236] Fix | Delete
[237] Fix | Delete
see Wordpress Codex
[238] Fix | Delete
http://codex.wordpress.org/Function_Reference/add_action
[239] Fix | Delete
[240] Fix | Delete
@param string $action name of the action to hook to, e.g 'init'
[241] Fix | Delete
@param string $function function to hook that will run on @action
[242] Fix | Delete
@param int $priority order in which to execute the function, relation to other function hooked to this action
[243] Fix | Delete
@param int $accepted_args the number of arguements the function accepts
[244] Fix | Delete
*/
[245] Fix | Delete
function add_action($action, $function, $priority = 10, $accepted_args = 1) {
[246] Fix | Delete
[247] Fix | Delete
// pass variables into Wordpress add_action function
[248] Fix | Delete
add_action($action, $function, $priority, $accepted_args);
[249] Fix | Delete
[250] Fix | Delete
}
[251] Fix | Delete
[252] Fix | Delete
/*
[253] Fix | Delete
helper function add_filter
[254] Fix | Delete
used to create add_filter wordpress filter
[255] Fix | Delete
[256] Fix | Delete
see Wordpress Codex
[257] Fix | Delete
http://codex.wordpress.org/Function_Reference/add_filter
[258] Fix | Delete
[259] Fix | Delete
@param string $action name of the action to hook to, e.g 'init'
[260] Fix | Delete
@param string $function function to hook that will run on @action
[261] Fix | Delete
@param int $priority order in which to execute the function, relation to other function hooked to this action
[262] Fix | Delete
@param int $accepted_args the number of arguements the function accepts
[263] Fix | Delete
*/
[264] Fix | Delete
function add_filter($action, $function, $priority = 10, $accepted_args = 1) {
[265] Fix | Delete
[266] Fix | Delete
// pass variables into Wordpress add_action function
[267] Fix | Delete
add_filter($action, $function, $priority, $accepted_args);
[268] Fix | Delete
[269] Fix | Delete
}
[270] Fix | Delete
[271] Fix | Delete
/*
[272] Fix | Delete
helper function get slug
[273] Fix | Delete
creates url friendly slug
[274] Fix | Delete
[275] Fix | Delete
@param string $name name to slugify
[276] Fix | Delete
@return string $name returns the slug
[277] Fix | Delete
*/
[278] Fix | Delete
function get_slug($name = null) {
[279] Fix | Delete
[280] Fix | Delete
// if no name set use the post type name
[281] Fix | Delete
if(!isset($name)) {
[282] Fix | Delete
[283] Fix | Delete
$name = $this->post_type_name;
[284] Fix | Delete
[285] Fix | Delete
}
[286] Fix | Delete
[287] Fix | Delete
// replace spaces with hyphen
[288] Fix | Delete
return str_replace(array(' ','_'), '-', strtolower($name));
[289] Fix | Delete
}
[290] Fix | Delete
[291] Fix | Delete
/*
[292] Fix | Delete
helper function get_plural
[293] Fix | Delete
returns the friendly plural name
[294] Fix | Delete
[295] Fix | Delete
ucwords capitalize words
[296] Fix | Delete
strtolower makes string lowercase before capitalizing
[297] Fix | Delete
str_replace replace all instances of _ to space
[298] Fix | Delete
[299] Fix | Delete
@param string $name the slug name you want to pluralize
[300] Fix | Delete
@return string the friendly pluralized name
[301] Fix | Delete
*/
[302] Fix | Delete
function get_plural($name = null) {
[303] Fix | Delete
[304] Fix | Delete
// if no name is passed the post_type_name is used
[305] Fix | Delete
if(!isset($name)) {
[306] Fix | Delete
[307] Fix | Delete
$name = $this->post_type_name;
[308] Fix | Delete
[309] Fix | Delete
}
[310] Fix | Delete
[311] Fix | Delete
// return the plural name
[312] Fix | Delete
// add 's' to the end
[313] Fix | Delete
return $this->get_human_friendly($name) . 's';
[314] Fix | Delete
}
[315] Fix | Delete
[316] Fix | Delete
/*
[317] Fix | Delete
helper function get_singular
[318] Fix | Delete
returns the friendly singular name
[319] Fix | Delete
[320] Fix | Delete
ucwords capitalize words
[321] Fix | Delete
strtolower makes string lowercase before capitalizing
[322] Fix | Delete
str_replace replace all instances of _ to space
[323] Fix | Delete
[324] Fix | Delete
@param string $name the slug name you want to unpluralize
[325] Fix | Delete
@return string the friendly singular name
[326] Fix | Delete
*/
[327] Fix | Delete
function get_singular($name = null) {
[328] Fix | Delete
[329] Fix | Delete
// if no name is passed the post_type_name is used
[330] Fix | Delete
if(!isset($name)) {
[331] Fix | Delete
[332] Fix | Delete
$name = $this->post_type_name;
[333] Fix | Delete
[334] Fix | Delete
}
[335] Fix | Delete
[336] Fix | Delete
// return the string
[337] Fix | Delete
return $this->get_human_friendly($name);
[338] Fix | Delete
[339] Fix | Delete
}
[340] Fix | Delete
[341] Fix | Delete
/*
[342] Fix | Delete
helper function get_human_friendly
[343] Fix | Delete
returns the human friendly name
[344] Fix | Delete
[345] Fix | Delete
ucwords capitalize words
[346] Fix | Delete
strtolower makes string lowercase before capitalizing
[347] Fix | Delete
str_replace replace all instances of hyphens and underscores to spaces
[348] Fix | Delete
[349] Fix | Delete
@param string $name the name you want to make friendly
[350] Fix | Delete
@return string the human friendly name
[351] Fix | Delete
*/
[352] Fix | Delete
function get_human_friendly($name = null) {
[353] Fix | Delete
[354] Fix | Delete
// if no name is passed the post_type_name is used
[355] Fix | Delete
if(!isset($name)) {
[356] Fix | Delete
[357] Fix | Delete
$name = $this->post_type_name;
[358] Fix | Delete
[359] Fix | Delete
}
[360] Fix | Delete
[361] Fix | Delete
// return human friendly name
[362] Fix | Delete
return ucwords(strtolower(str_replace('-', ' ', str_replace('_', ' ', $name))));
[363] Fix | Delete
[364] Fix | Delete
}
[365] Fix | Delete
[366] Fix | Delete
/*
[367] Fix | Delete
register_post_type function
[368] Fix | Delete
object function to register the post type
[369] Fix | Delete
[370] Fix | Delete
see Wordpress Codex
[371] Fix | Delete
http://codex.wordpress.org/Function_Reference/register_post_type
[372] Fix | Delete
*/
[373] Fix | Delete
function register_post_type() {
[374] Fix | Delete
[375] Fix | Delete
// friendly post type names
[376] Fix | Delete
$plural = $this->plural;
[377] Fix | Delete
$singular = $this->singular;
[378] Fix | Delete
$slug = $this->slug;
[379] Fix | Delete
[380] Fix | Delete
// default labels
[381] Fix | Delete
$labels = array(
[382] Fix | Delete
'name' => $plural,
[383] Fix | Delete
'singular_name' => $singular,
[384] Fix | Delete
'menu_name' => $plural,
[385] Fix | Delete
'all_items' => $plural,
[386] Fix | Delete
'add_new' => __('Add New', 'themify'),
[387] Fix | Delete
'add_new_item' => sprintf( __('Add new %s', 'themify'), $singular ),
[388] Fix | Delete
'edit_item' => sprintf( __('Edit %s', 'themify'), $singular ),
[389] Fix | Delete
'new_item' => sprintf( __('New %s', 'themify'), $singular ),
[390] Fix | Delete
'view_item' => sprintf( __('View %s', 'themify'), $singular ),
[391] Fix | Delete
'search_items' => sprintf( __('Search %s', 'themify'), $plural ),
[392] Fix | Delete
'not_found' => sprintf( __('No %s found', 'themify'), $plural ),
[393] Fix | Delete
'not_found_in_trash' => sprintf( __('No %s found in Trash', 'themify'), $plural ),
[394] Fix | Delete
'parent_item_colon' => sprintf( __('Parent %s:', 'themify'), $singular )
[395] Fix | Delete
);
[396] Fix | Delete
[397] Fix | Delete
// default options
[398] Fix | Delete
$defaults = array(
[399] Fix | Delete
'labels' => $labels,
[400] Fix | Delete
'public' => true,
[401] Fix | Delete
'rewrite' => array(
[402] Fix | Delete
'slug' => $slug,
[403] Fix | Delete
)
[404] Fix | Delete
);
[405] Fix | Delete
[406] Fix | Delete
// merge user submitted options with defaults
[407] Fix | Delete
$options = wp_parse_args( $this->options, $defaults );
[408] Fix | Delete
[409] Fix | Delete
// set the object options as full options passed
[410] Fix | Delete
$this->options = $options;
[411] Fix | Delete
[412] Fix | Delete
// check that the post type doesn't already exist
[413] Fix | Delete
if(!post_type_exists($this->post_type_name)) {
[414] Fix | Delete
[415] Fix | Delete
// register the post type
[416] Fix | Delete
register_post_type($this->post_type_name, $options);
[417] Fix | Delete
[418] Fix | Delete
}
[419] Fix | Delete
[420] Fix | Delete
}
[421] Fix | Delete
[422] Fix | Delete
[423] Fix | Delete
/*
[424] Fix | Delete
function register_taxonomy
[425] Fix | Delete
register a taxonomy to a post type
[426] Fix | Delete
[427] Fix | Delete
@param string $taxonomy_name the slug for the taxonomy
[428] Fix | Delete
@param array $options taxonomy options
[429] Fix | Delete
[430] Fix | Delete
see Wordpress codex
[431] Fix | Delete
http://codex.wordpress.org/Function_Reference/register_taxonomy
[432] Fix | Delete
*/
[433] Fix | Delete
[434] Fix | Delete
function register_taxonomy($taxonomy_names, $options = array()) {
[435] Fix | Delete
[436] Fix | Delete
[437] Fix | Delete
// an array of the names required excluding taxonomy_name
[438] Fix | Delete
$names = array(
[439] Fix | Delete
'singular',
[440] Fix | Delete
'plural',
[441] Fix | Delete
'slug'
[442] Fix | Delete
);
[443] Fix | Delete
[444] Fix | Delete
// if an array of names are passed
[445] Fix | Delete
if(is_array($taxonomy_names)) {
[446] Fix | Delete
[447] Fix | Delete
// set the taxonomy name
[448] Fix | Delete
$taxonomy_name = $taxonomy_names['taxonomy_name'];
[449] Fix | Delete
[450] Fix | Delete
// cycle through possible names
[451] Fix | Delete
foreach($names as $name) {
[452] Fix | Delete
[453] Fix | Delete
// if the user has set the name
[454] Fix | Delete
if(isset($taxonomy_names[$name])) {
[455] Fix | Delete
[456] Fix | Delete
// use user submitted name
[457] Fix | Delete
$$name = $taxonomy_names[$name];
[458] Fix | Delete
[459] Fix | Delete
// else generate the name
[460] Fix | Delete
} else {
[461] Fix | Delete
[462] Fix | Delete
// define the fnction to be used
[463] Fix | Delete
[464] Fix | Delete
// generate the name
[465] Fix | Delete
$$name = $this->{'get_'.$name}( $taxonomy_name );
[466] Fix | Delete
[467] Fix | Delete
}
[468] Fix | Delete
[469] Fix | Delete
}
[470] Fix | Delete
[471] Fix | Delete
// else if only the taxonomy_name has been supplied
[472] Fix | Delete
} else {
[473] Fix | Delete
[474] Fix | Delete
// create user friendly names
[475] Fix | Delete
$taxonomy_name = $taxonomy_names;
[476] Fix | Delete
$singular = $this->get_singular($taxonomy_name);
[477] Fix | Delete
$plural = $this->get_plural($taxonomy_name);
[478] Fix | Delete
$slug = $this->get_slug($taxonomy_name);
[479] Fix | Delete
[480] Fix | Delete
}
[481] Fix | Delete
[482] Fix | Delete
// default labels
[483] Fix | Delete
$labels = array(
[484] Fix | Delete
'name' => $plural,
[485] Fix | Delete
'singular_name' => $singular,
[486] Fix | Delete
'menu_name' => $plural,
[487] Fix | Delete
'all_items' => sprintf( __('All %s', 'themify'), $plural ),
[488] Fix | Delete
'edit_item' => sprintf( __('Edit %s', 'themify'), $singular ),
[489] Fix | Delete
'view_item' => sprintf( __('View %s', 'themify'), $singular ),
[490] Fix | Delete
'update_item' => sprintf( __('Update %s', 'themify'), $singular ),
[491] Fix | Delete
'add_new_item' => sprintf( __('Add New %s', 'themify'), $singular ),
[492] Fix | Delete
'new_item_name' => sprintf( __('New %s', 'themify'), $singular ),
[493] Fix | Delete
'parent_item' => sprintf( __('Parent %s', 'themify'), $plural ),
[494] Fix | Delete
'parent_item_colon' => sprintf( __('Parent %s:', 'themify'), $plural ),
[495] Fix | Delete
'search_items' => sprintf( __('Search %s', 'themify'), $plural ),
[496] Fix | Delete
'popular_items' => sprintf( __('Popular %s', 'themify'), $plural ),
[497] Fix | Delete
'separate_items_with_commas' => sprintf( __('Separate %s with commas', 'themify'), $plural ),
[498] Fix | Delete
'add_or_remove_items' => sprintf( __('Add or remove %s', 'themify'), $plural ),
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function