<?php
if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

if ( Sifency_Addons_Theme_Builder_Master::sifency_addons_is_legal() ) {

final class Sifency_CPT_Digital_Goods {

    private $option_key = 'sifency-options';
    private $post_type  = 'digital';
    private $taxonomy   = 'digital_category';

    public function __construct() {
        add_action( 'init', [ $this, 'register_all' ] );
    }

    /**
     * Register CPT + Taxonomy
     */
    public function register_all() {
        $this->register_post_type();
        $this->register_taxonomy();
    }

    /**
     * Register Post Type
     */
    private function register_post_type() {

        $options = get_option( $this->option_key, [] );
        $slug    = ! empty( $options['digital_slug'] )
            ? sanitize_title( $options['digital_slug'] )
            : 'digital';

        $labels = [
            'name'               => __( 'Digital Goods', 'sifency-addons' ),
            'singular_name'      => __( 'Digital Good', 'sifency-addons' ),
            'menu_name'          => __( 'Digital Goods', 'sifency-addons' ),
            'add_new'            => __( 'Add New', 'sifency-addons' ),
            'add_new_item'       => __( 'Add New Digital Good', 'sifency-addons' ),
            'edit_item'          => __( 'Edit Digital Good', 'sifency-addons' ),
            'new_item'           => __( 'New Digital Good', 'sifency-addons' ),
            'view_item'          => __( 'View Digital Good', 'sifency-addons' ),
            'search_items'       => __( 'Search Digital Goods', 'sifency-addons' ),
            'not_found'          => __( 'No digital goods found.', 'sifency-addons' ),
            'not_found_in_trash' => __( 'No digital goods found in Trash.', 'sifency-addons' ),
        ];

        $args = [
            'labels'        => $labels,
            'public'        => true,
            'has_archive'   => true,
            'menu_icon'     => 'dashicons-media-archive',
            'show_in_rest'  => true,
            'supports'      => [ 'title', 'editor', 'thumbnail', 'excerpt', 'revisions' ],
            'rewrite'       => [
                'slug'       => $slug,
                'with_front' => false,
            ],
        ];

        register_post_type( $this->post_type, $args );
    }

    /**
     * Register Taxonomy
     */
    private function register_taxonomy() {

        $labels = [
            'name'          => __( 'Digital Categories', 'sifency-addons' ),
            'singular_name' => __( 'Digital Category', 'sifency-addons' ),
            'menu_name'     => __( 'Categories', 'sifency-addons' ),
            'search_items'  => __( 'Search Categories', 'sifency-addons' ),
            'all_items'     => __( 'All Categories', 'sifency-addons' ),
            'edit_item'     => __( 'Edit Category', 'sifency-addons' ),
            'update_item'   => __( 'Update Category', 'sifency-addons' ),
            'add_new_item'  => __( 'Add New Category', 'sifency-addons' ),
        ];

        $args = [
            'hierarchical'      => true,
            'labels'            => $labels,
            'show_ui'           => true,
            'show_admin_column' => true,
            'show_in_rest'      => true,
            'rewrite'           => [
                'slug'         => 'digital-category',
                'with_front'   => false,
            ],
        ];

        register_taxonomy( $this->taxonomy, [ $this->post_type ], $args );
    }
}

new Sifency_CPT_Digital_Goods();
}
