: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
'choose_from_most_used' => sprintf( __('Choose from most used %s', 'themify'), $plural ),
'not_found' => sprintf( __('No %s found', 'themify'), $plural )
// merge default options with user submitted options
$options = array_replace_recursive($defaults, $options);
// add the taxonomy to the object array
// this is used to add columns and filters to admin pannel
$this->taxonomies[] = $taxonomy_name;
// create array used when registering taxonomies
$this->taxonomy_settings[$taxonomy_name] = $options;
function register_taxonomies
cycles through taxonomies added with the class and registers them
function is used with add_action
function register_taxonomies() {
if(is_array($this->taxonomy_settings)) {
// foreach taxonomy registered with the post type
foreach($this->taxonomy_settings as $taxonomy_name => $options) {
// register the taxonomy if it doesn't exist
if(!taxonomy_exists($taxonomy_name)) {
// register the taxonomy with Wordpress
register_taxonomy($taxonomy_name, $this->post_type_name, $options);
// if taxonomy exists, attach exisiting taxonomy to post type
register_taxonomy_for_object_type($taxonomy_name, $this->post_type_name);
function add_admin_columns
adds columns to the admin edit screen
function is used with add_action
function add_admin_columns($columns) {
// if no user columns have been specified use following defaults
if(!isset($this->columns)) {
'cb' => '<input type="checkbox" />',
'title' => __('Title', 'themify')
// if there are taxonomies registered to the post type
if(is_array($this->taxonomies)) {
// create a column for each taxonomy
foreach($this->taxonomies as $tax) {
// get the taxonomy object for labels
$taxonomy_object = get_taxonomy($tax);
// column key is the slug, value is friendly name
$columns[$tax] = $taxonomy_object->labels->name;
// if post type supports comments
if(post_type_supports($this->post_type_name, 'comments')) {
$columns['comments'] = '<img alt="Comments" src="'. admin_url() .'images/comment-grey-bubble.png">';
// add date of post to end of columns
$columns['date'] = __('Date', 'themify');
// use user submitted columns
// these are defined using the object columns() method
$columns = $this->columns;
function populate_admin_columns
populates custom columns on the admin edit screen
function is used with add_action
function populate_admin_columns($column, $post_id) {
// get wordpress $post object
// if column is a taxonomy associated with the post type
case (taxonomy_exists($column)) :
// Get the taxonomy for the post
$terms = get_the_terms($post_id, $column);
// Loop through each term, linking to the 'edit posts' page for the specific term.
foreach($terms as $term) {
// output is an array of terms associated with the post
esc_url(add_query_arg(array('post_type' => $post->post_type, $column => $term->slug), 'edit.php')),
// create friendly term name
esc_html(sanitize_term_field('name', $term->name, $term->term_id, $column, 'display'))
// Join the terms, separating them with a comma
echo join(', ', $output);
// get the taxonomy object for labels
$taxonomy_object = get_taxonomy($column);
echo sprintf( __('No %s', 'themify'), $taxonomy_object->labels->name );
// if column is for the post ID
echo esc_attr( $post->ID );
// if the column is prepended with 'meta_'
// this will automagically retrieve the meta values and display them
case (preg_match('/^meta_/', $column) ? true : false) :
// meta_book_author (meta key = book_author)
$meta = get_post_meta($post->ID, $x);
// if the column is post thumbnail
$link = add_query_arg(array('post' => $post->ID, 'action' => 'edit'), 'post.php');
// if it post has a featured image
if(has_post_thumbnail()) {
// display post featured image with edit link
echo '<a href="'. esc_url( $link ) .'">';
the_post_thumbnail(array(60, 60));
// display default media image with link
echo '<a href="'.esc_url( $link ).'"><img src="'. site_url('/wp-includes/images/crystal/default.png') .'" alt="'. $post->post_title .'" /></a>';
// default case checks if the column has a user function
// this is most commonly used for custom fields
// if there are user custom columns to populate
if(isset($this->custom_populate_columns,$this->custom_populate_columns[$column]) && is_array($this->custom_populate_columns) && is_callable($this->custom_populate_columns[$column])) {
//$this->custom_populate_columns[$column]($column, $post);
call_user_func( $this->custom_populate_columns[$column], $column, $post );
user function to define which taxonomy filters to display on the admin page
@param array $filters an array of taxonomy filters to display
function filters($filters = array()) {
$this->filters = $filters;
function add_taxtonomy_filters
creates select fields for filtering posts by taxonomies on admin edit screen
function add_taxonomy_filters() {
// must set this to the post type you want the filter(s) displayed on
if($typenow === $this->post_type_name){
// if custom filters are defined use those
if(is_array($this->filters)) {
$filters = $this->filters;
// else default to use all taxonomies associated with the post
$filters = (array) $this->taxonomies;
// foreach of the taxonomies we want to create filters for
foreach($filters as $tax_slug) {
// object for taxonomy, doesn't contain the terms
$tax = get_taxonomy($tax_slug);
// get taxonomy terms and order by name
$terms = get_terms($args);
printf(' <select name="%s" class="postform">', $tax_slug);
printf('<option value="0">%s</option>', 'Show all ' . $tax->label);
// foreach term create an option field
foreach ($terms as $term) {
// if filtered by this term make it selected
if(isset($_GET[$tax_slug]) && $_GET[$tax_slug] === $term->slug) {
printf('<option value="%s" selected="selected">%s (%s)</option>', $term->slug, $term->name, $term->count);
// create option for taxonomy
printf('<option value="%s">%s (%s)</option>', $term->slug, $term->name, $term->count);
print('</select> ');
user function to choose columns to be displayed on the admin edit screen
@param array $columns an array of columns to be displayed
function columns($columns) {
// assign user submitted columns to object
$this->columns = $columns;
user function to define what and how to populate a specific admin column
@param string $column_name the name of the column to populate
@param func $function an anonymous function to run when populating the column
function populate_column($column_name, $function) {
$this->custom_populate_columns[$column_name] = $function;
user function define what columns are sortable in admin edit screen
@param array $columns an array of the columns that are sortable
function sortable($columns = array()) {
// assign user defined sortable columns to object variable
$this->sortable = $columns;
// run filter to make columns sortable
$this->add_filter('manage_edit-' . $this->post_type_name . '_sortable_columns', array($this, 'make_columns_sortable'));
// run action that sorts columns on request
$this->add_action('load-edit.php', array($this, 'load_edit'));
function make_columns_sortable
internal function that adds any user defined sortable columns to wordpress default columns
function make_columns_sortable($columns) {
// for each sortable column
foreach($this->sortable as $column => $values) {
// make an array to merege into wordpress sortable columns
$sortable_columns[$column] = $values[0];
// merge sortable columns array into wordpress sortable columns
return array_merge($sortable_columns, $columns);
only sort columns on the edit.php page when requested
// run filter to sort columns when requested
$this->add_filter( 'request', array($this, 'sort_columns') );
internal function that sorts columns on request
run by load_edit() filter
@param array $vars the query vars submitted by user
function sort_columns($vars) {
// cycle through all sortable columns submitted by the user
foreach($this->sortable as $values) {
// retrieve the meta key from the user submitted array of sortable columns
// if the optional parameter is set and is set to true
$orderby = isset($values[1]) && true === $values[1]?'meta_value_num':'meta_value';
// Check if we're viewing this post type
if (isset($vars['post_type'],$vars['orderby']) && $meta_key === $vars['orderby'] && $this->post_type_name === $vars['post_type']) {
// merge the query vars with our custom variables
$vars = array_merge($vars,
used to change the menu icon in the admin dashboard
pass name of dashicon, list found here http://melchoyce.github.io/dashicons/
@param mixed $icon a string of the name of the icon to use
function menu_icon($icon = 'dashicons-admin-page') {
// WP 3.8 changed the icon system to use an icon font.
// http://melchoyce.github.io/dashicons/
$this->options['menu_icon'] = is_string($icon) && stripos($icon, 'dashicons') !== FALSE?$icon:'dashicons-admin-page';