<?php 
/*
Plugin Name:  Netto Theme Addons
Plugin URI:   https://awaikenthemes.com
Description:  This plugin is intended for use with the netto theme.
Version:      1.0.0
Author:       Awaiken Technology
Author URI:   https://awaiken.com
License:      GPL2
License URI:  https://www.gnu.org/licenses/gpl-2.0.html
Text Domain:  netto-themes-addons
Domain Path:  /languages
*/

define( 'NETTO_ADDONS_URL', plugins_url( '/', __FILE__ ) );
define( 'NETTO_ADDONS_PATH', plugin_dir_path( __FILE__ ) );


// Load translation.
add_action( 'init', 'netto_i18n' );

/**
 * Load the plugin text domain for translation.
 *
 * @since    1.0.0
 */
function netto_i18n() {
	load_plugin_textdomain( 'netto-themes-addons' );
}

/* Allow SVG upload */
add_filter( 'wp_check_filetype_and_ext', function( $data, $file, $filename, $mimes ) {

  $filetype = wp_check_filetype( $filename, $mimes );

  return [
      'ext' => $filetype['ext'],
      'type' => $filetype['type'],
      'proper_filename' => $data['proper_filename']
  ];

}, 10, 4 );

function netto_allow_svg_upload( $mimes ) {
  $mimes['svg'] = 'image/svg+xml';
  $mimes['svgz'] = 'image/svg+xml';
  return $mimes;
}
add_filter( 'upload_mimes', 'netto_allow_svg_upload' );

require NETTO_ADDONS_PATH . 'includes/secondary-image.php';


/*
* Portfolio CPT
*/
if(!class_exists('Awaiken_Portfolio')) { 
	class Awaiken_Portfolio {

		const CPT_SLUG = 'awaiken-project';
		const TAXONOMY_CATEGORY_SLUG = 'awaiken-project-category';

		public function register_data() {

			$labels = [
				'name' => esc_html_x( 'Projects', 'Projects', 'netto-themes-addons' ),
				'singular_name' => esc_html_x( 'Project', 'Project', 'netto-themes-addons' ),
				'menu_name' => esc_html_x( 'Projects', 'Projects', 'netto-themes-addons' ),
				'name_admin_bar' => esc_html__( 'Project Item', 'netto-themes-addons' ),
				'archives' => esc_html__( 'Project Item Archives', 'netto-themes-addons' ),
				'parent_item_colon' => esc_html__( 'Parent Item:', 'netto-themes-addons' ),
				'all_items' => esc_html__( 'All Items', 'netto-themes-addons' ),
				'add_new_item' => esc_html__( 'Add New Project', 'netto-themes-addons' ),
				'add_new' => esc_html__( 'Add New', 'netto-themes-addons' ),
				'new_item' => esc_html__( 'New Project', 'netto-themes-addons' ),
				'edit_item' => esc_html__( 'Edit Project', 'netto-themes-addons' ),
				'update_item' => esc_html__( 'Update Project', 'netto-themes-addons' ),
				'view_item' => esc_html__( 'View Project', 'netto-themes-addons' ),
				'search_items' => esc_html__( 'Search Project', 'netto-themes-addons' ),
				'not_found' => esc_html__( 'Not found', 'netto-themes-addons' ),
				'not_found_in_trash' => esc_html__( 'Not found in Trash', 'netto-themes-addons' ),
				'featured_image' => esc_html__( 'Featured Image', 'netto-themes-addons' ),
				'set_featured_image' => esc_html__( 'Set featured image', 'netto-themes-addons' ),
				'remove_featured_image' => esc_html__( 'Remove featured image', 'netto-themes-addons' ),
				'use_featured_image' => esc_html__( 'Use as featured image', 'netto-themes-addons' ),
				'insert_into_item' => esc_html__( 'Insert into Project', 'netto-themes-addons' ),
				'uploaded_to_this_item' => esc_html__( 'Uploaded to this Project', 'netto-themes-addons' ),
				'items_list' => esc_html__( 'Items list', 'netto-themes-addons' ),
				'items_list_navigation' => esc_html__( 'Items list navigation', 'netto-themes-addons' ),
				'filter_items_list' => esc_html__( 'Filter items list', 'netto-themes-addons' ),
			];

			$portfolio_slug = apply_filters( 'awaiken_project_slug', 'projects' );

			$rewrite = [
				'slug' => $portfolio_slug,
				'with_front' => false,
			];

			$args = [
				'labels' => $labels,
				'public' => true,
				'menu_position' => 25,
				'menu_icon' => 'dashicons-format-image',
				'capability_type' => 'post',
				'supports' => [ 'title', 'editor', 'thumbnail', 'author', 'excerpt', 'comments', 'revisions', 'page-attributes', 'custom-fields', 'elementor' ],
				'has_archive' => true,
				'rewrite' => $rewrite,
			];

			register_post_type( self::CPT_SLUG, $args );

			// Categories
			$portfolio_category_slug = apply_filters( 'awaiken_project_category_slug', 'project-category' );

			$rewrite = [
				'slug' => $portfolio_category_slug,
				'with_front' => false,
			];

			$args = [
				'hierarchical' => true,
				'show_ui' => true,
				'show_in_nav_menus' => false,
				'show_admin_column' => true,
				'labels' => $labels,
				'rewrite' => $rewrite,
				'public' => true,
				'labels' => [
					'name' => esc_html_x( 'Categories', 'Project', 'netto-themes-addons' ),
					'singular_name' => esc_html_x( 'Category', 'Project', 'netto-themes-addons' ),
					'all_items' => esc_html_x( 'All Categories', 'Project', 'netto-themes-addons' ),
				],
			];
			register_taxonomy( self::TAXONOMY_CATEGORY_SLUG, self::CPT_SLUG, $args );
		}

		public function __construct() {
			add_action( 'init', [ $this, 'register_data' ], 1 );
		}
	}
	/**
	 * initialize 
	 */
	$Awaiken_Portfolio = new Awaiken_Portfolio();
}