How can I extend Quick Edit option with 2 more fields

A small example from my last project. The important part is the hook quick_edit_custom_box. On this hook can you add your form elements.
The second important part is to add your script that update the data via javascript. The script in this example was add to the head in edit.php; it is better on footer and you must check the right page.

The example source below is inside a class, please note this.

add_action( 'quick_edit_custom_box', array( $this, 'add_quick_edit' ), 10, 2 );
add_action( 'admin_head-edit.php',   array( $this, 'quick_add_script' ) );

/**
 * Add data to quick edit on list post and page
 * 
 * @since   0.0.1
 * @access  public
 * @uses    wp_nonce_field, plugin_basename, get_plw123mh_hosts, esc_url_raw, _e
 * @param   string array $column_name
 * @param   string $post_type
 * @return  string
 */
public function add_quick_edit ( $column_name, $post_type ) {

    if ( 'multihosts' != $column_name )
        return;

    // Use nonce for verification
    wp_nonce_field( plugin_basename( __FILE__ ), self :: get_textdomain() . '_nonce' );

    $hostlist = $this -> get_plw123mh_hosts();

    $checkboxes="";
    while( list($key, $val) = each($hostlist) ) {
        if( '' != $val ) {
            $val_e  = esc_url_raw($val);
            $val="_" . str_replace( '.', '_', trim( strtolower($val_e) ) );
            /*
            $data   = get_post_meta( $post->ID, $val , TRUE );

            if ( 1 == $data || '' === $data )
                $checked = ' checked="checked"';
            else 
            */
                $checked = '';

            $checkboxes .= '<label class="alignleft"><input type="checkbox" id="' 
            . $val . '_check" name="' . $val 
            . '" value="1"' . $checked . '/><span class="checkbox-title"> ' . $val_e . '</span></label>' . "\n";
        }
    }

    ?>
    <fieldset class="inline-edit-col-left">
        <div class="inline-edit-col">
            <span class="title"><?php _e( 'Multihosts', self :: get_textdomain() ); ?></span>
            <div class="inline-edit-group">
    <?php
    echo $checkboxes;
    ?>
            </div>
        </div>
    </fieldset>
    <?php
}

    public function quick_add_script () {
    ?>
    <script type="text/javascript">
    jQuery(document).ready(function($) {
        $('a.editinline').live('click', function() {
            var id = inlineEditPost.getId(this);
            var val = parseInt( $('#inline_' + id + '_http://localhost').text() );
            $('#_http://localhost_check').attr('checked', !!val);
        });
    });
    </script>
    <?php
}

see also this answer WPSE 7291 for a example.
Also more hints inlcude bulk in this answer WPSE 3316.

Last hint: You can also save the data via hook `edit_post’. Also a small example, write from scratch.

add_action( 'edit_post', array( $this, 'quick_edit_save' ), 10, 3 );
function ilc_quickedit_save($post_id, $post) {

    if ( $post->post_type !== 'event' )
        return;

    if ( isset( $_POST['is_quickedit'] ) )
        update_post_meta( $post_id, 'eventdate', esc_attr( $_POST['eventdate'] ) );
}

Leave a Comment

tech