<?php
/**
 * Pricings Register
 *
 * @package All In One Custom Post
 * @since All In One Custom Post 1.0.0 
 */
if ( !defined( 'ABSPATH' ) ) exit;

// Register pricing custom post
function vr_register_post_pricings() {

	register_post_type( 'vr_pricings',
	array(
		'menu_icon' 	=> 'dashicons-tag',
		'supports' 		=> array( 'title', 'thumbnail', 'author' ),
		'public' 		=> true,
		'show_ui' 		=> true,
		'labels'        => array(
			'name'                	=> __( 'Pricings', PLUGIN_NAME ),
			'singular_name'       	=> __( 'Pricing', PLUGIN_NAME ),
			'add_new'             	=> __( 'Add New Pricing', PLUGIN_NAME ),
			'add_new_item'        	=> __( 'Add New Pricing', PLUGIN_NAME ),
			'menu_name'           	=> __( 'Pricings', PLUGIN_NAME ),
			'parent_item_colon'   	=> __( 'Parent Pricing', PLUGIN_NAME ),
			'all_items'           	=> __( 'All Pricings', PLUGIN_NAME ),
			'view_item'           	=> __( 'View Pricing', PLUGIN_NAME ),
			'edit_item'           	=> __( 'Edit Pricing', PLUGIN_NAME ),
			'update_item'         	=> __( 'Update Pricing', PLUGIN_NAME ),
			'search_items'        	=> __( 'Search Pricing', PLUGIN_NAME ),
			'not_found' 			=> __(  'No Pricing found', PLUGIN_NAME ),
			'not_found_in_trash'	=> __(  'No Pricing found in Trash', PLUGIN_NAME ),
			'parent' 				=> __(  'Parent Pricing', PLUGIN_NAME ),
		)
	) );

	register_taxonomy(
		'vr_pricings_categories',
		'vr_pricings',
		array(
			'labels' => array(
				'name' 				=> __( 'Pricings Categories', PLUGIN_NAME ),
				'singular_name' 	=> __( 'Category', PLUGIN_NAME ),
				'search_items'  	=> __( 'Search Categories', PLUGIN_NAME ),
				'all_items' 		=> __( 'All Categories', PLUGIN_NAME ),
				'parent_item' 		=> __( 'Parent Category', PLUGIN_NAME ),
				'parent_item_colon' => __( 'Parent Category:', PLUGIN_NAME ),
				'edit_item' 		=> __( 'Edit Category', PLUGIN_NAME ),
				'update_item' 		=> __( 'Update Category', PLUGIN_NAME ),
				'add_new_item' 		=> __( 'Add New Category', PLUGIN_NAME ),
				'new_item_name'		=> __( 'New Category Name', PLUGIN_NAME ),
				'menu_name' 		=> __( 'Categories', PLUGIN_NAME ),
			 ),
			'hierarchical' => true,
			'public' => true,
			'rewrite' => true
		)
	);

	register_taxonomy(
		'vr_pricings_tags',
		'vr_pricings',
		array(
			'labels' => array(
				'name' 				=> __( 'Pricings Tags', PLUGIN_NAME ),
				'singular_name' 	=> __( 'Tag', PLUGIN_NAME ),
				'search_items'  	=> __( 'Search Tags', PLUGIN_NAME ),
				'all_items' 		=> __( 'All Tags', PLUGIN_NAME ),
				'parent_item' 		=> __( 'Parent Tag', PLUGIN_NAME ),
				'parent_item_colon'	=> __( 'Parent Tag:', PLUGIN_NAME ),
				'edit_item' 		=> __( 'Edit Tag', PLUGIN_NAME ),
				'update_item' 		=> __( 'Update Tag', PLUGIN_NAME ),
				'add_new_item' 		=> __( 'Add New Tag', PLUGIN_NAME ),
				'new_item_name' 	=> __( 'New Tag Name', PLUGIN_NAME ),
				'menu_name' 		=> __( 'Tags', PLUGIN_NAME ),
			 ),
			'hierarchical' => false,
			'public' => true,
			'rewrite' => true
		)
	);

}
add_action( 'init', 'vr_register_post_pricings' );
$vr_pricings_metabox = new VP_Metabox( plugin_dir_path( __FILE__ ) . 'pricings_metabox.php' );

// Pricings Shortcode
function vr_shortcode_pricings( $atts ) {

	extract( shortcode_atts( array(
		'module'			=> '',
		'posts_per_page' 	=> -1,
		'column'			=> '',
		'category'			=> '',
		'id'				=> '',
		'ani' 				=> '',
		'animation'			=> ''
	), $atts ) );

	global $wp_query;
	$wp_query = new WP_Query( array(
		'p'					        => esc_attr( $id ),
		'posts_per_page' 	        => esc_attr( $posts_per_page ),
		'vr_pricings_categories'    => esc_attr( $category ),
		'post_type' 		        => 'vr_pricings',
		'post_status'		        => 'publish',
		'orderby'			        => 'date'
	) );

	if ( $animation != '' ) { $animation = 'data-animation="' . $animation . '"'; $ani = 'fx-start'; }
	ob_start(); ?>

	<?php if ( $module == 'group' ) : ?>
			
		<div class="pricing-groups row-equal clearfix <?php echo sanitize_html_class( $ani ); ?>" <?php echo $animation; ?>>
		<?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
		
			<?php if ( vp_metabox( 'vr_pricings.highlight' ) == 1 ) : ?>
					<article class="pricing-group pricing-highlight column-equal <?php echo wp_strip_all_tags( $column ); ?>">
			<?php else : ?>
					<article class="pricing-group column-equal  <?php echo wp_strip_all_tags( $column ); ?>">
			<?php endif; ?>
				<div class="pricing-head">
					<h3><?php echo wp_strip_all_tags( get_the_title() ); ?></h3>
					<div class="pricing-price">
						<span><?php echo wp_strip_all_tags( vp_metabox( 'vr_pricings.price' ) ); ?></span>
						<small><?php echo wp_strip_all_tags( vp_metabox( 'vr_pricings.schedule' ) ); ?></small>
					</div>
					<?php if ( vp_metabox( 'vr_pricings.url' ) != '' ) : ?>
						<a href="<?php echo esc_url( vp_metabox( 'vr_pricings.url' ) ); ?>" class="button-medium button-dark"><?php echo wp_strip_all_tags( 'vr_pricings.button_caption' ); ?></a>
					<?php else : ?>
						<a href="#" class="button-small button-edge"><?php echo wp_strip_all_tags( vp_metabox( 'vr_pricings.button_caption' ) ); ?></a>
					<?php endif; ?>
				</div>
				<ul>
					<?php 
					$lists = vp_metabox( 'vr_pricings.features' );
					foreach ( $lists as $list ) {
					?>
						<li><i class="fa <?php echo wp_strip_all_tags( $list['icon'] ); ?>"></i><?php echo wp_strip_all_tags( $list['caption'] ); ?></li>
					<?php } ?>
				</ul>
				</article>
		<?php endwhile; ?>
		</div>
		
	<?php elseif ( $module == 'widget' ) : ?>
	
		<div class="row row-equal fx">
		<?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
		
			<?php if ( vp_metabox( 'vr_pricings.highlight' ) == 1 ) : ?>
				<article class="pricing-widget pricing-highlight column-equal <?php echo wp_strip_all_tags( $column ); ?> <?php echo sanitize_html_class( $ani ); ?>" <?php echo $animation; ?>>
			<?php else : ?>
				<article class="pricing-widget column-equal <?php echo wp_strip_all_tags( $column ); ?> <?php echo sanitize_html_class( $ani ); ?>" <?php echo $animation; ?>>
			<?php endif; ?>
			<div class="pricing-head" style="background-color:<?php echo vp_metabox( 'vr_pricings.background_color' ); ?>;">
				<h3><?php echo wp_strip_all_tags( get_the_title() ); ?></h3>
				<i class="fa <?php echo sanitize_html_class( vp_metabox( 'vr_pricings.icon' ) ); ?>"></i>
				<div class="pricing-price">
					<span><?php echo wp_strip_all_tags( vp_metabox( 'vr_pricings.price' ) ); ?></span>
					<small><?php echo wp_strip_all_tags( vp_metabox( 'vr_pricings.schedule' ) ); ?></small>
				</div>
				<?php if ( vp_metabox( 'vr_pricings.url' ) != '' ) : ?>
					<a href="<?php echo esc_url( vp_metabox( 'vr_pricings.url' ) ); ?>" class="button-medium button-dark"><?php echo wp_strip_all_tags( 'vr_pricings.button_caption' ); ?></a>
				<?php else : ?>
					<a href="#" class="button-small button-dark"><?php echo wp_strip_all_tags( vp_metabox( 'vr_pricings.button_caption' ) ); ?></a>
				<?php endif; ?>
			</div>
			</article>
		<?php endwhile; ?>
		</div>
		
	<?php else : ?>
	
		<div class="row row-equal fx">
		<?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
		
			<?php if ( vp_metabox( 'vr_pricings.highlight' ) == 1 ) : ?>
				<article class="pricing-grid pricing-highlight column-equal <?php echo wp_strip_all_tags( $column ); ?> <?php echo sanitize_html_class( $ani ); ?>" <?php echo $animation; ?>>
			<?php else : ?>
				<article class="pricing-grid column-equal <?php echo wp_strip_all_tags( $column ); ?> <?php echo sanitize_html_class( $ani ); ?>" <?php echo $animation; ?>>
			<?php endif; ?>
				<div class="pricing-head"  style="background-color:<?php echo vp_metabox( 'vr_pricings.background_color' ); ?>;">
					<h3><?php echo wp_strip_all_tags( get_the_title() ); ?></h3>
					<i class="fa <?php echo sanitize_html_class( vp_metabox( 'vr_pricings.icon' ) ); ?>"></i>
					<div class="pricing-price">
						<span><?php echo wp_strip_all_tags( vp_metabox( 'vr_pricings.price' ) ); ?></span>
						<small><?php echo wp_strip_all_tags( vp_metabox( 'vr_pricings.schedule' ) ); ?></small>
					</div>
				</div>
				<ul>
					<?php 
					$lists = vp_metabox( 'vr_pricings.features' );
					foreach ( $lists as $list ) {
					?>
						<li><i class="fa <?php echo wp_strip_all_tags( $list['icon'] ); ?>"></i><?php echo wp_strip_all_tags( $list['caption'] ); ?></li>
					<?php } ?>
				</ul>
				<div class="pricing-foot">
					<?php if ( vp_metabox( 'vr_pricings.url' ) != '' ) : ?>
						<a href="<?php echo esc_url( vp_metabox( 'vr_pricings.url' ) ); ?>" class="button-medium button-dark"><?php echo wp_strip_all_tags( 'vr_pricings.button_caption' ); ?></a>
					<?php else : ?>
						<a href="#" class="button-small button-dark"><?php echo wp_strip_all_tags( vp_metabox( 'vr_pricings.button_caption' ) ); ?></a>
					<?php endif; ?>
				</div>
			</article>
			
		<?php endwhile; ?>
		</div>

	<?php endif; ?>
		
	<?php
	wp_reset_query();
	$html = ob_get_clean();
	return $html;
}
add_shortcode( "shortcode_pricings", "vr_shortcode_pricings" );

/*
 * EOF
 */