Undefined variable post_id in custom quick edit coloumn

I can see the data here (last coloumn)

I am trying to add a custom coloumn to post quick edit and everything is almost working. Custom meta is saved and passed but if I click on quick edit the preview is blank.
This is the error it gives me: Notice: Undefined variable: post_id in /home/etimueit/public_html/wp-content/themes/caru/functions.php on line 626

Here is my code.

function disponibilitaet_quickedit_custom_posts_columns( $posts_columns ) {
$posts_columns['disponibilitaet_edit_time'] = __( 'Modifica Disponibilità', 'disponibilitaet' );
return $posts_columns;
}
add_filter( 'manage_post_posts_columns', 'disponibilitaet_quickedit_custom_posts_columns' );

function disponibilitaet_quickedit_custom_column_display( $column_name, $post_id ) {
    if ( 'disponibilitaet_edit_time' == $column_name ) {
        $dispo_registrata = get_post_meta( $post_id, 'disponibilitaet_edit_time', true );

        if ( $dispo_registrata ) {
            echo esc_html( $dispo_registrata );
        } else {
            esc_html_e( 'N/A', 'disponibilitaet' );
        }
    }
}
add_action( 'manage_post_posts_custom_column', 'disponibilitaet_quickedit_custom_column_display', 10, 2 );

function disponibilitaet_quickedit_fields( $column_name, $post_type ) {
    if ( 'disponibilitaet_edit_time' != $column_name )
        return;`

//This is line 626

    $dispo_registrata = get_post_meta( $post_id, 'disponibilitaet_edit_time', true );
    ?>
    <fieldset class="inline-edit-col-right">
        <div class="inline-edit-col">
            <label>
                <span class="title"><?php esc_html_e( 'Disponibilit&agrave;', 'disponibilitaet' ); ?></span>
                <span class="input-text-wrap">
                <input type="text" name="disponibilitaet_edit_time" class="disponibilitaetedittime" value="<?php echo $dispo_registrata;?>">
            </span>
            </label>
        </div>
    </fieldset>
    <?php
}
add_action( 'quick_edit_custom_box', 'disponibilitaet_quickedit_fields', 10, 2 );
function disponibilitaet_quickedit_save_post( $post_id, $post ) {
    // if called by autosave, then bail here
    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
        return;

    // if this "post" post type?
    if ( $post->post_type != 'post' )
        return;

    // does this user have permissions?
    if ( ! current_user_can( 'edit_post', $post_id ) )
        return;

    // update!
    if ( isset( $_POST['disponibilitaet_edit_time'] ) ) {
        update_post_meta( $post_id, 'disponibilitaet_edit_time', $_POST['disponibilitaet_edit_time'] );
    }
}
add_action( 'save_post', 'disponibilitaet_quickedit_save_post', 10, 2 );

function disponibilitaet_quickedit_javascript() {
    $current_screen = get_current_screen();
    if ( $current_screen->id != 'edit-post' || $current_screen->post_type != 'post' )
        return;

    // Ensure jQuery library loads
    wp_enqueue_script( 'jquery' );
    ?>
    <script type="text/javascript">
        jQuery( function( $ ) {
            $( '#the-list' ).on( 'click', 'a.editinline', function( e ) {
                e.preventDefault();
                var editTime = $(this).data( 'edit-time' );
                inlineEditPost.revert();
                $( '.disponibilitaetedittime' ).val( editTime ? editTime : '' );
            });
        });
    </script>
    <?php
}
add_action( 'admin_print_footer_scripts-edit.php', 'disponibilitaet_quickedit_javascript' );

Read more here:: Undefined variable post_id in custom quick edit coloumn

Leave a Reply

Your email address will not be published. Required fields are marked *