<?php

function ds1_add_post_type_to_p() {
	global $lang_code;

	foreach(checkSettings("reg_post_types") 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,
			'menu_icon' 	=> (isset($pp_type['menu_icon'])) 		? $pp_type['menu_icon'] : '',
			'menu_position' => (isset($pp_type['menu_position'])) 	? intval($pp_type['menu_position']) : 4,
			'supports' 		=> (isset($pp_type['supports'])) 		? $pp_type['supports'] : [],
			'taxonomies' 	=> (isset($pp_type['taxonomies'])) 		? $pp_type['taxonomies'] : [],
			'public' 		=> (isset($pp_type['public'])) 			? $pp_type['public'] : true,
			'show_in_rest' 	=> (isset($pp_type['show_in_rest'])) 	? $pp_type['show_in_rest'] : true,
			'description' 	=> (isset($pp_type['description'])) 	? $pp_type['description'] : true,
			
			'hierarchical' 	=> (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_post_type( $pp_type['key'], $args );
	}
}
add_action( 'init', 'ds1_add_post_type_to_p' );

foreach(checkSettings("reg_post_types") as $pp_type) {
	add_filter("views_edit-". $pp_type['key'], function ( $views ){

		$screen = get_current_screen();
		$post_type = get_post_type_object($screen->post_type);
	
		if ($post_type->description) {
			printf('<h4 class="main-t-description">%s</h4>', $post_type->description); // echo 
		}
	
		return $views; // return original input unchanged
	});
}