<?php
/**
 * @package   BreadcrumbTrail
 * @version   1.1.0
 * @author    Justin Tadlock <justin@justintadlock.com>
 * @copyright Copyright (c) 2008 - 2017, Justin Tadlock
 * @link      https://themehybrid.com/plugins/breadcrumb-trail
 * @license   http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 */

function breadcrumb_trail( $dog_pet_house_args = array() ) {

	$dog_pet_house_breadcrumb = apply_filters( 'breadcrumb_trail_object', null, $dog_pet_house_args );

	if ( ! is_object( $dog_pet_house_breadcrumb ) ) {
		$dog_pet_house_breadcrumb = new Breadcrumb_Trail( $dog_pet_house_args );
	}

	return $dog_pet_house_breadcrumb->trail();
}

/**
 * Creates a breadcrumbs menu for the site based on the current page that's being viewed by the user.
 *
 * @since  0.6.0
 * @access public
 */
class Breadcrumb_Trail {

	/**
	 * Array of items belonging to the current breadcrumb trail.
	 *
	 * @since  0.1.0
	 * @access public
	 * @var    array
	 */
	public $items = array();

	/**
	 * Arguments used to build the breadcrumb trail.
	 *
	 * @since  0.1.0
	 * @access public
	 * @var    array
	 */
	public $dog_pet_house_args = array();

	/**
	 * Array of text labels.
	 *
	 * @since  1.0.0
	 * @access public
	 * @var    array
	 */
	public $dog_pet_house_labels = array();

	/**
	 * Array of post types (key) and taxonomies (value) to use for single post views.
	 *
	 * @since  1.0.0
	 * @access public
	 * @var    array
	 */
	public $dog_pet_house_post_taxonomy = array();

	public $labels;
    public $post_taxonomy;
	public $args;

	/* ====== Magic Methods ====== */

	/**
	 * Magic method to use in case someone tries to output the layout object as a string.
	 * We'll just return the trail HTML.
	 *
	 * @since  1.0.0
	 * @access public
	 * @return string
	 */
	public function __toString() {
		return $this->trail();
	}

	/**
	 * Sets up the breadcrumb trail properties.  Calls the `Breadcrumb_Trail::add_items()` method
	 * to creat the array of breadcrumb items.
	 *
	 * @since  0.6.0
	 * @access public
	 * @param  array $dog_pet_house_args  {
	 *     @type string    $container      Container HTML element. nav|div
	 *     @type string    $before         String to output before breadcrumb menu.
	 *     @type string    $after          String to output after breadcrumb menu.
	 *     @type string    $browse_tag     The HTML tag to use to wrap the "Browse" header text.
	 *     @type string    $list_tag       The HTML tag to use for the list wrapper.
	 *     @type string    $dog_pet_house_item_tag       The HTML tag to use for the item wrapper.
	 *     @type bool      $show_on_front  Whether to show when `is_front_page()`.
	 *     @type bool      $dog_pet_house_network        Whether to link to the network main site (multisite only).
	 *     @type bool      $show_title     Whether to show the title (last item) in the trail.
	 *     @type bool      $show_browse    Whether to show the breadcrumb menu header.
	 *     @type array     $dog_pet_house_labels         Text labels. @see Breadcrumb_Trail::set_labels()
	 *     @type array     $dog_pet_house_post_taxonomy  Taxonomies to use for post types. @see Breadcrumb_Trail::set_post_taxonomy()
	 *     @type bool      $echo           Whether to print or return the breadcrumbs.
	 * }
	 * @return void
	 */
	public function __construct( $dog_pet_house_args = array() ) {

		$dog_pet_house_defaults = array(
			'container'     => 'nav',
			'before'        => '',
			'after'         => '',
			'browse_tag'    => 'h2',
			'list_tag'      => 'ul',
			'item_tag'      => 'li',
			'show_on_front' => true,
			'network'       => false,
			'show_title'    => true,
			'show_browse'   => true,
			'labels'        => array(),
			'post_taxonomy' => array(),
			'echo'          => true,
		);

		// Parse the arguments with the deaults.
		$this->args = apply_filters( 'breadcrumb_trail_args', wp_parse_args( $dog_pet_house_args, $dog_pet_house_defaults ) );

		// Set the labels and post taxonomy properties.
		$this->set_labels();
		$this->set_post_taxonomy();

		// Let's find some items to add to the trail!
		$this->add_items();
	}

	/* ====== Public Methods ====== */

	/**
	 * Formats the HTML output for the breadcrumb trail.
	 *
	 * @since  0.6.0
	 * @access public
	 * @return string
	 */
	public function trail() {

		// Set up variables that we'll need.
		$dog_pet_house_breadcrumb    = '';
		$dog_pet_house_item_count    = count( $this->items );
		$dog_pet_house_item_position = 0;

		// Connect the breadcrumb trail if there are items in the trail.
		if ( 0 < $dog_pet_house_item_count ) {

			// Add 'browse' label if it should be shown.
			if ( true === $this->args['show_browse'] ) {

				$dog_pet_house_breadcrumb .= sprintf(
					'<%1$s class="trail-browse">%2$s</%1$s>',
					tag_escape( $this->args['browse_tag'] ),
					$this->labels['browse']
				);
			}

			// Open the unordered list.
			$dog_pet_house_breadcrumb .= sprintf(
				'<%s class="trail-items" itemscope itemtype="http://schema.org/BreadcrumbList">',
				tag_escape( $this->args['list_tag'] )
			);

			// Add the number of items and item list order schema.
			$dog_pet_house_breadcrumb .= sprintf( '<meta name="numberOfItems" content="%d" />', absint( $dog_pet_house_item_count ) );
			$dog_pet_house_breadcrumb .= '<meta name="itemListOrder" content="Ascending" />';

			// Loop through the items and add them to the list.
			foreach ( $this->items as $dog_pet_house_item ) {

				// Iterate the item position.
				++$dog_pet_house_item_position;

				// Check if the item is linked.
				preg_match( '/(<a.*?>)(.*?)(<\/a>)/i', $dog_pet_house_item, $dog_pet_house_matches );

				// Wrap the item text with appropriate itemprop.
				$dog_pet_house_item = ! empty( $dog_pet_house_matches ) ? sprintf( '%s<span itemprop="name">%s</span>%s', $dog_pet_house_matches[1], $dog_pet_house_matches[2], $dog_pet_house_matches[3] ) : sprintf( '<span itemprop="name">%s</span>', $dog_pet_house_item );

				// Wrap the item with its itemprop.
				$dog_pet_house_item = ! empty( $dog_pet_house_matches )
					? preg_replace( '/(<a.*?)([\'"])>/i', '$1$2 itemprop=$2item$2>', $dog_pet_house_item )
					: sprintf( '<span itemprop="item">%s</span>', $dog_pet_house_item );

				// Add list item classes.
				$dog_pet_house_item_class = 'trail-item';

				if ( 1 === $dog_pet_house_item_position && 1 < $dog_pet_house_item_count ) {
					$dog_pet_house_item_class .= ' trail-begin';

				} elseif ( $dog_pet_house_item_count === $dog_pet_house_item_position ) {
					$dog_pet_house_item_class .= ' trail-end';
				}

				// Create list item attributes.
				$dog_pet_house_attributes = 'itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem" class="' . $dog_pet_house_item_class . '"';

				// Build the meta position HTML.
				$dog_pet_house_meta = sprintf( '<meta itemprop="position" content="%s" />', absint( $dog_pet_house_item_position ) );

				// Build the list item.
				$dog_pet_house_breadcrumb .= sprintf( '<%1$s %2$s>%3$s%4$s</%1$s>', tag_escape( $this->args['item_tag'] ), $dog_pet_house_attributes, $dog_pet_house_item, $dog_pet_house_meta );
			}

			// Close the unordered list.
			$dog_pet_house_breadcrumb .= sprintf( '</%s>', tag_escape( $this->args['list_tag'] ) );

			// Wrap the breadcrumb trail.
			$dog_pet_house_breadcrumb = sprintf(
				'<%1$s role="navigation" aria-label="%2$s" class="breadcrumb-trail breadcrumbs" itemprop="breadcrumb">%3$s%4$s%5$s</%1$s>',
				tag_escape( $this->args['container'] ),
				esc_attr( $this->labels['aria_label'] ),
				$this->args['before'],
				$dog_pet_house_breadcrumb,
				$this->args['after']
			);
		}

		// Allow developers to filter the breadcrumb trail HTML.
		$dog_pet_house_breadcrumb = apply_filters( 'breadcrumb_trail', $dog_pet_house_breadcrumb, $this->args );

		if ( false === $this->args['echo'] ) {
			return $dog_pet_house_breadcrumb;
		}

		echo $dog_pet_house_breadcrumb;
	}

	/* ====== Protected Methods ====== */

	/**
	 * Sets the labels property.  Parses the inputted labels array with the defaults.
	 *
	 * @since  1.0.0
	 * @access protected
	 * @return void
	 */
	protected function set_labels() {

		$dog_pet_house_defaults = array(
			'browse'              => esc_html__( 'Browse:', 'dog-pet-house' ),
			'aria_label'          => esc_attr_x( 'Breadcrumbs', 'breadcrumbs aria label', 'dog-pet-house' ),
			'home'                => esc_html__( 'Home', 'dog-pet-house' ),
			'error_404'           => esc_html__( '404 Not Found', 'dog-pet-house' ),
			'archives'            => esc_html__( 'Archives', 'dog-pet-house' ),
			// Translators: %s is the search query.
			'search'              => esc_html__( 'Search results for: %s', 'dog-pet-house' ),
			// Translators: %s is the page number.
			'paged'               => esc_html__( 'Page %s', 'dog-pet-house' ),
			// Translators: %s is the page number.
			'paged_comments'      => esc_html__( 'Comment Page %s', 'dog-pet-house' ),
			// Translators: Minute archive title. %s is the minute time format.
			'archive_minute'      => esc_html__( 'Minute %s', 'dog-pet-house' ),
			// Translators: Weekly archive title. %s is the week date format.
			'archive_week'        => esc_html__( 'Week %s', 'dog-pet-house' ),

			// "%s" is replaced with the translated date/time format.
			'archive_minute_hour' => '%s',
			'archive_hour'        => '%s',
			'archive_day'         => '%s',
			'archive_month'       => '%s',
			'archive_year'        => '%s',
		);

		$this->labels = apply_filters( 'breadcrumb_trail_labels', wp_parse_args( $this->args['labels'], $dog_pet_house_defaults ) );
	}

	/**
	 * Sets the `$dog_pet_house_post_taxonomy` property.  This is an array of post types (key) and taxonomies (value).
	 * The taxonomy's terms are shown on the singular post view if set.
	 *
	 * @since  1.0.0
	 * @access protected
	 * @return void
	 */
	protected function set_post_taxonomy() {

		$dog_pet_house_defaults = array();

		// If post permalink is set to `%postname%`, use the `category` taxonomy.
		if ( '%postname%' === trim( get_option( 'permalink_structure' ), '/' ) ) {
			$dog_pet_house_defaults['post'] = 'category';
		}

		$this->post_taxonomy = apply_filters( 'breadcrumb_trail_post_taxonomy', wp_parse_args( $this->args['post_taxonomy'], $dog_pet_house_defaults ) );
	}

	/**
	 * Runs through the various WordPress conditional tags to check the current page being viewed.  Once
	 * a condition is met, a specific method is launched to add items to the `$items` array.
	 *
	 * @since  1.0.0
	 * @access protected
	 * @return void
	 */
	protected function add_items() {

		// If viewing the front page.
		if ( is_front_page() ) {
			$this->add_front_page_items();
		}

		// If not viewing the front page.
		else {

			// Add the network and site home links.
			$this->add_network_home_link();
			$this->add_site_home_link();

			// If viewing the home/blog page.
			if ( is_home() ) {
				$this->add_blog_items();
			}

			// If viewing a single post.
			elseif ( is_singular() ) {
				$this->add_singular_items();
			}

			// If viewing an archive page.
			elseif ( is_archive() ) {

				if ( is_post_type_archive() ) {
					$this->add_post_type_archive_items();

				} elseif ( is_category() || is_tag() || is_tax() ) {
					$this->add_term_archive_items();

				} elseif ( is_author() ) {
					$this->add_user_archive_items();

				} elseif ( get_query_var( 'minute' ) && get_query_var( 'hour' ) ) {
					$this->add_minute_hour_archive_items();

				} elseif ( get_query_var( 'minute' ) ) {
					$this->add_minute_archive_items();

				} elseif ( get_query_var( 'hour' ) ) {
					$this->add_hour_archive_items();

				} elseif ( is_day() ) {
					$this->add_day_archive_items();

				} elseif ( get_query_var( 'w' ) ) {
					$this->add_week_archive_items();

				} elseif ( is_month() ) {
					$this->add_month_archive_items();

				} elseif ( is_year() ) {
					$this->add_year_archive_items();

				} else {
					$this->add_default_archive_items();
				}
			}

			// If viewing a search results page.
			elseif ( is_search() ) {
				$this->add_search_items();
			}

			// If viewing the 404 page.
			elseif ( is_404() ) {
				$this->add_404_items();
			}
		}

		// Add paged items if they exist.
		$this->add_paged_items();

		// Allow developers to overwrite the items for the breadcrumb trail.
		$this->items = array_unique( apply_filters( 'breadcrumb_trail_items', $this->items, $this->args ) );
	}

	/**
	 * Gets front items based on $wp_rewrite->front.
	 *
	 * @since  1.0.0
	 * @access protected
	 * @return void
	 */
	protected function add_rewrite_front_items() {
		global $wp_rewrite;

		if ( $wp_rewrite->front ) {
			$this->add_path_parents( $wp_rewrite->front );
		}
	}

	/**
	 * Adds the page/paged number to the items array.
	 *
	 * @since  1.0.0
	 * @access protected
	 * @return void
	 */
	protected function add_paged_items() {

		// If viewing a paged singular post.
		if ( is_singular() && 1 < get_query_var( 'page' ) && true === $this->args['show_title'] ) {
			$this->items[] = sprintf( $this->labels['paged'], number_format_i18n( absint( get_query_var( 'page' ) ) ) );
		}

		// If viewing a singular post with paged comments.
		elseif ( is_singular() && get_option( 'page_comments' ) && 1 < get_query_var( 'cpage' ) ) {
			$this->items[] = sprintf( $this->labels['paged_comments'], number_format_i18n( absint( get_query_var( 'cpage' ) ) ) );
		}

		// If viewing a paged archive-type page.
		elseif ( is_paged() && true === $this->args['show_title'] ) {
			$this->items[] = sprintf( $this->labels['paged'], number_format_i18n( absint( get_query_var( 'paged' ) ) ) );
		}
	}

	/**
	 * Adds the network (all sites) home page link to the items array.
	 *
	 * @since  1.0.0
	 * @access protected
	 * @return void
	 */
	protected function add_network_home_link() {

		if ( is_multisite() && ! is_main_site() && true === $this->args['network'] ) {
			$this->items[] = sprintf( '<a href="%s" rel="home">%s</a>', esc_url( network_home_url() ), $this->labels['home'] );
		}
	}

	/**
	 * Adds the current site's home page link to the items array.
	 *
	 * @since  1.0.0
	 * @access protected
	 * @return void
	 */
	protected function add_site_home_link() {

		$dog_pet_house_network = is_multisite() && ! is_main_site() && true === $this->args['network'];
		$dog_pet_house_label   = $dog_pet_house_network ? get_bloginfo( 'name' ) : $this->labels['home'];
		$dog_pet_house_rel     = $dog_pet_house_network ? '' : ' rel="home"';

		$this->items[] = sprintf( '<a href="%s"%s>%s</a>', esc_url( user_trailingslashit( home_url() ) ), $dog_pet_house_rel, $dog_pet_house_label );
	}

	/**
	 * Adds items for the front page to the items array.
	 *
	 * @since  1.0.0
	 * @access protected
	 * @return void
	 */
	protected function add_front_page_items() {

		// Only show front items if the 'show_on_front' argument is set to 'true'.
		if ( true === $this->args['show_on_front'] || is_paged() || ( is_singular() && 1 < get_query_var( 'page' ) ) ) {

			// Add network home link.
			$this->add_network_home_link();

			// If on a paged view, add the site home link.
			if ( is_paged() ) {
				$this->add_site_home_link();
			}

			// If on the main front page, add the network home title.
			elseif ( true === $this->args['show_title'] ) {
				$this->items[] = is_multisite() && true === $this->args['network'] ? get_bloginfo( 'name' ) : $this->labels['home'];
			}
		}
	}

	/**
	 * Adds items for the posts page (i.e., is_home()) to the items array.
	 *
	 * @since  1.0.0
	 * @access protected
	 * @return void
	 */
	protected function add_blog_items() {

		// Get the post ID and post.
		$dog_pet_house_post_id = get_queried_object_id();
		$dog_pet_house_post    = get_post( $dog_pet_house_post_id );

		// If the post has parents, add them to the trail.
		if ( 0 < $dog_pet_house_post->post_parent ) {
			$this->add_post_parents( $dog_pet_house_post->post_parent );
		}

		// Get the page title.
		$dog_pet_house_title = get_the_title( $dog_pet_house_post_id );

		// Add the posts page item.
		if ( is_paged() ) {
			$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_permalink( $dog_pet_house_post_id ) ), $dog_pet_house_title );

		} elseif ( $dog_pet_house_title && true === $this->args['show_title'] ) {
			$this->items[] = $dog_pet_house_title;
		}
	}

	/**
	 * Adds singular post items to the items array.
	 *
	 * @since  1.0.0
	 * @access protected
	 * @return void
	 */
	protected function add_singular_items() {

		// Get the queried post.
		$dog_pet_house_post    = get_queried_object();
		$dog_pet_house_post_id = get_queried_object_id();

		// If the post has a parent, follow the parent trail.
		if ( 0 < $dog_pet_house_post->post_parent ) {
			$this->add_post_parents( $dog_pet_house_post->post_parent );
		}

		// If the post doesn't have a parent, get its hierarchy based off the post type.
		else {
			$this->add_post_hierarchy( $dog_pet_house_post_id );
		}

		// Display terms for specific post type taxonomy if requested.
		if ( ! empty( $this->post_taxonomy[ $dog_pet_house_post->post_type ] ) ) {
			$this->add_post_terms( $dog_pet_house_post_id, $this->post_taxonomy[ $dog_pet_house_post->post_type ] );
		}

		// End with the post title.
		if ( $dog_pet_house_post_title = single_post_title( '', false ) ) {

			if ( ( 1 < get_query_var( 'page' ) || is_paged() ) || ( get_option( 'page_comments' ) && 1 < absint( get_query_var( 'cpage' ) ) ) ) {
				$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_permalink( $dog_pet_house_post_id ) ), $dog_pet_house_post_title );

			} elseif ( true === $this->args['show_title'] ) {
				$this->items[] = $dog_pet_house_post_title;
			}
		}
	}

	/**
	 * Adds the items to the trail items array for taxonomy term archives.
	 *
	 * @since  1.0.0
	 * @access protected
	 * @global object $wp_rewrite
	 * @return void
	 */
	protected function add_term_archive_items() {
		global $wp_rewrite;

		// Get some taxonomy and term variables.
		$dog_pet_house_term           = get_queried_object();
		$dog_pet_house_taxonomy       = get_taxonomy( $dog_pet_house_term->taxonomy );
		$dog_pet_house_done_post_type = false;

		// If there are rewrite rules for the taxonomy.
		if ( false !== $dog_pet_house_taxonomy->rewrite ) {

			// If 'with_front' is true, dd $wp_rewrite->front to the trail.
			if ( $dog_pet_house_taxonomy->rewrite['with_front'] && $wp_rewrite->front ) {
				$this->add_rewrite_front_items();
			}

			// Get parent pages by path if they exist.
			$this->add_path_parents( $dog_pet_house_taxonomy->rewrite['slug'] );

			// Add post type archive if its 'has_archive' matches the taxonomy rewrite 'slug'.
			if ( $dog_pet_house_taxonomy->rewrite['slug'] ) {

				$dog_pet_house_slug = trim( $dog_pet_house_taxonomy->rewrite['slug'], '/' );

				// Deals with the situation if the slug has a '/' between multiple
				// strings. For example, "movies/genres" where "movies" is the post
				// type archive.
				$dog_pet_house_matches = explode( '/', $dog_pet_house_slug );

				// If matches are found for the path.
				if ( isset( $dog_pet_house_matches ) ) {

					// Reverse the array of matches to search for posts in the proper order.
					$dog_pet_house_matches = array_reverse( $dog_pet_house_matches );

					// Loop through each of the path matches.
					foreach ( $dog_pet_house_matches as $dog_pet_house_match ) {

						// If a match is found.
						$dog_pet_house_slug = $dog_pet_house_match;

						// Get public post types that match the rewrite slug.
						$dog_pet_house_post_types = $this->get_post_types_by_slug( $dog_pet_house_match );

						if ( ! empty( $dog_pet_house_post_types ) ) {

							$dog_pet_house_post_type_object = $dog_pet_house_post_types[0];

							// Add support for a non-standard label of 'archive_title' (special use case).
							$dog_pet_house_label = ! empty( $dog_pet_house_post_type_object->labels->archive_title ) ? $dog_pet_house_post_type_object->labels->archive_title : $dog_pet_house_post_type_object->labels->name;

							// Core filter hook.
							$dog_pet_house_label = apply_filters( 'post_type_archive_title', $dog_pet_house_label, $dog_pet_house_post_type_object->name );

							// Add the post type archive link to the trail.
							$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_post_type_archive_link( $dog_pet_house_post_type_object->name ) ), $dog_pet_house_label );

							$dog_pet_house_done_post_type = true;

							// Break out of the loop.
							break;
						}
					}
				}
			}
		}

		// If there's a single post type for the taxonomy, use it.
		if ( false === $dog_pet_house_done_post_type && 1 === count( $dog_pet_house_taxonomy->object_type ) && post_type_exists( $dog_pet_house_taxonomy->object_type[0] ) ) {

			// If the post type is 'post'.
			if ( 'post' === $dog_pet_house_taxonomy->object_type[0] ) {
				$dog_pet_house_post_id = get_option( 'page_for_posts' );

				if ( 'posts' !== get_option( 'show_on_front' ) && 0 < $dog_pet_house_post_id ) {
					$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_permalink( $dog_pet_house_post_id ) ), get_the_title( $dog_pet_house_post_id ) );
				}

				// If the post type is not 'post'.
			} else {
				$dog_pet_house_post_type_object = get_post_type_object( $dog_pet_house_taxonomy->object_type[0] );

				$dog_pet_house_label = ! empty( $dog_pet_house_post_type_object->labels->archive_title ) ? $dog_pet_house_post_type_object->labels->archive_title : $dog_pet_house_post_type_object->labels->name;

				// Core filter hook.
				$dog_pet_house_label = apply_filters( 'post_type_archive_title', $dog_pet_house_label, $dog_pet_house_post_type_object->name );

				$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_post_type_archive_link( $dog_pet_house_post_type_object->name ) ), $dog_pet_house_label );
			}
		}

		// If the taxonomy is hierarchical, list its parent terms.
		if ( is_taxonomy_hierarchical( $dog_pet_house_term->taxonomy ) && $dog_pet_house_term->parent ) {
			$this->add_term_parents( $dog_pet_house_term->parent, $dog_pet_house_term->taxonomy );
		}

		// Add the term name to the trail end.
		if ( is_paged() ) {
			$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_term_link( $dog_pet_house_term, $dog_pet_house_term->taxonomy ) ), single_term_title( '', false ) );

		} elseif ( true === $this->args['show_title'] ) {
			$this->items[] = single_term_title( '', false );
		}
	}

	/**
	 * Adds the items to the trail items array for post type archives.
	 *
	 * @since  1.0.0
	 * @access protected
	 * @return void
	 */
	protected function add_post_type_archive_items() {

		// Get the post type object.
		$dog_pet_house_post_type_object = get_post_type_object( get_query_var( 'post_type' ) );

		if ( false !== $dog_pet_house_post_type_object->rewrite ) {

			// If 'with_front' is true, add $wp_rewrite->front to the trail.
			if ( $dog_pet_house_post_type_object->rewrite['with_front'] ) {
				$this->add_rewrite_front_items();
			}

			// If there's a rewrite slug, check for parents.
			if ( ! empty( $dog_pet_house_post_type_object->rewrite['slug'] ) ) {
				$this->add_path_parents( $dog_pet_house_post_type_object->rewrite['slug'] );
			}
		}

		// Add the post type [plural] name to the trail end.
		if ( is_paged() || is_author() ) {
			$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_post_type_archive_link( $dog_pet_house_post_type_object->name ) ), post_type_archive_title( '', false ) );

		} elseif ( true === $this->args['show_title'] ) {
			$this->items[] = post_type_archive_title( '', false );
		}

		// If viewing a post type archive by author.
		if ( is_author() ) {
			$this->add_user_archive_items();
		}
	}

	/**
	 * Adds the items to the trail items array for user (author) archives.
	 *
	 * @since  1.0.0
	 * @access protected
	 * @global object $wp_rewrite
	 * @return void
	 */
	protected function add_user_archive_items() {
		global $wp_rewrite;

		// Add $wp_rewrite->front to the trail.
		$this->add_rewrite_front_items();

		// Get the user ID.
		$dog_pet_house_user_id = get_query_var( 'author' );

		// If $author_base exists, check for parent pages.
		if ( ! empty( $wp_rewrite->author_base ) && ! is_post_type_archive() ) {
			$this->add_path_parents( $wp_rewrite->author_base );
		}

		// Add the author's display name to the trail end.
		if ( is_paged() ) {
			$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_author_posts_url( $dog_pet_house_user_id ) ), get_the_author_meta( 'display_name', $dog_pet_house_user_id ) );

		} elseif ( true === $this->args['show_title'] ) {
			$this->items[] = get_the_author_meta( 'display_name', $dog_pet_house_user_id );
		}
	}

	/**
	 * Adds the items to the trail items array for minute + hour archives.
	 *
	 * @since  1.0.0
	 * @access protected
	 * @return void
	 */
	protected function add_minute_hour_archive_items() {

		// Add $wp_rewrite->front to the trail.
		$this->add_rewrite_front_items();

		// Add the minute + hour item.
		if ( true === $this->args['show_title'] ) {
			$this->items[] = sprintf( $this->labels['archive_minute_hour'], get_the_time( esc_html_x( 'g:i a', 'minute and hour archives time format', 'dog-pet-house' ) ) );
		}
	}

	/**
	 * Adds the items to the trail items array for minute archives.
	 *
	 * @since  1.0.0
	 * @access protected
	 * @return void
	 */
	protected function add_minute_archive_items() {

		// Add $wp_rewrite->front to the trail.
		$this->add_rewrite_front_items();

		// Add the minute item.
		if ( true === $this->args['show_title'] ) {
			$this->items[] = sprintf( $this->labels['archive_minute'], get_the_time( esc_html_x( 'i', 'minute archives time format', 'dog-pet-house' ) ) );
		}
	}

	/**
	 * Adds the items to the trail items array for hour archives.
	 *
	 * @since  1.0.0
	 * @access protected
	 * @return void
	 */
	protected function add_hour_archive_items() {

		// Add $wp_rewrite->front to the trail.
		$this->add_rewrite_front_items();

		// Add the hour item.
		if ( true === $this->args['show_title'] ) {
			$this->items[] = sprintf( $this->labels['archive_hour'], get_the_time( esc_html_x( 'g a', 'hour archives time format', 'dog-pet-house' ) ) );
		}
	}

	/**
	 * Adds the items to the trail items array for day archives.
	 *
	 * @since  1.0.0
	 * @access protected
	 * @return void
	 */
	protected function add_day_archive_items() {

		// Add $wp_rewrite->front to the trail.
		$this->add_rewrite_front_items();

		// Get year, month, and day.
		$dog_pet_house_year  = sprintf( $this->labels['archive_year'], get_the_time( esc_html_x( 'Y', 'yearly archives date format', 'dog-pet-house' ) ) );
		$dog_pet_house_month = sprintf( $this->labels['archive_month'], get_the_time( esc_html_x( 'F', 'monthly archives date format', 'dog-pet-house' ) ) );
		$dog_pet_house_day   = sprintf( $this->labels['archive_day'], get_the_time( esc_html_x( 'j', 'daily archives date format', 'dog-pet-house' ) ) );

		// Add the year and month items.
		$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_year_link( get_the_time( 'Y' ) ) ), $dog_pet_house_year );
		$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_month_link( get_the_time( 'Y' ), get_the_time( 'm' ) ) ), $dog_pet_house_month );

		// Add the day item.
		if ( is_paged() ) {
			$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_day_link( get_the_time( 'Y' ) ), get_the_time( 'm' ), get_the_time( 'd' ) ), $dog_pet_house_day );

		} elseif ( true === $this->args['show_title'] ) {
			$this->items[] = $dog_pet_house_day;
		}
	}

	/**
	 * Adds the items to the trail items array for week archives.
	 *
	 * @since  1.0.0
	 * @access protected
	 * @return void
	 */
	protected function add_week_archive_items() {

		// Add $wp_rewrite->front to the trail.
		$this->add_rewrite_front_items();

		// Get the year and week.
		$dog_pet_house_year = sprintf( $this->labels['archive_year'], get_the_time( esc_html_x( 'Y', 'yearly archives date format', 'dog-pet-house' ) ) );
		$dog_pet_house_week = sprintf( $this->labels['archive_week'], get_the_time( esc_html_x( 'W', 'weekly archives date format', 'dog-pet-house' ) ) );

		// Add the year item.
		$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_year_link( get_the_time( 'Y' ) ) ), $dog_pet_house_year );

		// Add the week item.
		if ( is_paged() ) {
			$this->items[] = esc_url(
				get_archives_link(
					add_query_arg(
						array(
							'm' => get_the_time( 'Y' ),
							'w' => get_the_time( 'W' ),
						),
						home_url()
					),
					$dog_pet_house_week,
					false
				)
			);

		} elseif ( true === $this->args['show_title'] ) {
			$this->items[] = $dog_pet_house_week;
		}
	}

	/**
	 * Adds the items to the trail items array for month archives.
	 *
	 * @since  1.0.0
	 * @access protected
	 * @return void
	 */
	protected function add_month_archive_items() {

		// Add $wp_rewrite->front to the trail.
		$this->add_rewrite_front_items();

		// Get the year and month.
		$dog_pet_house_year  = sprintf( $this->labels['archive_year'], get_the_time( esc_html_x( 'Y', 'yearly archives date format', 'dog-pet-house' ) ) );
		$dog_pet_house_month = sprintf( $this->labels['archive_month'], get_the_time( esc_html_x( 'F', 'monthly archives date format', 'dog-pet-house' ) ) );

		// Add the year item.
		$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_year_link( get_the_time( 'Y' ) ) ), $dog_pet_house_year );

		// Add the month item.
		if ( is_paged() ) {
			$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_month_link( get_the_time( 'Y' ), get_the_time( 'm' ) ) ), $dog_pet_house_month );

		} elseif ( true === $this->args['show_title'] ) {
			$this->items[] = $dog_pet_house_month;
		}
	}

	/**
	 * Adds the items to the trail items array for year archives.
	 *
	 * @since  1.0.0
	 * @access protected
	 * @return void
	 */
	protected function add_year_archive_items() {

		// Add $wp_rewrite->front to the trail.
		$this->add_rewrite_front_items();

		// Get the year.
		$dog_pet_house_year = sprintf( $this->labels['archive_year'], get_the_time( esc_html_x( 'Y', 'yearly archives date format', 'dog-pet-house' ) ) );

		// Add the year item.
		if ( is_paged() ) {
			$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_year_link( get_the_time( 'Y' ) ) ), $dog_pet_house_year );

		} elseif ( true === $this->args['show_title'] ) {
			$this->items[] = $dog_pet_house_year;
		}
	}

	/**
	 * Adds the items to the trail items array for archives that don't have a more specific method
	 * defined in this class.
	 *
	 * @since  1.0.0
	 * @access protected
	 * @return void
	 */
	protected function add_default_archive_items() {

		// If this is a date-/time-based archive, add $wp_rewrite->front to the trail.
		if ( is_date() || is_time() ) {
			$this->add_rewrite_front_items();
		}

		if ( true === $this->args['show_title'] ) {
			$this->items[] = $this->labels['archives'];
		}
	}

	/**
	 * Adds the items to the trail items array for search results.
	 *
	 * @since  1.0.0
	 * @access protected
	 * @return void
	 */
	protected function add_search_items() {

		if ( is_paged() ) {
			$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_search_link() ), sprintf( $this->labels['search'], get_search_query() ) );

		} elseif ( true === $this->args['show_title'] ) {
			$this->items[] = sprintf( $this->labels['search'], get_search_query() );
		}
	}

	/**
	 * Adds the items to the trail items array for 404 pages.
	 *
	 * @since  1.0.0
	 * @access protected
	 * @return void
	 */
	protected function add_404_items() {

		if ( true === $this->args['show_title'] ) {
			$this->items[] = $this->labels['error_404'];
		}
	}

	/**
	 * Adds a specific post's parents to the items array.
	 *
	 * @since  1.0.0
	 * @access protected
	 * @param  int $dog_pet_house_post_id
	 * @return void
	 */
	protected function add_post_parents( $dog_pet_house_post_id ) {
		$dog_pet_house_parents = array();

		while ( $dog_pet_house_post_id ) {

			// Get the post by ID.
			$dog_pet_house_post = get_post( $dog_pet_house_post_id );

			// If we hit a page that's set as the front page, bail.
			if ( 'page' == $dog_pet_house_post->post_type && 'page' == get_option( 'show_on_front' ) && $dog_pet_house_post_id == get_option( 'page_on_front' ) ) {
				break;
			}

			// Add the formatted post link to the array of parents.
			$dog_pet_house_parents[] = sprintf( '<a href="%s">%s</a>', esc_url( get_permalink( $dog_pet_house_post_id ) ), get_the_title( $dog_pet_house_post_id ) );

			// If there's no longer a post parent, break out of the loop.
			if ( 0 >= $dog_pet_house_post->post_parent ) {
				break;
			}

			// Change the post ID to the parent post to continue looping.
			$dog_pet_house_post_id = $dog_pet_house_post->post_parent;
		}

		// Get the post hierarchy based off the final parent post.
		$this->add_post_hierarchy( $dog_pet_house_post_id );

		// Display terms for specific post type taxonomy if requested.
		if ( ! empty( $this->post_taxonomy[ $dog_pet_house_post->post_type ] ) ) {
			$this->add_post_terms( $dog_pet_house_post_id, $this->post_taxonomy[ $dog_pet_house_post->post_type ] );
		}

		// Merge the parent items into the items array.
		$this->items = array_merge( $this->items, array_reverse( $dog_pet_house_parents ) );
	}

	/**
	 * Adds a specific post's hierarchy to the items array.  The hierarchy is determined by post type's
	 * rewrite arguments and whether it has an archive page.
	 *
	 * @since  1.0.0
	 * @access protected
	 * @param  int $dog_pet_house_post_id
	 * @return void
	 */
	protected function add_post_hierarchy( $dog_pet_house_post_id ) {

		// Get the post type.
		$dog_pet_house_post_type        = get_post_type( $dog_pet_house_post_id );
		$dog_pet_house_post_type_object = get_post_type_object( $dog_pet_house_post_type );

		// If this is the 'post' post type, get the rewrite front items and map the rewrite tags.
		if ( 'post' === $dog_pet_house_post_type ) {

			// Add $wp_rewrite->front to the trail.
			$this->add_rewrite_front_items();

			// Map the rewrite tags.
			$this->map_rewrite_tags( $dog_pet_house_post_id, get_option( 'permalink_structure' ) );
		}

		// If the post type has rewrite rules.
		elseif ( false !== $dog_pet_house_post_type_object->rewrite ) {

			// If 'with_front' is true, add $wp_rewrite->front to the trail.
			if ( $dog_pet_house_post_type_object->rewrite['with_front'] ) {
				$this->add_rewrite_front_items();
			}

			// If there's a path, check for parents.
			if ( ! empty( $dog_pet_house_post_type_object->rewrite['slug'] ) ) {
				$this->add_path_parents( $dog_pet_house_post_type_object->rewrite['slug'] );
			}
		}

		// If there's an archive page, add it to the trail.
		if ( $dog_pet_house_post_type_object->has_archive ) {

			// Add support for a non-standard label of 'archive_title' (special use case).
			$dog_pet_house_label = ! empty( $dog_pet_house_post_type_object->labels->archive_title ) ? $dog_pet_house_post_type_object->labels->archive_title : $dog_pet_house_post_type_object->labels->name;

			// Core filter hook.
			$dog_pet_house_label = apply_filters( 'post_type_archive_title', $dog_pet_house_label, $dog_pet_house_post_type_object->name );

			$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_post_type_archive_link( $dog_pet_house_post_type ) ), $dog_pet_house_label );
		}

		// Map the rewrite tags if there's a `%` in the slug.
		if ( 'post' !== $dog_pet_house_post_type && ! empty( $dog_pet_house_post_type_object->rewrite['slug'] ) && false !== strpos( $dog_pet_house_post_type_object->rewrite['slug'], '%' ) ) {
			$this->map_rewrite_tags( $dog_pet_house_post_id, $dog_pet_house_post_type_object->rewrite['slug'] );
		}
	}

	/**
	 * Gets post types by slug.  This is needed because the get_post_types() function doesn't exactly
	 * match the 'has_archive' argument when it's set as a string instead of a boolean.
	 *
	 * @since  0.6.0
	 * @access protected
	 * @param  int $dog_pet_house_slug  The post type archive slug to search for.
	 * @return void
	 */
	protected function get_post_types_by_slug( $dog_pet_house_slug ) {

		$dog_pet_house_return = array();

		$dog_pet_house_post_types = get_post_types( array(), 'objects' );

		foreach ( $dog_pet_house_post_types as $dog_pet_house_type ) {

			if ( $dog_pet_house_slug === $dog_pet_house_type->has_archive || ( true === $dog_pet_house_type->has_archive && $dog_pet_house_slug === $dog_pet_house_type->rewrite['slug'] ) ) {
				$dog_pet_house_return[] = $dog_pet_house_type;
			}
		}

		return $dog_pet_house_return;
	}

	/**
	 * Adds a post's terms from a specific taxonomy to the items array.
	 *
	 * @since  1.0.0
	 * @access protected
	 * @param  int    $dog_pet_house_post_id  The ID of the post to get the terms for.
	 * @param  string $dog_pet_house_taxonomy The taxonomy to get the terms from.
	 * @return void
	 */
	protected function add_post_terms( $dog_pet_house_post_id, $dog_pet_house_taxonomy ) {

		// Get the post type.
		$dog_pet_house_post_type = get_post_type( $dog_pet_house_post_id );

		// Get the post categories.
		$dog_pet_house_terms = get_the_terms( $dog_pet_house_post_id, $dog_pet_house_taxonomy );

		// Check that categories were returned.
		if ( $dog_pet_house_terms && ! is_wp_error( $dog_pet_house_terms ) ) {

			// Sort the terms by ID and get the first category.
			if ( function_exists( 'wp_list_sort' ) ) {
				$dog_pet_house_terms = wp_list_sort( $dog_pet_house_terms, 'term_id' );

			} else {
				usort( $dog_pet_house_terms, '_usort_terms_by_ID' );
			}

			$dog_pet_house_term = get_term( $dog_pet_house_terms[0], $dog_pet_house_taxonomy );

			// If the category has a parent, add the hierarchy to the trail.
			if ( 0 < $dog_pet_house_term->parent ) {
				$this->add_term_parents( $dog_pet_house_term->parent, $dog_pet_house_taxonomy );
			}

			// Add the category archive link to the trail.
			$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_term_link( $dog_pet_house_term, $dog_pet_house_taxonomy ) ), $dog_pet_house_term->name );
		}
	}

	/**
	 * Get parent posts by path.  Currently, this method only supports getting parents of the 'page'
	 * post type.  The goal of this function is to create a clear path back to home given what would
	 * normally be a "ghost" directory.  If any page matches the given path, it'll be added.
	 *
	 * @since  1.0.0
	 * @access protected
	 * @param  string $dog_pet_house_path The path (slug) to search for posts by.
	 * @return void
	 */
	function add_path_parents( $dog_pet_house_path ) {

		// Trim '/' off $dog_pet_house_path in case we just got a simple '/' instead of a real path.
		$dog_pet_house_path = trim( $dog_pet_house_path, '/' );

		// If there's no path, return.
		if ( empty( $dog_pet_house_path ) ) {
			return;
		}

		// Get parent post by the path.
		$dog_pet_house_post = get_page_by_path( $dog_pet_house_path );

		if ( ! empty( $dog_pet_house_post ) ) {
			$this->add_post_parents( $dog_pet_house_post->ID );
		} elseif ( is_null( $dog_pet_house_post ) ) {

			// Separate post names into separate paths by '/'.
			$dog_pet_house_path = trim( $dog_pet_house_path, '/' );
			preg_match_all( '/\/.*?\z/', $dog_pet_house_path, $dog_pet_house_matches );

			// If matches are found for the path.
			if ( isset( $dog_pet_house_matches ) ) {

				// Reverse the array of matches to search for posts in the proper order.
				$dog_pet_house_matches = array_reverse( $dog_pet_house_matches );

				// Loop through each of the path matches.
				foreach ( $dog_pet_house_matches as $dog_pet_house_match ) {

					// If a match is found.
					if ( isset( $dog_pet_house_match[0] ) ) {

						// Get the parent post by the given path.
						$dog_pet_house_path = str_replace( $dog_pet_house_match[0], '', $dog_pet_house_path );
						$dog_pet_house_post = get_page_by_path( trim( $dog_pet_house_path, '/' ) );

						// If a parent post is found, set the $dog_pet_house_post_id and break out of the loop.
						if ( ! empty( $dog_pet_house_post ) && 0 < $dog_pet_house_post->ID ) {
							$this->add_post_parents( $dog_pet_house_post->ID );
							break;
						}
					}
				}
			}
		}
	}

	/**
	 * Searches for term parents of hierarchical taxonomies.  This function is similar to the WordPress
	 * function get_category_parents() but handles any type of taxonomy.
	 *
	 * @since  1.0.0
	 * @param  int    $dog_pet_house_term_id  ID of the term to get the parents of.
	 * @param  string $dog_pet_house_taxonomy Name of the taxonomy for the given term.
	 * @return void
	 */
	function add_term_parents( $dog_pet_house_term_id, $dog_pet_house_taxonomy ) {

		// Set up some default arrays.
		$dog_pet_house_parents = array();

		// While there is a parent ID, add the parent term link to the $dog_pet_house_parents array.
		while ( $dog_pet_house_term_id ) {

			// Get the parent term.
			$dog_pet_house_term = get_term( $dog_pet_house_term_id, $dog_pet_house_taxonomy );

			// Add the formatted term link to the array of parent terms.
			$dog_pet_house_parents[] = sprintf( '<a href="%s">%s</a>', esc_url( get_term_link( $dog_pet_house_term, $dog_pet_house_taxonomy ) ), $dog_pet_house_term->name );

			// Set the parent term's parent as the parent ID.
			$dog_pet_house_term_id = $dog_pet_house_term->parent;
		}

		// If we have parent terms, reverse the array to put them in the proper order for the trail.
		if ( ! empty( $dog_pet_house_parents ) ) {
			$this->items = array_merge( $this->items, array_reverse( $dog_pet_house_parents ) );
		}
	}

	/**
	 * Turns %tag% from permalink structures into usable links for the breadcrumb trail.  This feels kind of
	 * hackish for now because we're checking for specific %tag% examples and only doing it for the 'post'
	 * post type.  In the future, maybe it'll handle a wider variety of possibilities, especially for custom post
	 * types.
	 *
	 * @since  0.6.0
	 * @access protected
	 * @param  int    $dog_pet_house_post_id ID of the post whose parents we want.
	 * @param  string $dog_pet_house_path    Path of a potential parent page.
	 * @param  array  $dog_pet_house_args    Mixed arguments for the menu.
	 * @return array
	 */
	protected function map_rewrite_tags( $dog_pet_house_post_id, $dog_pet_house_path ) {

		$dog_pet_house_post = get_post( $dog_pet_house_post_id );

		// Trim '/' from both sides of the $dog_pet_house_path.
		$dog_pet_house_path = trim( $dog_pet_house_path, '/' );

		// Split the $dog_pet_house_path into an array of strings.
		$dog_pet_house_matches = explode( '/', $dog_pet_house_path );

		// If matches are found for the path.
		if ( is_array( $dog_pet_house_matches ) ) {

			// Loop through each of the matches, adding each to the $trail array.
			foreach ( $dog_pet_house_matches as $dog_pet_house_match ) {

				// Trim any '/' from the $dog_pet_house_match.
				$dog_pet_house_tag = trim( $dog_pet_house_match, '/' );

				// If using the %year% tag, add a link to the yearly archive.
				if ( '%year%' == $dog_pet_house_tag ) {
					$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_year_link( get_the_time( 'Y', $dog_pet_house_post_id ) ) ), sprintf( $this->labels['archive_year'], get_the_time( esc_html_x( 'Y', 'yearly archives date format', 'dog-pet-house' ) ) ) );
				}

				// If using the %monthnum% tag, add a link to the monthly archive.
				elseif ( '%monthnum%' == $dog_pet_house_tag ) {
					$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_month_link( get_the_time( 'Y', $dog_pet_house_post_id ), get_the_time( 'm', $dog_pet_house_post_id ) ) ), sprintf( $this->labels['archive_month'], get_the_time( esc_html_x( 'F', 'monthly archives date format', 'dog-pet-house' ) ) ) );
				}

				// If using the %day% tag, add a link to the daily archive.
				elseif ( '%day%' == $dog_pet_house_tag ) {
					$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_day_link( get_the_time( 'Y', $dog_pet_house_post_id ), get_the_time( 'm', $dog_pet_house_post_id ), get_the_time( 'd', $dog_pet_house_post_id ) ) ), sprintf( $this->labels['archive_day'], get_the_time( esc_html_x( 'j', 'daily archives date format', 'dog-pet-house' ) ) ) );
				}

				// If using the %author% tag, add a link to the post author archive.
				elseif ( '%author%' == $dog_pet_house_tag ) {
					$this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_author_posts_url( $dog_pet_house_post->post_author ) ), get_the_author_meta( 'display_name', $dog_pet_house_post->post_author ) );
				}

				// If using the %category% tag, add a link to the first category archive to match permalinks.
				elseif ( taxonomy_exists( trim( $dog_pet_house_tag, '%' ) ) ) {

					// Force override terms in this post type.
					$this->post_taxonomy[ $dog_pet_house_post->post_type ] = false;

					// Add the post categories.
					$this->add_post_terms( $dog_pet_house_post_id, trim( $dog_pet_house_tag, '%' ) );
				}
			}
		}
	}
}