Taxonomy_Manager::get_attachment_taxonomy_slug()

Gets the slug for the attachment taxonomy that should be used for form uploads.

Description

If a hierarchical attachment taxonomy has already been registered, the method will try its best to make a correct guess on which taxonomy to use. A filter is available to override this.

See also

Return

(string) Taxonomy slug, or empty string if attachment taxonomies should not be used.

Source

File: src/db-objects/taxonomy-manager.php

	public function get_attachment_taxonomy_slug() {
		$prefix = $this->get_prefix();

		if ( ! empty( $this->attachment_taxonomy_slug ) ) {
			$taxonomy_slug = $this->attachment_taxonomy_slug;
		} else {
			$taxonomy_slug = 'attachment_category';

			// If a hierarchical taxonomy has already been registered, make the best guess to use the right one.
			$attachment_taxonomies = get_object_taxonomies( 'attachment', 'objects' );
			if ( ! empty( $attachment_taxonomies ) ) {
				$attachment_taxonomies = array_keys( wp_list_filter( $attachment_taxonomies, array( 'hierarchical' => true ) ) );
				if ( ! empty( $attachment_taxonomies ) ) {
					if ( in_array( 'attachment_category', $attachment_taxonomies, true ) ) {
						$taxonomy_slug = 'attachment_category';
					} elseif ( in_array( 'category', $attachment_taxonomies, true ) ) {
						$taxonomy_slug = 'category';
					} else {
						$taxonomy_slug = $attachment_taxonomies[0];
					}
				}
			}
		}

		/**
		 * Filters the slug for the attachment taxonomy that should be used for form uploads.
		 *
		 * An empty string may be returned in order to not use attachment taxonomies at all.
		 *
		 * @since 1.0.0
		 *
		 * @param string $taxonomy_slug The taxonomy slug, or an empty string.
		 */
		return apply_filters( "{$prefix}get_attachment_taxonomy_slug", $taxonomy_slug );
	}

Changelog

Changelog
Version Description
1.0.0 Introduced.