How to create my own column?
This guide will demonstrate how to create a new column type for Admin Columns Pro.
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.
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.
The starter-kit contains the following files and folders. Here is a brief explanation of each:
/css: folder for .css files
/js:folder for .js files
/languages: folder for .pot, .po and .mo files
ac-COLUMN_NAME.php: Main plugin file that registers the column
ac-column-COLUMN_NAME.php: Column class with all column logic for both the free and PRO version of Admin Columns
acp-column-COLUMN_NAME.php: Column class with all column logic for the PRO version of Admin Columns
readme.txt: WordPress readme file to be used by the wordpress repository
This starter-kit uses
PLACEHOLDERS such as
COLUMN_NAME 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_column
COLUMN_LABEL: Multiple words, can include spaces, visible when selecting a column
PLUGIN_URL: Url to the github or WordPress repository
PLUGIN_TAGS: Comma seperated list of relevant tags
DESCRIPTION: Brief description of the field type, no longer than 2 lines
EXTENDED_DESCRIPTION: Extended description of the field type
AUTHOR_NAME: Name of field type author
AUTHOR_URL: URL to author’s website
ac-COLUMN_NAME.php file (now renamed using your column name) and change the column type if necessary.
ac-column-COLUMN_NAME.php file (now renamed using your column name) and include your custom code in the appropriate functions.
That’s it, your column type plugin is ready for testing! Please login to your WP website and activate the ac-COLUMN_NAME plugin. With the plugin activated, you will now see a new column type available when creating a new column in the Admin Columns plugin.
Once you created and activated your new
AC/Column column, it’s time to customize the functionality.
ac-column-COLUMN_NAME.php file has a couple of functions. Each of them is documented with internal comments, so please read them from the file
Here is a quick overview of the functions:
__construct: Set the the properties of the column, such as type, label or group
get_value: Returns the display value for the column.
get_raw_value: Returns the raw value for the column, used for sorting and editing.
is_valid: (Optional) This determines whether the column should be available for a specific type, like a post or a page.
register_settings: (Optional) Create extra settings for your column. These are visible when editing a column.
Please read over the extended comments found above each function to learn more.
Make your column Pro
Features like filtering, sorting and inline edit is only available for the pro version of Admin Columns Pro. The
acp-column-COLUMN_NAME.php file contains an implementation on how to make the column sortable and editable. You’ll need to implement an Editing and Sorting interface in your column class and create the associated models. This will allow you to enable sorting or editing in your column settings.