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 
	<?php
function papi_get_term_id( $term_id = null ) {
    if ( is_object( $term_id ) && isset( $term_id->term_id ) ) {
        return $term_id->term_id;
    }
    if ( is_numeric( $term_id ) && is_string( $term_id ) && $term_id !== '0' ) {
        return intval( $term_id );
    }
    if ( is_null( $term_id ) || intval( $term_id ) === 0 ) {
        if ( ! is_admin() && ( is_category() || is_tag() || is_tax() ) ) {
            return get_queried_object_id();
        } else if ( $term_id = papi_get_or_post( 'term_id' ) ) {
            return intval( $term_id );
        } else if ( $tag_id = papi_get_or_post( 'tag_ID' ) ) {
            return intval( $tag_id );
        }
    }
    return intval( $term_id );
}
function papi_get_taxonomy( $term_id = null ) {
    if ( $taxonomy = papi_get_or_post( 'taxonomy' ) ) {
        return $taxonomy;
    }
    $term_id = papi_get_term_id( $term_id );
    if ( $term_id !== 0 ) {
        $term = get_term( $term_id, '' );
        if ( is_object( $term ) && ! is_wp_error( $term ) ) {
            return strtolower( $term->taxonomy );
        }
    }
    return '';
}
function papi_get_taxonomy_label( $taxonomy, $label, $default = '' ) {
    if ( ! taxonomy_exists( $taxonomy ) ) {
        return $default;
    }
    return get_taxonomy( $taxonomy )->labels->$label;
}
function papi_supports_term_meta() {
    return function_exists( 'get_term_meta' );
}