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

/**
 * Register Portfolio CPT and Taxonomy with Dynamic Slug
 */
if ( Sifency_Addons_Theme_Builder_Master::sifency_addons_is_legal() ) {
final class Sifency_CPT_Portfolio {

	/**
	 * Init hooks
	 */
	public function __construct() {
		if ( class_exists( 'Sifency_Addons_Theme_Builder_Master' ) 
			&& Sifency_Addons_Theme_Builder_Master::sifency_addons_is_legal() 
		) {
			add_action( 'init', [ $this, 'register_post_type' ] );
		}
	}

	/**
	 * Register Portfolio Post Type
	 */
	public function register_post_type() {
		$options = get_option( 'sifency-options', [] );

		$slug = ! empty( $options['portfolio_slug'] )
			? sanitize_title( $options['portfolio_slug'] )
			: 'portfolio';

		$labels = [
			'name'               => __( 'Portfolio', 'sifency-addons' ),
			'singular_name'      => __( 'Portfolio', 'sifency-addons' ),
			'add_new'            => __( 'Add New', 'sifency-addons' ),
			'add_new_item'       => __( 'Add New Portfolio', 'sifency-addons' ),
			'edit_item'          => __( 'Edit Portfolio', 'sifency-addons' ),
			'new_item'           => __( 'New Portfolio', 'sifency-addons' ),
			'view_item'          => __( 'View Portfolio', 'sifency-addons' ),
			'search_items'       => __( 'Search Portfolios', 'sifency-addons' ),
			'not_found'          => __( 'No portfolio found', 'sifency-addons' ),
			'not_found_in_trash' => __( 'No portfolio found in trash', 'sifency-addons' ),
			'menu_name'          => __( 'Portfolio', 'sifency-addons' ),
		];

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

		register_post_type( 'portfolio', $args );

		$this->register_taxonomy();
	}

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

		$labels = [
			'name'          => __( 'Portfolio Categories', 'sifency-addons' ),
			'singular_name' => __( 'Portfolio Category', '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' ),
			'new_item_name' => __( 'New Category Name', 'sifency-addons' ),
			'menu_name'     => __( 'Categories', 'sifency-addons' ),
		];

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

		register_taxonomy( 'portfolio_category', [ 'portfolio' ], $args );
	}
}
new Sifency_CPT_Portfolio();
}