<?php

function ds1_add_taxonomy_to_p() {
	global $lang_code;

	foreach(checkSettings("reg_taxonomy") as $pp_type) {
		if(! isset($pp_type['labels']) || ! $pp_type['labels'] ) {
			$labels = array(
				'name'               => __( $pp_type['name'], $lang_code ),
				'singular_name'      => __( $pp_type['name'], $lang_code ),
				'menu_name'          => __( $pp_type['name'], $lang_code )
			);
		}
		else {
			$labels = $pp_type['labels'];
		}

		$args = array(
			'labels' 		=> $labels,
			'hierarchical' 	=> (isset($pp_type['hierarchical'])) ? $pp_type['hierarchical'] : true,
			'public' 		=> (isset($pp_type['public'])) 		 ? $pp_type['public'] : true,
			'_builtin'		=> (isset($pp_type['hierarchical'])) ? $pp_type['hierarchical'] : false,
		);
		
		if( isset($pp_type['rewrite']) ) {
			$args['rewrite'] = $pp_type['rewrite'];
		}

		if( isset($pp_type['more_fields'] ) ) {
			$args = array_merge($args, $pp_type['more_fields']);
		}

		register_taxonomy(  $pp_type['key'], $pp_type['ptypes'], $args );
	}
}
add_action( 'init', 'ds1_add_taxonomy_to_p' );
