How to create my own custom column
This guide will demonstrate how to create a new column type for Admin Columns Pro.
Download
We have a free starter-kit available for creating a column for Admin Columns. This starter kit contains all the necessary files to create your own custom column and is heavily commented so you can build your column quickly and confidently.
Please download a copy of this starter-kit here: https://github.com/codepress/ac-column-template. (Click the Download Zip button )
After the starter-kit has downloaded, please extract the .zip file and move the folder called ac-column-template-master to your wp-content/plugins directory.
Structure
The starter kit contains the following files and folders. Here is a brief explanation of each:
/ac-column-template.php: Main plugin file that registers the column/classes/Column/Column.php: Column class with all column logic/classes/Column/Editing.php: Editing Model with all editing-related logic/classes/Colum/Export.php: Export Model with all export-related logic/classes/Column/Search.php: Smart Filtering logic with all filtering-related logic/classes/Column/Sorting.php: Sorting Model with all sorting-related logic/readme.txt: WordPress readme file to be used by the WordPress repository
Setup
This starter-kit uses two placeholders throughout the file names and code. Use the following list of placeholders to do a ‘find and replace’:
COLUMN_NAME: Single-word, no spaces. Underscores allowed. eg. my_columnCOLUMN_LABEL: Multiple words, can include spaces, visible when selecting a column
That’s it, your column type plugin is ready for testing! Please login to your WP website and activate the ac-column-template plugin. With the plugin activated, you will now see a new column type available when creating a new column in the Admin Columns plugin.
Hook Example
The starter-kit template will register the column for you. The hook used to register your column to Admin Columns looks something like this:
Custom Column class example
Value formatter class example. This class renders the column value on the list table.