Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codehooligans/343f759f3e1e4e8127c9 to your computer and use it in GitHub Desktop.
Save codehooligans/343f759f3e1e4e8127c9 to your computer and use it in GitHub Desktop.
Codehooligans.com: Adding Taxonomy Column Headers
<?php
add_action( 'init', 'product_init' );
function product_init()
{
register_taxonomy( 'product_packages', 'products',
array( 'hierarchical' => true,
'label' => __('Product Packages'),
'query_var' => false
)
);
// Added from Part II.
// This filter sets up a call to your function which will handle
// adding (and removing) items from the columns array. This
// filter passes up only one argument. The array of default headers.
add_filter( 'manage_product_packages_columns',
'admin_product_packages_column_headers, 10, 1);
}
// Add this to your code's init function. This filter passes up
// only one argument. The array of default headers.
add_filter( 'manage_product_packages_columns',
'admin_product_packages_column_headers, 10, 1);
// Add this function somewhere else in your plugin or functions file.
function admin_product_packages_column_headers($columns)
{
// We are going to create a new array to hold the headers.
// Below we take the checkbox column and the name column
// and add to the new column array. Removing unwanted columns
// and adding new one is trivial. The below method has
// room form much improvement.
$columns_local = array();
if (isset($columns['cb']))
{
$columns_local['cb'] = $columns['cb'];
unset($columns['cb']);
}
if (isset($columns['name']))
{
$columns_local['name'] = $columns['name'];
unset($columns['name']);
}
// We add the Package Active to the second column
if (!isset($columns_local['product_package_active']))
$columns_local['product_package_active'] = "Active";
if (isset($columns['posts']))
$columns['posts'] = "Used";
$columns_local = array_merge($columns_local, $columns);
if (!isset($columns_local['product_package_unit_price']))
$columns_local['product_package_unit_price'] = "Price";
return array_merge($columns_local, $columns);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment