<?php

/**
 * Initialize Custom Post Type - Confin Theme
 */

function confin_custom_post_type() {
	// Team - Start
	$service_slug = 'service';
	$services = esc_html__('Services', 'confin-core');

	// Register custom post type - Team
	register_post_type('service',
		array(
			'labels' => array(
				'name' => $services,
				'singular_name' => sprintf(esc_html__('%s Post', 'confin-core' ), $services),
				'all_items' => sprintf(esc_html__('%s', 'confin-core' ), $services),
				'add_new' => esc_html__('Add New', 'confin-core') ,
				'add_new_item' => sprintf(esc_html__('Add New %s', 'confin-core' ), $services),
				'edit' => esc_html__('Edit', 'confin-core') ,
				'edit_item' => sprintf(esc_html__('Edit %s', 'confin-core' ), $services),
				'new_item' => sprintf(esc_html__('New %s', 'confin-core' ), $services),
				'view_item' => sprintf(esc_html__('View %s', 'confin-core' ), $services),
				'search_items' => sprintf(esc_html__('Search %s', 'confin-core' ), $services),
				'not_found' => esc_html__('Nothing found in the Database.', 'confin-core') ,
				'not_found_in_trash' => esc_html__('Nothing found in Trash', 'confin-core') ,
				'parent_item_colon' => ''
			) ,
			'public' => true,
			'publicly_queryable' => true,
			'exclude_from_search' => false,
			'show_ui' => true,
			'query_var' => true,
			'menu_position' => 11,
			'menu_icon' => 'dashicons-welcome-add-page',
			'rewrite' => array(
				'slug' => $service_slug,
				'with_front' => false
			),
			'has_archive' => true,
			'capability_type' => 'post',
			'hierarchical' => true,
			'supports' => array(
				'title',
				'editor',
				'thumbnail',
				'excerpt',
				'revisions',
			)
		)
	);
	// Service - End

  // Case - Start
  $project_slug = 'project';
  $projects = esc_html__('Project', 'confin-core');

  // Register custom post type - project
  register_post_type('project',
    array(
      'labels' => array(
        'name' => $projects,
        'singular_name' => sprintf(esc_html__('%s Post', 'confin-core' ), $projects),
        'all_items' => sprintf(esc_html__('%s', 'confin-core' ), $projects),
        'add_new' => esc_html__('Add New', 'confin-core') ,
        'add_new_item' => sprintf(esc_html__('Add New %s', 'confin-core' ), $projects),
        'edit' => esc_html__('Edit', 'confin-core') ,
        'edit_item' => sprintf(esc_html__('Edit %s', 'confin-core' ), $projects),
        'new_item' => sprintf(esc_html__('New %s', 'confin-core' ), $projects),
        'view_item' => sprintf(esc_html__('View %s', 'confin-core' ), $projects),
        'search_items' => sprintf(esc_html__('Search %s', 'confin-core' ), $projects),
        'not_found' => esc_html__('Nothing found in the Database.', 'confin-core') ,
        'not_found_in_trash' => esc_html__('Nothing found in Trash', 'confin-core') ,
        'parent_item_colon' => ''
      ) ,
      'public' => true,
      'publicly_queryable' => true,
      'exclude_from_search' => false,
      'show_ui' => true,
      'query_var' => true,
      'menu_position' => 12,
      'menu_icon' => 'dashicons-portfolio',
      'rewrite' => array(
        'slug' => $project_slug,
        'with_front' => false
      ),
      'has_archive' => true,
      'capability_type' => 'post',
      'hierarchical' => true,
      'supports' => array(
        'title',
        'editor',
        'thumbnail',
      )
    )
  );
  // project - End
  // Add Category Taxonomy for our Custom Post Type - Project
  register_taxonomy(
    'project_category',
    'project',
    array(
      'hierarchical' => true,
      'public' => true,
      'show_ui' => true,
      'show_admin_column' => true,
      'show_in_nav_menus' => true,
      'labels' => array(
        'name' => sprintf(esc_html__( '%s Categories', 'panzeri-core' ), $projects),
        'singular_name' => sprintf(esc_html__('%s Category', 'panzeri-core'), $projects),
        'search_items' =>  sprintf(esc_html__( 'Search %s Categories', 'panzeri-core'), $projects),
        'all_items' => sprintf(esc_html__( 'All %s Categories', 'panzeri-core'), $projects),
        'parent_item' => sprintf(esc_html__( 'Parent %s Category', 'panzeri-core'), $projects),
        'parent_item_colon' => sprintf(esc_html__( 'Parent %s Category:', 'panzeri-core'), $projects),
        'edit_item' => sprintf(esc_html__( 'Edit %s Category', 'panzeri-core'), $projects),
        'update_item' => sprintf(esc_html__( 'Update %s Category', 'panzeri-core'), $projects),
        'add_new_item' => sprintf(esc_html__( 'Add New %s Category', 'panzeri-core'), $projects),
        'new_item_name' => sprintf(esc_html__( 'New %s Category Name', 'panzeri-core'), $projects)
      ),
      'rewrite' => array( 'slug' => $project_slug . '_cat' ),
    )
  );

  $args = array(
    'hierarchical' => true,
    'public' => true,
    'show_ui' => true,
    'show_admin_column' => true,
    'show_in_nav_menus' => true,
    'show_tagcloud' => false,
  );

}


// After Theme Setup
function confin_custom_flush_rules() {
	// Enter post type function, so rewrite work within this function
	confin_custom_post_type();
	// Flush it
	flush_rewrite_rules();
}
register_activation_hook(__FILE__, 'confin_custom_flush_rules');
add_action('init', 'confin_custom_post_type');


/* ---------------------------------------------------------------------------
 * Custom columns - Service
 * --------------------------------------------------------------------------- */
add_filter("manage_edit-service_columns", "confin_service_edit_columns");
function confin_service_edit_columns($columns) {
  $new_columns['cb'] = '<input type="checkbox" />';
  $new_columns['title'] = esc_html__('Title', 'confin-core' );
  $new_columns['thumbnail'] = esc_html__('Image', 'confin-core' );
  $new_columns['date'] = esc_html__('Date', 'confin-core' );

  return $new_columns;
}

add_action('manage_service_posts_custom_column', 'confin_manage_service_columns', 10, 2);
function confin_manage_service_columns( $column_name ) {
  global $post;

  switch ($column_name) {

    /* If displaying the 'Image' column. */
    case 'thumbnail':
      echo get_the_post_thumbnail( $post->ID, array( 100, 100) );
    break;

    /* Just break out of the switch statement for everything else. */
    default :
      break;
    break;

  }
}


/* ---------------------------------------------------------------------------
 * Custom columns - case
 * --------------------------------------------------------------------------- */
add_filter("manage_edit-project_columns", "confin_project_edit_columns");
function confin_project_edit_columns($columns) {
  $new_columns['cb'] = '<input type="checkbox" />';
  $new_columns['title'] = esc_html__('Title', 'confin-core' );
  $new_columns['thumbnail'] = esc_html__('Image', 'confin-core' );
  $new_columns['date'] = esc_html__('Date', 'confin-core' );

  return $new_columns;
}

add_action('manage_project_posts_custom_column', 'confin_manage_project_columns', 10, 2);
function confin_manage_project_columns( $column_name ) {
  global $post;

  switch ($column_name) {

    /* If displaying the 'Image' column. */
    case 'thumbnail':
      echo get_the_post_thumbnail( $post->ID, array( 100, 100) );
    break;

    /* Just break out of the switch statement for everything else. */
    default :
      break;
    break;

  }
}
