<?php
/**
 * The default Custom post type Slide
 *
 * @package WordPress
 * @subpackage Charity
 * @since Charity 1.0
 */
class Wpl_Toolskit_Slider {

	/**
	 * Construct
	 *
	 * @since 1.0.0
	 */
	public function __construct() {
		/* Add Custom Post Types */
		add_action( 'init', array( $this, 'wpl_sliders_cpt' ), 0 );

		/* Add Taxomomy Custom Post Types */
		//add_action( 'init', array( $this, 'wpl_toolskit_slider_taxomomy' ), 0 );

		/* Add Meta Boxes Custom Post Types*/
		add_action( 'admin_init', array( $this, 'wpl_toolskit_slider_meta_boxes' ) );
	}

	/**
	 * Get CPT parameters from Theme Option
	 *
	 * @since 1.0.0
	 */
	public function wpl_get_rewrite_url() {
		return ot_get_option('wpl_slide_url_rewrite') ? ot_get_option('wpl_slide_url_rewrite') : 'slide';
	}

	public function wpl_get_category_url_rewrite() {
	}

	public function wpl_get_name_singular() {
		return ot_get_option('wpl_slide_name_singular') ? ot_get_option('wpl_slide_name_singular') : 'Slide';
	}

	public function wpl_get_name_plural() {
		return ot_get_option('wpl_slide_name_plural') ? ot_get_option('wpl_slide_name_plural') : 'Slides';
	}


	/**
	 * Register Custom Post Type
	 *
	 * @since 1.0.0
	 */
	public 	function wpl_sliders_cpt(){

		$labels = array(
			'name'                => _x( $this->wpl_get_name_plural(), 'Post Type General Name', 'charity-toolskit' ),
			'singular_name'       => _x( $this->wpl_get_name_singular(), 'Post Type Singular Name', 'charity-toolskit' ),
			'menu_name'           => __( $this->wpl_get_name_plural(), 'charity-toolskit' ),
			'name_admin_bar'      => __( $this->wpl_get_name_singular(), 'charity-toolskit' ),
			'parent_item_colon'   => __( 'Parent Item:', 'charity-toolskit' ),
			'all_items'           => sprintf( _x( 'All %1$s', 'Plural name', 'charity-toolskit' ), $this->wpl_get_name_plural() ),
			'add_new_item'        => sprintf( _x( 'Add New %1$s', 'Singular name', 'charity-toolskit' ), $this->wpl_get_name_singular() ),
			'add_new'             => sprintf( _x( 'Add %1$s', 'Singular name', 'charity-toolskit' ), $this->wpl_get_name_singular() ),
			'new_item'            => sprintf( _x( 'New %1$s', 'Singular name', 'charity-toolskit' ), $this->wpl_get_name_singular() ),
			'edit_item'           => sprintf( _x( 'Edit %1$s', 'Singular name', 'charity-toolskit' ), $this->wpl_get_name_singular() ),
			'update_item'         => sprintf( _x( 'Update %1$s', 'Singular name', 'charity-toolskit' ), $this->wpl_get_name_singular() ),
			'view_item'           => sprintf( _x( 'View %1$s', 'Singular name', 'charity-toolskit' ), $this->wpl_get_name_singular() ),
			'search_items'        => sprintf( _x( 'Search %1$s', 'Singular name', 'charity-toolskit' ), $this->wpl_get_name_singular() ),
			'not_found'           => __( 'Not found', 'charity-toolskit' ),
			'not_found_in_trash'  => __( 'Not found in Trash', 'charity-toolskit' ),
		);
		$rewrite = array(
			'slug'                => $this->wpl_get_rewrite_url(),
			'with_front'          => true,
			'pages'               => true,
			'feeds'               => false,
		);
		$args = array(
			'label'               => __( $this->wpl_get_name_singular(), 'charity-toolskit' ),
			'description'         => __( 'Add items to your home page slider.', 'charity-toolskit' ),
			'labels'              => $labels,
			'supports'            => array('title', 'excerpt', 'author'),
			'show_in_rest' 		  => true,
			'hierarchical'        => false,
			'public'              => true,
			'show_ui'             => true,
			'show_in_menu'        => true,
			//'menu_position'       => 33.1,
			'menu_icon'           => 'dashicons-slides',
			'show_in_admin_bar'   => true,
			'show_in_nav_menus'   => true,
			'can_export'          => true,
			'has_archive'         => true,
			'exclude_from_search' => false,
			'publicly_queryable'  => true,
			'rewrite'             => $rewrite,
			'capability_type'     => 'post',
		);
		register_post_type( 'post_sliders', $args );
	}

	/**
	 * Register Custom Taxonomy
	 *
	 * @since 1.0.0
	 */
	public function wpl_toolskit_slider_taxomomy() {}



	/**
	 * Register Meta Boxes
	 *
	 * @since 1.0.0
	 */
	public function wpl_toolskit_slider_meta_boxes() {
		$sliders_meta_box = array(
			'id'          => 'sliders_meta_box',
			'title'       => __('Slider Options', 'charity-toolskit'),
			'desc'        => '',
			'pages'       => array( 'post_sliders' ),
			'context'     => 'normal',
			'priority'    => 'default',
			'fields'      => array(

				array(
					'label'       => __('Slide image', 'charity-toolskit'),
					'id'          => 'wpl_slide_image',
					'type'        => 'upload',
					'desc'        => __('The image will be displayed in the header of the page, the required dimensions:  (1920 x 800)',  'charity-toolskit'),
					'std'         => '',
					'rows'        => '',
					'post_type'   => '',
					'taxonomy'    => '',
					'class'       => '',
					'section'     => ''
				),
				array(
					'label'       => __('Type of slider', 'charity-toolskit'),
					'id'          => 'wpl_slide_type',
					'type'        => 'select',
					'desc'        => __('Standard Slider or Cause Slider', 'charity-toolskit'),
					'std'         => 'standard_slider',
					'rows'        => '',
					'post_type'   => '',
					'taxonomy'    => '',
					'class'       => '',
					'operator'    => 'and',
					'section'     => '',
					'choices'     => array(
						array(
							'value'       => 'standard_slider',
							'label'       => __( 'Standard Slider', 'charity-toolskit' ),
							'src'         => ''
						),
						array(
							'value'       => 'cause_slider',
							'label'       => __( 'Cause Slider', 'charity-toolskit' ),
							'src'         => ''
						),
					)
				),
				array(
					'label'       => __('Action Button Text', 'charity-toolskit'),
					'id'          => 'wpl_slider_button_text_standard',
					'type'        => 'text',
					'desc'        => __('Add text to the button', 'charity-toolskit'),
					'std'         => '',
					'rows'        => '',
					'post_type'   => '',
					'taxonomy'    => '',
					'class'       => '',
					'condition'   => 'wpl_slide_type:is(standard_slider)',
				),
				array(
					'label'       => __('Action Button URL', 'charity-toolskit'),
					'id'          => 'wpl_slider_button_url_standard',
					'type'        => 'text',
					'desc'        => __('Add button url', 'charity-toolskit'),
					'std'         => '',
					'rows'        => '',
					'post_type'   => '',
					'taxonomy'    => '',
					'class'       => '',
					'condition'   => 'wpl_slide_type:is(standard_slider)',
				),
				array(
					'label'       => __('Select Cause', 'charity-toolskit'),
					'id'          => 'wpl_slider_button_cause_id',
					'type'        => 'custom-post-type-select',
					'desc'        => __('Select causes', 'charity-toolskit'),
					'std'         => '',
					'rows'        => '',
					'post_type'   => 'post_causes',
					'taxonomy'    => '',
					'class'       => '',
					'condition'   => 'wpl_slide_type:is(cause_slider)',
				),
				array(
					'label'       => __('Action Button Text', 'charity-toolskit'),
					'id'          => 'wpl_slider_button_text',
					'type'        => 'text',
					'desc'        => __('Add text to the button', 'charity-toolskit'),
					'std'         => '',
					'rows'        => '',
					'post_type'   => '',
					'taxonomy'    => '',
					'class'       => '',
					'condition'   => 'wpl_slide_type:is(cause_slider)',
				),
				array(
					'label'       => __('Action Button URL', 'charity-toolskit'),
					'id'          => 'wpl_slider_button_url',
					'type'        => 'text',
					'desc'        => __('Add button url', 'charity-toolskit'),
					'std'         => '',
					'rows'        => '',
					'post_type'   => '',
					'taxonomy'    => '',
					'class'       => '',
					'condition'   => 'wpl_slide_type:is(cause_slider)',
				),
			)
		);
	ot_register_meta_box( $sliders_meta_box );
	}
}
?>
