Inventory_Presser_Plugin::change_term_links( string $termlink, object $term )

Change links to terms in our taxonomies to include /inventory before /tax/term.

On This Page


Parameters Parameters

$termlink

(string) (Required) URL to modify.

$term

(object) (Required) An instance of the WP_Term class.


Top ↑

Return Return

(string) A modified term link that has our post type slug prepended.


Top ↑

Source Source

File: inventory-presser.php

		public function change_term_links( $termlink, $term ) {
			// Exit early, this method runs often in the dashboard.
			if ( false !== $termlink && '/category' === substr( $termlink, 0, 9 ) ) {
				return $termlink;
			}
			$taxonomy = get_taxonomy( strtolower( $term->taxonomy ) );
			if ( ! empty( $taxonomy->object_type ) && ! in_array( INVP::POST_TYPE, $taxonomy->object_type, true ) ) {
				return $termlink;
			}

			$post_type = get_post_type_object( INVP::POST_TYPE );
			if ( empty( $post_type ) ) {
				return $termlink;
			}

			$termlink = $post_type->rewrite['slug'] . $termlink;
			return $termlink;
		}