This guide will demonstrate how to create a new column type for Admin Columns 3 and Admin Columns Pro 4.
We have a free starter-kit available for creating a column for Admin Columns. This starter-kit contains all the necessary files to create a WordPress plugin 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.
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 Pro
acp-column-COLUMN_NAME.php: Column class with all column logic for Admin Columns Pro 4
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 are 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.