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

//
// MegaMenus Register
// 
function vr_register_post_megamenus() {

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

	register_taxonomy( 
		'vr_megamenus_categories',
		'vr_megamenus',
		array(
			'labels' => array( 
				'name' 				=> __( 'MegaMenus 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_megamenus_tags',
		'vr_megamenus',
		array(
			'labels' => array( 
				'name' 				=> __( 'MegaMenus 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_megamenus' );
$vr_megamenus_metabox = new VP_Metabox( plugin_dir_path( __FILE__ ) . 'megamenus_metabox.php' );

//
// Menu Type Bind
//
function vr_megamenu_type_post( $type ) {
	if ( $type === 'post' )
		return true;
	return false;
}
VP_Security::instance()->whitelist_function( 'vr_megamenu_type_post' );

function vr_megamenu_type_custom( $type ) {
	if ( $type === 'custom' )
		return true;
	return false;
}
VP_Security::instance()->whitelist_function( 'vr_megamenu_type_custom' );

function vr_megamenu_type_widget( $type ) {
	if ( $type === 'widget' )
		return true;
	return false;
}
VP_Security::instance()->whitelist_function( 'vr_megamenu_type_widget' );

//
// Bind Primary Menu
//
function aio_bind_menu() {

	$datas = wp_get_nav_menu_object ( 'primary-menu' );
	$data = wp_get_nav_menu_items( $datas->term_id );

	$result = array();
	foreach ( (array) $data as $key => $menu_item ) {
		if ( $menu_item->menu_item_parent == 0 ) {
			$result[] = array( 'value' => $menu_item->title, 'label' => $menu_item->title );
		}
	}
	return $result;
}
VP_Security::instance()->whitelist_function( 'aio_bind_menu' );

//
// Bind Sidebar
//
function aio_bind_sidebars() {
	global $wp_query;
	$wp_query = new WP_Query( array(
		'posts_per_page' 	=> 24,
		'category'			=> '',
		'post_type' 		=> 'vr_sidebars',
		'post_status'		=> 'publish',
		'orderby'			=> 'date'
	));
	$result = array();
	$result[] = array( 'value' => 'Index Sidebar', 'label' => 'Index Sidebar' );
	$result[] = array( 'value' => 'Page Sidebar', 'label' => 'Page Sidebar' );
	$result[] = array( 'value' => 'Single Sidebar', 'label' => 'Single Sidebar' );
	$result[] = array( 'value' => 'Footer Area', 'label' => 'Footer Area' );
	while ( $wp_query->have_posts() ) : $wp_query->the_post();
		$result[] = array( 'value' => vp_metabox( 'vr_sidebars.name' ), 'label' => vp_metabox( 'vr_sidebars.name' ) );
	endwhile;
	wp_reset_query();
	return $result;
}
VP_Security::instance()->whitelist_function( 'aio_bind_sidebars' );

/*
 * EOF
 */