Creating your own columns is easier that you might think. It basically requires just three steps:
And if you’re feeling cheeky you can also change the data of your column as it’s being saved
On this page we’ll look at registering a new column-type. If you’re looking for a cut-and-dry solution you can check out our free starter column
Before we start adding our custom column-type we’ll have to make sure that Sections get’s loaded. We use the cuisine_sections_loaded
hook for this:
add_action( 'cuisine_sections_loaded', function(){
//load your event listeners here
...
});
In our Starter Column we trigger the ColumnIgniter class with the autoloader after this action.
Registering the actual column happens via a regular WordPress filter. It takes an array with three parameters and a key.
Here’s an example:
add_filter( 'cuisine_sections_column_types', function( $types ){
$template = Url::path( 'plugin', 'my-plugin-folder/Assets/template.php' );
//change the $types[ key ] and the name value:
$types['my-column'] = array(
'name' => 'My Custom Column',
'class' => 'MyColumn\Column',
'template' => $template
);
return $types;
});
Let’s break that down:
First we use the cuisine_sections_column_types filter to add a new value to the column $types array.
Inside the filter we use a utility class in Cuisine Core to fetch the path of our plugin folder. After that we add a my-column key to the $types array, with a name, class and template value for our column.