Overview

If you have created your own column you will be able to add editable functionality to them very easily. Admin Columns has an easy to use API you can use to add the editable functionality to any column. This article will explain step-by-step how to use these filters and contains a full working example.

Plugin Developers

We encourage plugin developers to add editable column support to their plugins. Your users will love it. They will be able to quickly edit your plugin’s column content without opening each post(type), user or media. We made a very easy to use API which will let you add this in minutes. You just need to add 4 filters and you are set. Below you will find a tutorial and an working example for a SEO Title column.

With these 4 filters you will be able to add editability to any existing column.

  1. Register your column to be editable.
    // Register a column to be editable.
    add_filter( 'cac/editable/is_column_editable/column=COLUMN_NAME', '__return_true' );
  2. Set the editable settings.
    In this example we register the column as an editable text field.
    // Set the editable properties
    function my_plugin_column_editable_settings( $editable_data, $model ) {
    	$editable_data['COLUMN_NAME']['default_column'] = true; // Do not change this
    
    	// Set the editability type.
    	$editable_data['COLUMN_NAME']['type'] = 'text'; // Accepts 'text', 'select', 'textarea', 'media', 'float', 'togglable', 'select' and more.
    
    	return $editable_data;
    }
    add_filter( 'cac/editable/editables_data', 'my_plugin_column_editable_settings', 10, 2 );
  3. Retrieve the value that should be used for editing
    // Retrieve the value that will be used for editing
    function my_plugin_column_value( $value, $column, $id, $model ) {
    
    	// Retrieve the value that should be used for editing
    	// For example: $value = get_post_meta( $post_id, '_my_custom_field_example', true );
    	return $value;
    }
    add_filter( 'cac/editable/column_value/column=COLUMN_NAME', 'my_plugin_column_value', 10, 4 );
  4. Store the value that has been entered with inline-edit to the database
    <?php
    // Store the editable column value to the database
    function my_plugin_column_save( $result, $column, $id, $value, $model ) {
    
    	// Store the value that has been entered with inline-edit
    	// For example: update_post_meta( $id, '_my_custom_field_example', $value );
    }
    add_filter( 'cac/editable/column_save/column=COLUMN_NAME', 'my_plugin_column_save', 10, 5 );
  5. That’s it! Your column is editable now 🙂

Example

SEO Title column

Full working example for the SEO Title column ( WordPress SEO by Yoast ).

// Register the Title SEO ( WordPress SEO by Yoast ) as editable
add_filter( 'cac/editable/is_column_editable/column=wpseo-title', '__return_true' );

// Get the value for Title SEO column ( WordPress SEO by Yoast )
function my_cac_get_editable_column_value_seo_title( $value, $column, $id, $model ) {
	return get_post_meta( $id, '_yoast_wpseo_title', true );
}
add_filter( 'cac/editable/column_value/column=wpseo-title', 'my_cac_get_editable_column_value_seo_title', 10, 4 );

// Save the value for Title SEO column ( WordPress SEO by Yoast )
function my_cac_save_column_value_seo_title( $result, $column, $id, $value, $model ) {
	update_post_meta( $id, '_yoast_wpseo_title', $value );
}
add_filter( 'cac/editable/column_save/column=wpseo-title', 'my_cac_save_column_value_seo_title', 10, 5 );

// Editable settings for the Title SEO column ( WordPress SEO by Yoast )
function my_cac_editable_column_settings_seo_title( $editable_data, $model ) {
	$editable_data['wpseo-title'] = array(
		'default_column' => true,
		'type' => 'text',
		'placeholder' => __( 'Enter new SEO Title', 'cac-post_seo_title' )
	);
	return $editable_data;
}
add_filter( 'cac/editable/editables_data', 'my_cac_editable_column_settings_seo_title', 10, 2 );

The SEO columns will have an edit icon…

wordpress_seo_editable_settings

..and are now editable!

wordpress_seo_title_editable_column

Download

We have a free starter-kit available for making a column editable for Admin Columns. This starter-kit contains all the necessary files to create a WP plugin and is heavily commented. Please download a copy of this starter-kit here: https://github.com/codepress/ac-editable-template. (Click the Download Zip button )

After the starter-kit has downloaded, please extract the .zip file and move the folder called ac-editable-template-master to your wp-content/plugins directory.

Used Filters

You can learn more about each filter and it’s properties.

 Share

If you think your editable column can benefits other, please be sure to post a thread on the Forum for a chance to be added to the site.