<?php

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( class_exists( 'AIEO_Content_Types', false ) ) {
	return;
}

class AIEO_Content_Types {

	
	public static function post_types() {
		$out = array();
		foreach ( get_post_types( array( 'public' => true ), 'objects' ) as $pt ) {
			if ( in_array( $pt->name, array( 'attachment', 'revision', 'nav_menu_item' ), true ) ) {
				continue;
			}
			$out[ $pt->name ] = (string) $pt->labels->name;
		}
		
		return (array) apply_filters( 'aieo_content_post_types', $out );
	}

	
	public static function is_content_post_type( $post_type ) {
		$post_type = (string) $post_type;
		if ( '' === $post_type || in_array( $post_type, array( 'attachment', 'revision', 'nav_menu_item' ), true ) ) {
			return false;
		}
		$pto = get_post_type_object( $post_type );
		return $pto && ! empty( $pto->public );
	}

	
	public static function taxonomies() {
		$out = array();
		foreach ( get_taxonomies( array( 'public' => true ), 'objects' ) as $tx ) {
			if ( 'post_format' === $tx->name || ! is_taxonomy_viewable( $tx ) ) {
				continue;
			}
			if ( 0 === strpos( $tx->name, 'pa_' ) && 'pa_need' !== $tx->name ) {
				continue;
			}
			$out[ $tx->name ] = (string) $tx->labels->name;
		}
		
		return (array) apply_filters( 'aieo_content_taxonomies', $out );
	}

	
	public static function post_type_count( $post_type ) {
		$counts = wp_count_posts( (string) $post_type );
		return ( is_object( $counts ) && isset( $counts->publish ) ) ? (int) $counts->publish : 0;
	}

	
	public static function taxonomy_count( $taxonomy ) {
		$n = wp_count_terms( array( 'taxonomy' => (string) $taxonomy, 'hide_empty' => false ) );
		return is_wp_error( $n ) ? 0 : (int) $n;
	}
}
