1.1 – Versioning System

Custom Post Type Version
Per registrare l’avanzamento del tema ho creato un custom post type denominato version tramite funzione inserita nel file functions.php del tema child:

// Registra Custom Post Type
function version_cpt() {
	$labels = array(
		'name'                  => _x( 'Versioni', 'Post Type General Name', '_incubationchild' ),
		'singular_name'         => _x( 'Versione', 'Post Type Singular Name', '_incubationchild' ),
		'menu_name'             => __( 'Versioni', '_incubationchild' ),
		'name_admin_bar'        => __( 'Versione', '_incubationchild' ),
		'archives'              => __( 'Archivio versioni', '_incubationchild' ),
		'attributes'            => __( 'Attributi versione', '_incubationchild' ),
		'parent_item_colon'     => __( 'Versione genitore:', '_incubationchild' ),
		'all_items'             => __( 'Tutte le versioni', '_incubationchild' ),
		'add_new_item'          => __( 'Aggiungi nuova versione', '_incubationchild' ),
		'add_new'               => __( 'Aggiungi nuovo', '_incubationchild' ),
		'new_item'              => __( 'Nuova versione', '_incubationchild' ),
		'edit_item'             => __( 'Modifica versione', '_incubationchild' ),
		'update_item'           => __( 'Aggiorna versione', '_incubationchild' ),
		'view_item'             => __( 'Visualizza versione', '_incubationchild' ),
		'view_items'            => __( 'Visualizza versioni', '_incubationchild' ),
		'search_items'          => __( 'Cerca versione', '_incubationchild' ),
		'not_found'             => __( 'Nessuna versione trovata', '_incubationchild' ),
		'not_found_in_trash'    => __( 'Nessuna versione trovata nel cestino', '_incubationchild' ),
		'featured_image'        => __( 'Featured Image', '_incubationchild' ),
		'set_featured_image'    => __( 'Imposta featured image', '_incubationchild' ),
		'remove_featured_image' => __( 'Rimuovi featured image', '_incubationchild' ),
		'use_featured_image'    => __( 'Usa come featured image', '_incubationchild' ),
		'insert_into_item'      => __( 'Inserisci nella versione', '_incubationchild' ),
		'uploaded_to_this_item' => __( 'Aggiorna in questa versione', '_incubationchild' ),
		'items_list'            => __( 'Lista versioni', '_incubationchild' ),
		'items_list_navigation' => __( 'Naviga tra le versioniItems list navigation', '_incubationchild' ),
		'filter_items_list'     => __( 'Filtra la lista versioni', '_incubationchild' ),
	);
	$args = array(
		'label'                 => __( 'Versione', '_incubationchild' ),
		'description'           => __( 'Descrizione aggiornamento del tema', '_incubationchild' ),
		'labels'                => $labels,
		'supports'              => array( 'title', 'editor', 'revisions' ),
		'taxonomies'            => array( 'category', 'post_tag' ),
		'hierarchical'          => false,
		'public'                => true,
		'show_ui'               => true,
		'show_in_menu'          => true,
		'menu_position'         => 5,
		'menu_icon'             => 'dashicons-hammer',
		'show_in_admin_bar'     => true,
		'show_in_nav_menus'     => true,
		'can_export'            => true,
		'has_archive'           => true,
		'exclude_from_search'   => true,
		'publicly_queryable'    => true,
		'capability_type'       => 'post',
		'show_in_rest'          => true,
	);
	register_post_type( 'version', $args );
}
add_action( 'init', 'version_cpt', 0 );

Per consentire la visualizzazione degli stessi ho creato un template di pagina che visualizza i custom post type version (page-version.php):

<?php
/**
 * Template Name: Archivio Versioni
 *
 * Template per la visualizzazione della pagina con l'elenco dei cambi versione
 *
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package _incubationchild
 */
get_header();
?>
        <main id="primary" class="site-main col-12 col-md-8">
        <?php the_breadcrumb(); ?>
        <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                <header class="entry-header">
                    <?php the_title( '<h1 class="entry-title">', '</h1>' ); ?>
                </header><!-- .entry-header -->
                <?php _incubation_post_thumbnail(); ?>
                <div class="entry-content">
            <?php
            the_content();
                $loop = new WP_Query( array( 'post_type' => 'version', 'paged' => $paged ) );
                if ( $loop->have_posts() ) :
            while ( $loop->have_posts() ) :
                $loop->the_post();
                get_template_part( 'template-parts/content', 'archiveversion' );
                // If comments are open or we have at least one comment, load up the comment template.
                if ( comments_open() || get_comments_number() ) :
                    comments_template();
                endif;
            endwhile; // End of the loop.
        endif;
        wp_reset_postdata();
            ?>
                </div><!-- .entry-content -->
<?php if ( get_edit_post_link() ) : ?>
    <footer class="entry-footer">
        <?php
        edit_post_link(
            sprintf(
                wp_kses(
                    /* translators: %s: Name of current post. Only visible to screen readers */
                    __( 'Edit <span class="screen-reader-text">%s</span>', '_incubation' ),
                    array(
                        'span' => array(
                            'class' => array(),
                        ),
                    )
                ),
                wp_kses_post( get_the_title() )
            ),
            '<span class="edit-link">',
            '</span>'
        );
        ?>
    </footer><!-- .entry-footer -->
<?php endif; ?>
</article><!-- #post-<?php the_ID(); ?> -->
        </main><!-- #main -->
<?php
get_sidebar();
get_footer();

Per consentire un indice migliore ho ridotto la visualizzazione al solo titolo di ogni aggiornamento versione creando, all’interno della cartella template-parts del child il file content-archiveversion.php.

<?php
/**
 * Parte di template per la visualizzazione dei post Version nella pagina archivio
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package _incubationchild
 */
?>
            <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
                <header class="entry-header">
                    <?php
                        the_title( '<h2 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h2>' );
                    if ( 'post' === get_post_type() ) :
                        ?>
                        <div class="entry-meta">
                            <?php
                            _incubation_posted_on();
                            _incubation_posted_by();
                            ?>
                        </div><!-- .entry-meta -->
                    <?php endif; ?>
                </header><!-- .entry-header -->
                <?php _incubation_post_thumbnail(); ?>
                <div class="entry-content">
                    <?php
                    ?>
                </div><!-- .entry-content -->
                <footer class="entry-footer">
                    <?php  _incubation_entry_footer(); ?>
                </footer><!-- .entry-footer -->
            </article><!-- #post-<?php the_ID(); ?> -->