cac/columns/custom

Deprecated This documentation is deprecated since Admin Columns version 4.
Please view the updated version of this documentation here.

With this filter you can create your own column type. If you like to create a column yourself, read our detailed instructions¬†on how to “create a new column type“.

Usage

/**
 * Filter cac/columns/custom
 * 
 * @param $columns array Contains list of columns with their classnames and full filepath
 * @param $storage_model object Contains all properties for the stored content type
 * @return $columns array List of columns
 */
function my_cac_custom_column( $columns, $storage_model ) {

    // classname of your column
    $classname  = 'My_Column_Class';

    // filepath of your column class ( inside a theme )
    $filepath   = get_stylesheet_directory() . '/class-my-column-class.php';

    // filepath of your column class ( inside a plugin )
    $filepath   = plugin_dir_path( __FILE__ ) . '/class-my-column-class.php';

    // do not change.
    $columns[ $classname ] = $filepath;

    return $columns;
}

// cac/columns/custom - filter to register column
add_filter( 'cac/columns/custom', 'my_cac_custom_column', 10, 2 );

// cac/columns/custom/post_type={$post_type} - filter to register column based on it's posttype
add_filter( 'cac/columns/custom/post_type=page', 'my_cac_custom_column', 10, 2 );

// cac/columns/custom/type={$type} - filter to register column based on it's content META type
// type can be either a post, user, comment, link or media
add_filter( 'cac/columns/custom/type=comment', 'my_cac_custom_column', 10, 2 );

Example

There is a starter-kit available to easily start creating a new column type.