/** * Add "dimofiles" custom field in quick edit */ function add_dimofili_post_column( $columns, $post_type ) { switch ( $post_type ) { case 'post': $new_columns = array(); foreach( $columns as $key => $value ) { $new_columns[ $key ] = $value; if ( $key == 'title' ) $new_columns[ 'dimofiles' ] = 'Δημοφιλές άρθρο'; } return $new_columns; } return $columns; } /** * Add "grafei" custom field in quick edit */ function add_grafei_post_column( $columns, $post_type ) { switch ( $post_type ) { case 'post': $new_columns = array(); foreach( $columns as $key => $value ) { $new_columns[ $key ] = $value; if ( $key == 'dimofiles' ) $new_columns[ 'grafei' ] = 'Γράφει'; } return $new_columns; } return $columns; } add_filter( 'manage_posts_columns', 'add_dimofili_post_column', 10, 2 ); add_filter( 'manage_posts_columns', 'add_grafei_post_column', 10, 2 ); /** * Add custom fields data in each column post */ function custom_fields_populate_post_column_data( $column_name, $post_id ) { switch( $column_name ) { case 'dimofiles': $dimofiles = get_post_meta($post_id, 'dimofiles',true); $icon_yes = ($dimofiles == 1 ? '<span class="dashicons dashicons-yes"></span>' : '' ); echo '<div id="dimofiles-' . $post_id . '" style="display: none; ">' . $dimofiles . '</div>'; echo '<div style="text-align: center; ">' . $icon_yes. '</div>'; break; case 'grafei': echo '<div id="grafei-' . $post_id . '" style="">' . get_post_meta($post_id, 'grafei',true) . '</div>'; break; } } add_action( 'manage_posts_custom_column', 'custom_fields_populate_post_column_data', 10, 2 ); /** * Add custom fields in quick edit */ function add_custom_fields_to_bulk_quick_edit_custom_box( $column_name, $post_type ) { switch ( $post_type ) { case 'post': switch( $column_name ) { case 'dimofiles': ?> <fieldset class="inline-edit-col-right"> <div class="inline-edit-group"> <label> <span class="title">Δημοφιλές άρθρο</span> <input type="checkbox" name="dimofiles" /> </label> </div> </fieldset> <?php break; case 'grafei': ?> <fieldset class="inline-edit-col-right"> <div class="inline-edit-group"> <label> <span class="title">Γράφει</span> <input type="text" name="grafei" value="" size="50"/> </label> </div> </fieldset><?php break; } break; } } add_action( 'bulk_edit_custom_box', 'add_custom_fields_to_bulk_quick_edit_custom_box', 10, 2 ); add_action( 'quick_edit_custom_box', 'add_custom_fields_to_bulk_quick_edit_custom_box', 10, 2 ); /** * Enqueue file /child-theme/assets/js/quick_edit.js */ function enqueue_custom_fields_edit_scripts() { wp_enqueue_script( 'dimofiles-admin-edit', get_stylesheet_directory_uri() . '/assets/js/quick_edit.js', array( 'jquery', 'inline-edit-post' ), '', true ); } add_action( 'admin_print_scripts-edit.php', 'enqueue_custom_fields_edit_scripts' ); /** * Save custom fields values in quick data */ function save_custom_fields_post( $post_id, $post ) { // don't save for autosave if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return $post_id; // dont save for revisions if ( isset( $post->post_type ) && $post->post_type == 'revision' ) return $post_id; switch( $post->post_type ) { case 'post': if(isset($_POST['dimofiles'])) { update_post_meta( $post_id, 'dimofiles', 1 ); } else { update_post_meta( $post_id, 'dimofiles', 0 ); } if(isset($_POST['grafei'])) { update_post_meta( $post_id, 'grafei', $_POST['grafei'] ); } else { update_post_meta( $post_id, 'grafei', '' ); } break; } } add_action( 'save_post','save_custom_fields_post', 1 , 2);