quick_edit_custom_box
Fires for each column in a list table (posts or terms) in Quick Edit mode.
Usage
add_action( 'quick_edit_custom_box', 'wp_kama_quick_edit_custom_box_action', 10, 3 );
/**
* Function for `quick_edit_custom_box` action-hook.
*
* @param string $column_name Name of the column to edit.
* @param string $post_type The post type slug, or current screen name if this is a taxonomy list table.
* @param string $taxonomy The taxonomy name, if any.
*
* @return void
*/
function wp_kama_quick_edit_custom_box_action( $column_name, $post_type, $taxonomy ){
// action...
}
- $column_name(string)
- Column name (key).
- $post_type(string)
- Post type slug, or the current screen name for a taxonomy list table.
- $taxonomy(string)
- Taxonomy name or another value.
Examples
#1 A Views field in Quick Edit
This example adds a Views column and a corresponding field to the post Quick Edit panel.
<?php
add_filter( 'manage_post_posts_columns', function ( $columns ) {
$my_columns = [
'views' => 'Views',
];
return $columns + $my_columns;
} );
add_action( 'manage_post_posts_custom_column', function ( $column_name ) {
if ( $column_name === 'views' ) {
echo (int) get_post_meta( get_the_ID(), 'views', true );
}
} );
add_action( 'quick_edit_custom_box', 'display_custom_quickedit_book', 10, 2 );
function display_custom_quickedit_book( $column_name, $post_type ) {
if ( 'views' === $column_name && 'post' === $post_type ): ?>
<fieldset class="inline-edit-col-right">
<div class="inline-edit-col">
<div class="inline-edit-group wp-clearfix">
<label class="inline-edit-group">
<?php
if ( $column_name === 'views' ) {
$views = (int) get_post_meta( get_the_ID(), 'views', true );
?>
<span class="title">Views</span>
<input type="number" name="views" value="<?php echo $views; ?>"/>
<?php
}
?>
</label>
</div>
</div>
</fieldset>
<?php endif;
}
add_action( 'save_post', 'save_views_meta', 10, 2 );
function save_views_meta( $post_id, $post ) {
// Do not handle autosaves.
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return $post_id;
}
// Do not handle post types other than post or users without edit permission.
if ( 'post' !== $post->post_type || ! current_user_can( 'edit_post', $post_id ) ) {
return $post_id;
}
// Verify the security token.
if ( ! isset( $_REQUEST['_inline_edit'] ) || ! wp_verify_nonce( $_REQUEST['_inline_edit'], 'inlineeditnonce' ) ) {
return $post_id;
}
// Update the field.
if ( isset( $_POST['views'] ) ) {
update_post_meta( $post_id, 'views', (int) $_POST['views'] );
}
return $post_id;
}Changelog
| Since 2.7.0 | Introduced. |
Where the hook is called
quick_edit_custom_box
quick_edit_custom_box
wp-admin/includes/class-wp-posts-list-table.php 2204
do_action( 'quick_edit_custom_box', $column_name, $screen->post_type, '' );
wp-admin/includes/class-wp-terms-list-table.php 722
do_action( 'quick_edit_custom_box', $column_name, 'edit-tags', $this->screen->taxonomy );
