1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  16  17  18  19  20  21  22  23  24  25  26  27  28  29  30  31  32  33  34  35  36  37  38  39  40  41  42  43  44  45  46  47  48  49  50  51  52  53  54  55  56  57  58  59  60  61  62  63  64  65  66  67  68  69  70  71  72  73  74  75  76  77  78  79  80  81  82  83  84  85  86  87  88  89  90  91  92  93  94  95  96  97  98  99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 
	<?php
function papi_get_taxonomy_type_id( $term_id = 0 ) {
    return papi_get_entry_type_id( $term_id, 'term' );
}
function papi_get_taxonomy_type_name( $term_id = 0 ) {
    $term_id = papi_get_term_id( $term_id );
    if ( empty( $term_id ) ) {
        return '';
    }
    $entry_type_id = papi_get_taxonomy_type_id( $term_id );
    if ( empty( $entry_type_id ) ) {
        return '';
    }
    $entry_type = papi_get_entry_type_by_id( $entry_type_id );
    if ( empty( $entry_type ) ) {
        return '';
    }
    return $entry_type->name;
}
function papi_load_taxonomy_type_id( $entry_type_id = '', $type = 'term' ) {
    if ( $type !== 'term' ) {
        return $entry_type_id;
    }
    $key      = papi_get_page_type_key();
    $term_id  = papi_get_term_id();
    $taxonomy = papi_get_taxonomy( $term_id );
    
    if ( empty( $entry_type_id ) ) {
        $entry_type_id = papi_filter_settings_only_taxonomy_type( $taxonomy );
    }
    
    if ( empty( $entry_type_id ) && $term_id > 0 && papi_supports_term_meta() ) {
        $meta_value    = get_term_meta( $term_id, $key, true );
        $entry_type_id = empty( $meta_value ) ? '' : $meta_value;
    }
    
    if ( empty( $entry_type_id ) ) {
        $key = sprintf( 'entry_type_id.taxonomy.%s', $taxonomy );
        if ( papi()->exists( $key )  ) {
            return papi()->make( $key );
        }
    }
    return $entry_type_id;
}
add_filter( 'papi/entry_type_id', 'papi_load_taxonomy_type_id', 10, 2 );
function papi_get_taxonomies() {
    $taxonomies  = [];
    $entry_types = papi_get_all_entry_types( [
        'types' => 'taxonomy'
    ] );
    foreach ( $entry_types as $entry_type ) {
        $taxonomies = array_merge( $taxonomies, papi_to_array( $entry_type->taxonomy ) );
    }
    return array_unique( $taxonomies );
}
function papi_set_taxonomy_type_id( $term_id, $taxonomy_type ) {
    if ( papi_entry_type_exists( $taxonomy_type ) ) {
        return update_term_meta( papi_get_term_id( $term_id ), papi_get_page_type_key(), $taxonomy_type );
    }
    return false;
}
function the_papi_taxonomy_type_name( $term_id = 0 ) {
    echo papi_get_taxonomy_type_name( $term_id );
}