Advertisement
towfiqi

breadcrumbs-tail.php

Oct 2nd, 2019
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 41.19 KB | None | 0 0
  1. <?php
  2. /**
  3. * Breadcrumb Trail - A breadcrumb menu script for WordPress.
  4. *
  5. * Breadcrumb Trail is a script for showing a breadcrumb trail for any type of page. It tries to
  6. * anticipate any type of structure and display the best possible trail that matches your site's
  7. * permalink structure. While not perfect, it attempts to fill in the gaps left by many other
  8. * breadcrumb scripts.
  9. *
  10. * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
  11. * General Public License as published by the Free Software Foundation; either version 2 of the License,
  12. * or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
  15. * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16. *
  17. * @package BreadcrumbTrail
  18. * @version 1.1.0
  19. * @author Justin Tadlock <justin@justintadlock.com>
  20. * @copyright Copyright (c) 2008 - 2017, Justin Tadlock
  21. * @link https://themehybrid.com/plugins/breadcrumb-trail
  22. * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  23. */
  24.  
  25. /**
  26. * Shows a breadcrumb for all types of pages. This is a wrapper function for the Breadcrumb_Trail class,
  27. * which should be used in theme templates.
  28. *
  29. * @since 0.1.0
  30. * @access public
  31. * @param array $args Arguments to pass to Breadcrumb_Trail.
  32. * @return void
  33. */
  34. function breadcrumb_trail( $args = array() ) {
  35.  
  36. $breadcrumb = apply_filters( 'breadcrumb_trail_object', null, $args );
  37.  
  38. if ( ! is_object( $breadcrumb ) )
  39. $breadcrumb = new Breadcrumb_Trail( $args );
  40.  
  41. return $breadcrumb->trail();
  42. }
  43.  
  44. /**
  45. * Creates a breadcrumbs menu for the site based on the current page that's being viewed by the user.
  46. *
  47. * @since 0.6.0
  48. * @access public
  49. */
  50. class Breadcrumb_Trail {
  51.  
  52. /**
  53. * Array of items belonging to the current breadcrumb trail.
  54. *
  55. * @since 0.1.0
  56. * @access public
  57. * @var array
  58. */
  59. public $items = array();
  60.  
  61. /**
  62. * Arguments used to build the breadcrumb trail.
  63. *
  64. * @since 0.1.0
  65. * @access public
  66. * @var array
  67. */
  68. public $args = array();
  69.  
  70. /**
  71. * Array of text labels.
  72. *
  73. * @since 1.0.0
  74. * @access public
  75. * @var array
  76. */
  77. public $labels = array();
  78.  
  79. /**
  80. * Array of post types (key) and taxonomies (value) to use for single post views.
  81. *
  82. * @since 1.0.0
  83. * @access public
  84. * @var array
  85. */
  86. public $post_taxonomy = array();
  87.  
  88. /* ====== Magic Methods ====== */
  89.  
  90. /**
  91. * Magic method to use in case someone tries to output the layout object as a string.
  92. * We'll just return the trail HTML.
  93. *
  94. * @since 1.0.0
  95. * @access public
  96. * @return string
  97. */
  98. public function __toString() {
  99. return $this->trail();
  100. }
  101.  
  102. /**
  103. * Sets up the breadcrumb trail properties. Calls the `Breadcrumb_Trail::add_items()` method
  104. * to creat the array of breadcrumb items.
  105. *
  106. * @since 0.6.0
  107. * @access public
  108. * @param array $args {
  109. * @type string $container Container HTML element. nav|div
  110. * @type string $before String to output before breadcrumb menu.
  111. * @type string $after String to output after breadcrumb menu.
  112. * @type string $browse_tag The HTML tag to use to wrap the "Browse" header text.
  113. * @type string $list_tag The HTML tag to use for the list wrapper.
  114. * @type string $item_tag The HTML tag to use for the item wrapper.
  115. * @type bool $show_on_front Whether to show when `is_front_page()`.
  116. * @type bool $network Whether to link to the network main site (multisite only).
  117. * @type bool $show_title Whether to show the title (last item) in the trail.
  118. * @type bool $show_browse Whether to show the breadcrumb menu header.
  119. * @type array $labels Text labels. @see Breadcrumb_Trail::set_labels()
  120. * @type array $post_taxonomy Taxonomies to use for post types. @see Breadcrumb_Trail::set_post_taxonomy()
  121. * @type bool $echo Whether to print or return the breadcrumbs.
  122. * }
  123. * @return void
  124. */
  125. public function __construct( $args = array() ) {
  126.  
  127. $defaults = array(
  128. 'container' => 'nav',
  129. 'before' => '',
  130. 'after' => '',
  131. 'browse_tag' => 'h2',
  132. 'list_tag' => 'ul',
  133. 'item_tag' => 'li',
  134. 'show_on_front' => true,
  135. 'network' => false,
  136. 'show_title' => true,
  137. 'show_browse' => true,
  138. 'labels' => array(),
  139. 'post_taxonomy' => array(),
  140. 'echo' => true
  141. );
  142.  
  143. // Parse the arguments with the deaults.
  144. $this->args = apply_filters( 'breadcrumb_trail_args', wp_parse_args( $args, $defaults ) );
  145.  
  146. // Set the labels and post taxonomy properties.
  147. $this->set_labels();
  148. $this->set_post_taxonomy();
  149.  
  150. // Let's find some items to add to the trail!
  151. $this->add_items();
  152. }
  153.  
  154. /* ====== Public Methods ====== */
  155.  
  156. /**
  157. * Formats the HTML output for the breadcrumb trail.
  158. *
  159. * @since 0.6.0
  160. * @access public
  161. * @return string
  162. */
  163. public function trail() {
  164.  
  165. // Set up variables that we'll need.
  166. $breadcrumb = '';
  167. $item_count = count( $this->items );
  168. $item_position = 0;
  169.  
  170. // Connect the breadcrumb trail if there are items in the trail.
  171. if ( 0 < $item_count ) {
  172.  
  173. // Add 'browse' label if it should be shown.
  174. if ( true === $this->args['show_browse'] ) {
  175.  
  176. $breadcrumb .= sprintf(
  177. '<%1$s class="trail-browse">%2$s</%1$s>',
  178. tag_escape( $this->args['browse_tag'] ),
  179. $this->labels['browse']
  180. );
  181. }
  182.  
  183. // Open the unordered list.
  184. $breadcrumb .= sprintf(
  185. '<%s class="trail-items" itemscope itemtype="http://schema.org/BreadcrumbList">',
  186. tag_escape( $this->args['list_tag'] )
  187. );
  188.  
  189. // Add the number of items and item list order schema.
  190. $breadcrumb .= sprintf( '<meta name="numberOfItems" content="%d" />', absint( $item_count ) );
  191. $breadcrumb .= '<meta name="itemListOrder" content="Ascending" />';
  192.  
  193. // Loop through the items and add them to the list.
  194. foreach ( $this->items as $item ) {
  195.  
  196. // Iterate the item position.
  197. ++$item_position;
  198.  
  199. // Check if the item is linked.
  200. preg_match( '/(<a.*?>)(.*?)(<\/a>)/i', $item, $matches );
  201.  
  202.  
  203. preg_match('/^<a.*?href=(["\'])(.*?)\1.*$/', $item, $m);
  204. $itemUrl = $m[2] ? $m[2] : '';
  205.  
  206. // Wrap the item text with appropriate itemprop.
  207. $item = ! empty( $matches ) ? sprintf( '%s<span itemprop="name">%s</span>%s', $matches[1], $matches[2], $matches[3] ) : sprintf( '<span itemprop="name">%s</span>', $item );
  208.  
  209. // Wrap the item with its itemprop.
  210. $item = ! empty( $matches )
  211. ? preg_replace( '/(<a.*?)([\'"])>/i', '$1$2 itemprop=$2item$2>', $item )
  212. : sprintf( '<span>%s</span>', $item );
  213.  
  214. // Add list item classes.
  215. $item_class = 'trail-item';
  216.  
  217. if ( 1 === $item_position && 1 < $item_count )
  218. $item_class .= ' trail-begin';
  219.  
  220. elseif ( $item_count === $item_position )
  221. $item_class .= ' trail-end';
  222.  
  223. // Create list item attributes.
  224. $attributes = 'itemprop="itemListElement" itemscope itemtype="http://schema.org/ListItem" class="' . $item_class . '"';
  225.  
  226. // Build the meta position HTML.
  227. $meta = sprintf( '<meta itemprop="position" content="%s" />', absint( $item_position ) );
  228.  
  229.  
  230. $itemN = $itemUrl ? sprintf( '<meta itemprop="item" content="%s" />', esc_url( $itemUrl ) ) : '';
  231.  
  232.  
  233. // Build the list item.
  234. $breadcrumb .= sprintf( '<%1$s %2$s>%3$s%4$s%5$s</%1$s>', tag_escape( $this->args['item_tag'] ),$attributes, $item, $meta, $itemN );
  235. }
  236.  
  237. // Close the unordered list.
  238. $breadcrumb .= sprintf( '</%s>', tag_escape( $this->args['list_tag'] ) );
  239.  
  240. // Wrap the breadcrumb trail.
  241. $breadcrumb = sprintf(
  242. '<%1$s role="navigation" aria-label="%2$s" class="breadcrumb-trail breadcrumbs" itemprop="breadcrumb">%3$s%4$s%5$s</%1$s>',
  243. tag_escape( $this->args['container'] ),
  244. esc_attr( $this->labels['aria_label'] ),
  245. $this->args['before'],
  246. $breadcrumb,
  247. $this->args['after']
  248. );
  249. }
  250.  
  251. // Allow developers to filter the breadcrumb trail HTML.
  252. $breadcrumb = apply_filters( 'breadcrumb_trail', $breadcrumb, $this->args );
  253.  
  254. if ( false === $this->args['echo'] )
  255. return $breadcrumb;
  256.  
  257. echo $breadcrumb;
  258. }
  259.  
  260. /* ====== Protected Methods ====== */
  261.  
  262. /**
  263. * Sets the labels property. Parses the inputted labels array with the defaults.
  264. *
  265. * @since 1.0.0
  266. * @access protected
  267. * @return void
  268. */
  269. protected function set_labels() {
  270.  
  271. $defaults = array(
  272. 'browse' => esc_html__( 'Browse:', 'breadcrumb-trail' ),
  273. 'aria_label' => esc_attr_x( 'Breadcrumbs', 'breadcrumbs aria label', 'breadcrumb-trail' ),
  274. 'home' => esc_html__( 'Home', 'breadcrumb-trail' ),
  275. 'error_404' => esc_html__( '404 Not Found', 'breadcrumb-trail' ),
  276. 'archives' => esc_html__( 'Archives', 'breadcrumb-trail' ),
  277. // Translators: %s is the search query.
  278. 'search' => esc_html__( 'Search results for: %s', 'breadcrumb-trail' ),
  279. // Translators: %s is the page number.
  280. 'paged' => esc_html__( 'Page %s', 'breadcrumb-trail' ),
  281. // Translators: %s is the page number.
  282. 'paged_comments' => esc_html__( 'Comment Page %s', 'breadcrumb-trail' ),
  283. // Translators: Minute archive title. %s is the minute time format.
  284. 'archive_minute' => esc_html__( 'Minute %s', 'breadcrumb-trail' ),
  285. // Translators: Weekly archive title. %s is the week date format.
  286. 'archive_week' => esc_html__( 'Week %s', 'breadcrumb-trail' ),
  287.  
  288. // "%s" is replaced with the translated date/time format.
  289. 'archive_minute_hour' => '%s',
  290. 'archive_hour' => '%s',
  291. 'archive_day' => '%s',
  292. 'archive_month' => '%s',
  293. 'archive_year' => '%s',
  294. );
  295.  
  296. $this->labels = apply_filters( 'breadcrumb_trail_labels', wp_parse_args( $this->args['labels'], $defaults ) );
  297. }
  298.  
  299. /**
  300. * Sets the `$post_taxonomy` property. This is an array of post types (key) and taxonomies (value).
  301. * The taxonomy's terms are shown on the singular post view if set.
  302. *
  303. * @since 1.0.0
  304. * @access protected
  305. * @return void
  306. */
  307. protected function set_post_taxonomy() {
  308.  
  309. $defaults = array();
  310.  
  311. // If post permalink is set to `%postname%`, use the `category` taxonomy.
  312. if ( '%postname%' === trim( get_option( 'permalink_structure' ), '/' ) )
  313. $defaults['post'] = 'category';
  314.  
  315. $this->post_taxonomy = apply_filters( 'breadcrumb_trail_post_taxonomy', wp_parse_args( $this->args['post_taxonomy'], $defaults ) );
  316. }
  317.  
  318. /**
  319. * Runs through the various WordPress conditional tags to check the current page being viewed. Once
  320. * a condition is met, a specific method is launched to add items to the `$items` array.
  321. *
  322. * @since 1.0.0
  323. * @access protected
  324. * @return void
  325. */
  326. protected function add_items() {
  327.  
  328. // If viewing the front page.
  329. if ( is_front_page() ) {
  330. $this->add_front_page_items();
  331. }
  332.  
  333. // If not viewing the front page.
  334. else {
  335.  
  336. // Add the network and site home links.
  337. $this->add_network_home_link();
  338. $this->add_site_home_link();
  339.  
  340. // If viewing the home/blog page.
  341. if ( is_home() ) {
  342. $this->add_blog_items();
  343. }
  344.  
  345. // If viewing a single post.
  346. elseif ( is_singular() ) {
  347. $this->add_singular_items();
  348. }
  349.  
  350. // If viewing an archive page.
  351. elseif ( is_archive() ) {
  352.  
  353. if ( is_post_type_archive() )
  354. $this->add_post_type_archive_items();
  355.  
  356. elseif ( is_category() || is_tag() || is_tax() )
  357. $this->add_term_archive_items();
  358.  
  359. elseif ( is_author() )
  360. $this->add_user_archive_items();
  361.  
  362. elseif ( get_query_var( 'minute' ) && get_query_var( 'hour' ) )
  363. $this->add_minute_hour_archive_items();
  364.  
  365. elseif ( get_query_var( 'minute' ) )
  366. $this->add_minute_archive_items();
  367.  
  368. elseif ( get_query_var( 'hour' ) )
  369. $this->add_hour_archive_items();
  370.  
  371. elseif ( is_day() )
  372. $this->add_day_archive_items();
  373.  
  374. elseif ( get_query_var( 'w' ) )
  375. $this->add_week_archive_items();
  376.  
  377. elseif ( is_month() )
  378. $this->add_month_archive_items();
  379.  
  380. elseif ( is_year() )
  381. $this->add_year_archive_items();
  382.  
  383. else
  384. $this->add_default_archive_items();
  385. }
  386.  
  387. // If viewing a search results page.
  388. elseif ( is_search() ) {
  389. $this->add_search_items();
  390. }
  391.  
  392. // If viewing the 404 page.
  393. elseif ( is_404() ) {
  394. $this->add_404_items();
  395. }
  396. }
  397.  
  398. // Add paged items if they exist.
  399. $this->add_paged_items();
  400.  
  401. // Allow developers to overwrite the items for the breadcrumb trail.
  402. $this->items = array_unique( apply_filters( 'breadcrumb_trail_items', $this->items, $this->args ) );
  403. }
  404.  
  405. /**
  406. * Gets front items based on $wp_rewrite->front.
  407. *
  408. * @since 1.0.0
  409. * @access protected
  410. * @return void
  411. */
  412. protected function add_rewrite_front_items() {
  413. global $wp_rewrite;
  414.  
  415. if ( $wp_rewrite->front )
  416. $this->add_path_parents( $wp_rewrite->front );
  417. }
  418.  
  419. /**
  420. * Adds the page/paged number to the items array.
  421. *
  422. * @since 1.0.0
  423. * @access protected
  424. * @return void
  425. */
  426. protected function add_paged_items() {
  427.  
  428. // If viewing a paged singular post.
  429. if ( is_singular() && 1 < get_query_var( 'page' ) && true === $this->args['show_title'] )
  430. $this->items[] = sprintf( $this->labels['paged'], number_format_i18n( absint( get_query_var( 'page' ) ) ) );
  431.  
  432. // If viewing a singular post with paged comments.
  433. elseif ( is_singular() && get_option( 'page_comments' ) && 1 < get_query_var( 'cpage' ) )
  434. $this->items[] = sprintf( $this->labels['paged_comments'], number_format_i18n( absint( get_query_var( 'cpage' ) ) ) );
  435.  
  436. // If viewing a paged archive-type page.
  437. elseif ( is_paged() && true === $this->args['show_title'] )
  438. $this->items[] = sprintf( $this->labels['paged'], number_format_i18n( absint( get_query_var( 'paged' ) ) ) );
  439. }
  440.  
  441. /**
  442. * Adds the network (all sites) home page link to the items array.
  443. *
  444. * @since 1.0.0
  445. * @access protected
  446. * @return void
  447. */
  448. protected function add_network_home_link() {
  449.  
  450. if ( is_multisite() && ! is_main_site() && true === $this->args['network'] )
  451. $this->items[] = sprintf( '<a href="%s" rel="home">%s</a>', esc_url( network_home_url() ), $this->labels['home'] );
  452. }
  453.  
  454. /**
  455. * Adds the current site's home page link to the items array.
  456. *
  457. * @since 1.0.0
  458. * @access protected
  459. * @return void
  460. */
  461. protected function add_site_home_link() {
  462.  
  463. $network = is_multisite() && ! is_main_site() && true === $this->args['network'];
  464. $label = $network ? get_bloginfo( 'name' ) : $this->labels['home'];
  465. $rel = $network ? '' : ' rel="home"';
  466.  
  467. $this->items[] = sprintf( '<a href="%s"%s>%s</a>', esc_url( user_trailingslashit( home_url() ) ), $rel, $label );
  468. }
  469.  
  470. /**
  471. * Adds items for the front page to the items array.
  472. *
  473. * @since 1.0.0
  474. * @access protected
  475. * @return void
  476. */
  477. protected function add_front_page_items() {
  478.  
  479. // Only show front items if the 'show_on_front' argument is set to 'true'.
  480. if ( true === $this->args['show_on_front'] || is_paged() || ( is_singular() && 1 < get_query_var( 'page' ) ) ) {
  481.  
  482. // Add network home link.
  483. $this->add_network_home_link();
  484.  
  485. // If on a paged view, add the site home link.
  486. if ( is_paged() )
  487. $this->add_site_home_link();
  488.  
  489. // If on the main front page, add the network home title.
  490. elseif ( true === $this->args['show_title'] )
  491. $this->items[] = is_multisite() && true === $this->args['network'] ? get_bloginfo( 'name' ) : $this->labels['home'];
  492. }
  493. }
  494.  
  495. /**
  496. * Adds items for the posts page (i.e., is_home()) to the items array.
  497. *
  498. * @since 1.0.0
  499. * @access protected
  500. * @return void
  501. */
  502. protected function add_blog_items() {
  503.  
  504. // Get the post ID and post.
  505. $post_id = get_queried_object_id();
  506. $post = get_post( $post_id );
  507.  
  508. // If the post has parents, add them to the trail.
  509. if ( 0 < $post->post_parent )
  510. $this->add_post_parents( $post->post_parent );
  511.  
  512. // Get the page title.
  513. $title = get_the_title( $post_id );
  514.  
  515. // Add the posts page item.
  516. if ( is_paged() )
  517. $this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_permalink( $post_id ) ), $title );
  518.  
  519. elseif ( $title && true === $this->args['show_title'] )
  520. $this->items[] = $title;
  521. }
  522.  
  523. /**
  524. * Adds singular post items to the items array.
  525. *
  526. * @since 1.0.0
  527. * @access protected
  528. * @return void
  529. */
  530. protected function add_singular_items() {
  531.  
  532. // Get the queried post.
  533. $post = get_queried_object();
  534. $post_id = get_queried_object_id();
  535.  
  536. // If the post has a parent, follow the parent trail.
  537. if ( 0 < $post->post_parent )
  538. $this->add_post_parents( $post->post_parent );
  539.  
  540. // If the post doesn't have a parent, get its hierarchy based off the post type.
  541. else
  542. $this->add_post_hierarchy( $post_id );
  543.  
  544. // Display terms for specific post type taxonomy if requested.
  545. if ( ! empty( $this->post_taxonomy[ $post->post_type ] ) )
  546. $this->add_post_terms( $post_id, $this->post_taxonomy[ $post->post_type ] );
  547.  
  548. // End with the post title.
  549. if ( $post_title = single_post_title( '', false ) ) {
  550.  
  551. if ( ( 1 < get_query_var( 'page' ) || is_paged() ) || ( get_option( 'page_comments' ) && 1 < absint( get_query_var( 'cpage' ) ) ) )
  552. $this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_permalink( $post_id ) ), $post_title );
  553.  
  554. elseif ( true === $this->args['show_title'] )
  555. $this->items[] = $post_title;
  556. }
  557. }
  558.  
  559. /**
  560. * Adds the items to the trail items array for taxonomy term archives.
  561. *
  562. * @since 1.0.0
  563. * @access protected
  564. * @global object $wp_rewrite
  565. * @return void
  566. */
  567. protected function add_term_archive_items() {
  568. global $wp_rewrite;
  569.  
  570. // Get some taxonomy and term variables.
  571. $term = get_queried_object();
  572. $taxonomy = get_taxonomy( $term->taxonomy );
  573. $done_post_type = false;
  574.  
  575. // If there are rewrite rules for the taxonomy.
  576. if ( false !== $taxonomy->rewrite ) {
  577.  
  578. // If 'with_front' is true, dd $wp_rewrite->front to the trail.
  579. if ( $taxonomy->rewrite['with_front'] && $wp_rewrite->front )
  580. $this->add_rewrite_front_items();
  581.  
  582. // Get parent pages by path if they exist.
  583. $this->add_path_parents( $taxonomy->rewrite['slug'] );
  584.  
  585. // Add post type archive if its 'has_archive' matches the taxonomy rewrite 'slug'.
  586. if ( $taxonomy->rewrite['slug'] ) {
  587.  
  588. $slug = trim( $taxonomy->rewrite['slug'], '/' );
  589.  
  590. // Deals with the situation if the slug has a '/' between multiple
  591. // strings. For example, "movies/genres" where "movies" is the post
  592. // type archive.
  593. $matches = explode( '/', $slug );
  594.  
  595. // If matches are found for the path.
  596. if ( isset( $matches ) ) {
  597.  
  598. // Reverse the array of matches to search for posts in the proper order.
  599. $matches = array_reverse( $matches );
  600.  
  601. // Loop through each of the path matches.
  602. foreach ( $matches as $match ) {
  603.  
  604. // If a match is found.
  605. $slug = $match;
  606.  
  607. // Get public post types that match the rewrite slug.
  608. $post_types = $this->get_post_types_by_slug( $match );
  609.  
  610. if ( ! empty( $post_types ) ) {
  611.  
  612. $post_type_object = $post_types[0];
  613.  
  614. // Add support for a non-standard label of 'archive_title' (special use case).
  615. $label = ! empty( $post_type_object->labels->archive_title ) ? $post_type_object->labels->archive_title : $post_type_object->labels->name;
  616.  
  617. // Core filter hook.
  618. $label = apply_filters( 'post_type_archive_title', $label, $post_type_object->name );
  619.  
  620. // Add the post type archive link to the trail.
  621. $this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_post_type_archive_link( $post_type_object->name ) ), $label );
  622.  
  623. $done_post_type = true;
  624.  
  625. // Break out of the loop.
  626. break;
  627. }
  628. }
  629. }
  630. }
  631. }
  632.  
  633. // If there's a single post type for the taxonomy, use it.
  634. if ( false === $done_post_type && 1 === count( $taxonomy->object_type ) && post_type_exists( $taxonomy->object_type[0] ) ) {
  635.  
  636. // If the post type is 'post'.
  637. if ( 'post' === $taxonomy->object_type[0] ) {
  638. $post_id = get_option( 'page_for_posts' );
  639.  
  640. if ( 'posts' !== get_option( 'show_on_front' ) && 0 < $post_id )
  641. $this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_permalink( $post_id ) ), get_the_title( $post_id ) );
  642.  
  643. // If the post type is not 'post'.
  644. } else {
  645. $post_type_object = get_post_type_object( $taxonomy->object_type[0] );
  646.  
  647. $label = ! empty( $post_type_object->labels->archive_title ) ? $post_type_object->labels->archive_title : $post_type_object->labels->name;
  648.  
  649. // Core filter hook.
  650. $label = apply_filters( 'post_type_archive_title', $label, $post_type_object->name );
  651.  
  652. $this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_post_type_archive_link( $post_type_object->name ) ), $label );
  653. }
  654. }
  655.  
  656. // If the taxonomy is hierarchical, list its parent terms.
  657. if ( is_taxonomy_hierarchical( $term->taxonomy ) && $term->parent )
  658. $this->add_term_parents( $term->parent, $term->taxonomy );
  659.  
  660. // Add the term name to the trail end.
  661. if ( is_paged() )
  662. $this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_term_link( $term, $term->taxonomy ) ), single_term_title( '', false ) );
  663.  
  664. elseif ( true === $this->args['show_title'] )
  665. $this->items[] = single_term_title( '', false );
  666. }
  667.  
  668. /**
  669. * Adds the items to the trail items array for post type archives.
  670. *
  671. * @since 1.0.0
  672. * @access protected
  673. * @return void
  674. */
  675. protected function add_post_type_archive_items() {
  676.  
  677. // Get the post type object.
  678. $post_type_object = get_post_type_object( get_query_var( 'post_type' ) );
  679.  
  680. if ( false !== $post_type_object->rewrite ) {
  681.  
  682. // If 'with_front' is true, add $wp_rewrite->front to the trail.
  683. if ( $post_type_object->rewrite['with_front'] )
  684. $this->add_rewrite_front_items();
  685.  
  686. // If there's a rewrite slug, check for parents.
  687. if ( ! empty( $post_type_object->rewrite['slug'] ) )
  688. $this->add_path_parents( $post_type_object->rewrite['slug'] );
  689. }
  690.  
  691. // Add the post type [plural] name to the trail end.
  692. if ( is_paged() || is_author() )
  693. $this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_post_type_archive_link( $post_type_object->name ) ), post_type_archive_title( '', false ) );
  694.  
  695. elseif ( true === $this->args['show_title'] )
  696. $this->items[] = post_type_archive_title( '', false );
  697.  
  698. // If viewing a post type archive by author.
  699. if ( is_author() )
  700. $this->add_user_archive_items();
  701. }
  702.  
  703. /**
  704. * Adds the items to the trail items array for user (author) archives.
  705. *
  706. * @since 1.0.0
  707. * @access protected
  708. * @global object $wp_rewrite
  709. * @return void
  710. */
  711. protected function add_user_archive_items() {
  712. global $wp_rewrite;
  713.  
  714. // Add $wp_rewrite->front to the trail.
  715. $this->add_rewrite_front_items();
  716.  
  717. // Get the user ID.
  718. $user_id = get_query_var( 'author' );
  719.  
  720. // If $author_base exists, check for parent pages.
  721. if ( ! empty( $wp_rewrite->author_base ) && ! is_post_type_archive() )
  722. $this->add_path_parents( $wp_rewrite->author_base );
  723.  
  724. // Add the author's display name to the trail end.
  725. if ( is_paged() )
  726. $this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_author_posts_url( $user_id ) ), get_the_author_meta( 'display_name', $user_id ) );
  727.  
  728. elseif ( true === $this->args['show_title'] )
  729. $this->items[] = get_the_author_meta( 'display_name', $user_id );
  730. }
  731.  
  732. /**
  733. * Adds the items to the trail items array for minute + hour archives.
  734. *
  735. * @since 1.0.0
  736. * @access protected
  737. * @return void
  738. */
  739. protected function add_minute_hour_archive_items() {
  740.  
  741. // Add $wp_rewrite->front to the trail.
  742. $this->add_rewrite_front_items();
  743.  
  744. // Add the minute + hour item.
  745. if ( true === $this->args['show_title'] )
  746. $this->items[] = sprintf( $this->labels['archive_minute_hour'], get_the_time( esc_html_x( 'g:i a', 'minute and hour archives time format', 'breadcrumb-trail' ) ) );
  747. }
  748.  
  749. /**
  750. * Adds the items to the trail items array for minute archives.
  751. *
  752. * @since 1.0.0
  753. * @access protected
  754. * @return void
  755. */
  756. protected function add_minute_archive_items() {
  757.  
  758. // Add $wp_rewrite->front to the trail.
  759. $this->add_rewrite_front_items();
  760.  
  761. // Add the minute item.
  762. if ( true === $this->args['show_title'] )
  763. $this->items[] = sprintf( $this->labels['archive_minute'], get_the_time( esc_html_x( 'i', 'minute archives time format', 'breadcrumb-trail' ) ) );
  764. }
  765.  
  766. /**
  767. * Adds the items to the trail items array for hour archives.
  768. *
  769. * @since 1.0.0
  770. * @access protected
  771. * @return void
  772. */
  773. protected function add_hour_archive_items() {
  774.  
  775. // Add $wp_rewrite->front to the trail.
  776. $this->add_rewrite_front_items();
  777.  
  778. // Add the hour item.
  779. if ( true === $this->args['show_title'] )
  780. $this->items[] = sprintf( $this->labels['archive_hour'], get_the_time( esc_html_x( 'g a', 'hour archives time format', 'breadcrumb-trail' ) ) );
  781. }
  782.  
  783. /**
  784. * Adds the items to the trail items array for day archives.
  785. *
  786. * @since 1.0.0
  787. * @access protected
  788. * @return void
  789. */
  790. protected function add_day_archive_items() {
  791.  
  792. // Add $wp_rewrite->front to the trail.
  793. $this->add_rewrite_front_items();
  794.  
  795. // Get year, month, and day.
  796. $year = sprintf( $this->labels['archive_year'], get_the_time( esc_html_x( 'Y', 'yearly archives date format', 'breadcrumb-trail' ) ) );
  797. $month = sprintf( $this->labels['archive_month'], get_the_time( esc_html_x( 'F', 'monthly archives date format', 'breadcrumb-trail' ) ) );
  798. $day = sprintf( $this->labels['archive_day'], get_the_time( esc_html_x( 'j', 'daily archives date format', 'breadcrumb-trail' ) ) );
  799.  
  800. // Add the year and month items.
  801. $this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_year_link( get_the_time( 'Y' ) ) ), $year );
  802. $this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_month_link( get_the_time( 'Y' ), get_the_time( 'm' ) ) ), $month );
  803.  
  804. // Add the day item.
  805. if ( is_paged() )
  806. $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' ) ), $day );
  807.  
  808. elseif ( true === $this->args['show_title'] )
  809. $this->items[] = $day;
  810. }
  811.  
  812. /**
  813. * Adds the items to the trail items array for week archives.
  814. *
  815. * @since 1.0.0
  816. * @access protected
  817. * @return void
  818. */
  819. protected function add_week_archive_items() {
  820.  
  821. // Add $wp_rewrite->front to the trail.
  822. $this->add_rewrite_front_items();
  823.  
  824. // Get the year and week.
  825. $year = sprintf( $this->labels['archive_year'], get_the_time( esc_html_x( 'Y', 'yearly archives date format', 'breadcrumb-trail' ) ) );
  826. $week = sprintf( $this->labels['archive_week'], get_the_time( esc_html_x( 'W', 'weekly archives date format', 'breadcrumb-trail' ) ) );
  827.  
  828. // Add the year item.
  829. $this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_year_link( get_the_time( 'Y' ) ) ), $year );
  830.  
  831. // Add the week item.
  832. if ( is_paged() )
  833. $this->items[] = esc_url( get_archives_link( add_query_arg( array( 'm' => get_the_time( 'Y' ), 'w' => get_the_time( 'W' ) ), home_url() ), $week, false ) );
  834.  
  835. elseif ( true === $this->args['show_title'] )
  836. $this->items[] = $week;
  837. }
  838.  
  839. /**
  840. * Adds the items to the trail items array for month archives.
  841. *
  842. * @since 1.0.0
  843. * @access protected
  844. * @return void
  845. */
  846. protected function add_month_archive_items() {
  847.  
  848. // Add $wp_rewrite->front to the trail.
  849. $this->add_rewrite_front_items();
  850.  
  851. // Get the year and month.
  852. $year = sprintf( $this->labels['archive_year'], get_the_time( esc_html_x( 'Y', 'yearly archives date format', 'breadcrumb-trail' ) ) );
  853. $month = sprintf( $this->labels['archive_month'], get_the_time( esc_html_x( 'F', 'monthly archives date format', 'breadcrumb-trail' ) ) );
  854.  
  855. // Add the year item.
  856. $this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_year_link( get_the_time( 'Y' ) ) ), $year );
  857.  
  858. // Add the month item.
  859. if ( is_paged() )
  860. $this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_month_link( get_the_time( 'Y' ), get_the_time( 'm' ) ) ), $month );
  861.  
  862. elseif ( true === $this->args['show_title'] )
  863. $this->items[] = $month;
  864. }
  865.  
  866. /**
  867. * Adds the items to the trail items array for year archives.
  868. *
  869. * @since 1.0.0
  870. * @access protected
  871. * @return void
  872. */
  873. protected function add_year_archive_items() {
  874.  
  875. // Add $wp_rewrite->front to the trail.
  876. $this->add_rewrite_front_items();
  877.  
  878. // Get the year.
  879. $year = sprintf( $this->labels['archive_year'], get_the_time( esc_html_x( 'Y', 'yearly archives date format', 'breadcrumb-trail' ) ) );
  880.  
  881. // Add the year item.
  882. if ( is_paged() )
  883. $this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_year_link( get_the_time( 'Y' ) ) ), $year );
  884.  
  885. elseif ( true === $this->args['show_title'] )
  886. $this->items[] = $year;
  887. }
  888.  
  889. /**
  890. * Adds the items to the trail items array for archives that don't have a more specific method
  891. * defined in this class.
  892. *
  893. * @since 1.0.0
  894. * @access protected
  895. * @return void
  896. */
  897. protected function add_default_archive_items() {
  898.  
  899. // If this is a date-/time-based archive, add $wp_rewrite->front to the trail.
  900. if ( is_date() || is_time() )
  901. $this->add_rewrite_front_items();
  902.  
  903. if ( true === $this->args['show_title'] )
  904. $this->items[] = $this->labels['archives'];
  905. }
  906.  
  907. /**
  908. * Adds the items to the trail items array for search results.
  909. *
  910. * @since 1.0.0
  911. * @access protected
  912. * @return void
  913. */
  914. protected function add_search_items() {
  915.  
  916. if ( is_paged() )
  917. $this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_search_link() ), sprintf( $this->labels['search'], get_search_query() ) );
  918.  
  919. elseif ( true === $this->args['show_title'] )
  920. $this->items[] = sprintf( $this->labels['search'], get_search_query() );
  921. }
  922.  
  923. /**
  924. * Adds the items to the trail items array for 404 pages.
  925. *
  926. * @since 1.0.0
  927. * @access protected
  928. * @return void
  929. */
  930. protected function add_404_items() {
  931.  
  932. if ( true === $this->args['show_title'] )
  933. $this->items[] = $this->labels['error_404'];
  934. }
  935.  
  936. /**
  937. * Adds a specific post's parents to the items array.
  938. *
  939. * @since 1.0.0
  940. * @access protected
  941. * @param int $post_id
  942. * @return void
  943. */
  944. protected function add_post_parents( $post_id ) {
  945. $parents = array();
  946.  
  947. while ( $post_id ) {
  948.  
  949. // Get the post by ID.
  950. $post = get_post( $post_id );
  951.  
  952. // If we hit a page that's set as the front page, bail.
  953. if ( 'page' == $post->post_type && 'page' == get_option( 'show_on_front' ) && $post_id == get_option( 'page_on_front' ) )
  954. break;
  955.  
  956. // Add the formatted post link to the array of parents.
  957. $parents[] = sprintf( '<a href="%s">%s</a>', esc_url( get_permalink( $post_id ) ), get_the_title( $post_id ) );
  958.  
  959. // If there's no longer a post parent, break out of the loop.
  960. if ( 0 >= $post->post_parent )
  961. break;
  962.  
  963. // Change the post ID to the parent post to continue looping.
  964. $post_id = $post->post_parent;
  965. }
  966.  
  967. // Get the post hierarchy based off the final parent post.
  968. $this->add_post_hierarchy( $post_id );
  969.  
  970. // Display terms for specific post type taxonomy if requested.
  971. if ( ! empty( $this->post_taxonomy[ $post->post_type ] ) )
  972. $this->add_post_terms( $post_id, $this->post_taxonomy[ $post->post_type ] );
  973.  
  974. // Merge the parent items into the items array.
  975. $this->items = array_merge( $this->items, array_reverse( $parents ) );
  976. }
  977.  
  978. /**
  979. * Adds a specific post's hierarchy to the items array. The hierarchy is determined by post type's
  980. * rewrite arguments and whether it has an archive page.
  981. *
  982. * @since 1.0.0
  983. * @access protected
  984. * @param int $post_id
  985. * @return void
  986. */
  987. protected function add_post_hierarchy( $post_id ) {
  988.  
  989. // Get the post type.
  990. $post_type = get_post_type( $post_id );
  991. $post_type_object = get_post_type_object( $post_type );
  992.  
  993. // If this is the 'post' post type, get the rewrite front items and map the rewrite tags.
  994. if ( 'post' === $post_type ) {
  995.  
  996. // Add $wp_rewrite->front to the trail.
  997. $this->add_rewrite_front_items();
  998.  
  999. // Map the rewrite tags.
  1000. $this->map_rewrite_tags( $post_id, get_option( 'permalink_structure' ) );
  1001. }
  1002.  
  1003. // If the post type has rewrite rules.
  1004. elseif ( false !== $post_type_object->rewrite ) {
  1005.  
  1006. // If 'with_front' is true, add $wp_rewrite->front to the trail.
  1007. if ( $post_type_object->rewrite['with_front'] )
  1008. $this->add_rewrite_front_items();
  1009.  
  1010. // If there's a path, check for parents.
  1011. if ( ! empty( $post_type_object->rewrite['slug'] ) )
  1012. $this->add_path_parents( $post_type_object->rewrite['slug'] );
  1013. }
  1014.  
  1015. // If there's an archive page, add it to the trail.
  1016. if ( $post_type_object->has_archive ) {
  1017.  
  1018. // Add support for a non-standard label of 'archive_title' (special use case).
  1019. $label = ! empty( $post_type_object->labels->archive_title ) ? $post_type_object->labels->archive_title : $post_type_object->labels->name;
  1020.  
  1021. // Core filter hook.
  1022. $label = apply_filters( 'post_type_archive_title', $label, $post_type_object->name );
  1023.  
  1024. $this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_post_type_archive_link( $post_type ) ), $label );
  1025. }
  1026.  
  1027. // Map the rewrite tags if there's a `%` in the slug.
  1028. if ( 'post' !== $post_type && ! empty( $post_type_object->rewrite['slug'] ) && false !== strpos( $post_type_object->rewrite['slug'], '%' ) )
  1029. $this->map_rewrite_tags( $post_id, $post_type_object->rewrite['slug'] );
  1030. }
  1031.  
  1032. /**
  1033. * Gets post types by slug. This is needed because the get_post_types() function doesn't exactly
  1034. * match the 'has_archive' argument when it's set as a string instead of a boolean.
  1035. *
  1036. * @since 0.6.0
  1037. * @access protected
  1038. * @param int $slug The post type archive slug to search for.
  1039. * @return void
  1040. */
  1041. protected function get_post_types_by_slug( $slug ) {
  1042.  
  1043. $return = array();
  1044.  
  1045. $post_types = get_post_types( array(), 'objects' );
  1046.  
  1047. foreach ( $post_types as $type ) {
  1048.  
  1049. if ( $slug === $type->has_archive || ( true === $type->has_archive && $slug === $type->rewrite['slug'] ) )
  1050. $return[] = $type;
  1051. }
  1052.  
  1053. return $return;
  1054. }
  1055.  
  1056. /**
  1057. * Adds a post's terms from a specific taxonomy to the items array.
  1058. *
  1059. * @since 1.0.0
  1060. * @access protected
  1061. * @param int $post_id The ID of the post to get the terms for.
  1062. * @param string $taxonomy The taxonomy to get the terms from.
  1063. * @return void
  1064. */
  1065. protected function add_post_terms( $post_id, $taxonomy ) {
  1066.  
  1067. // Get the post type.
  1068. $post_type = get_post_type( $post_id );
  1069.  
  1070. // Get the post categories.
  1071. $terms = get_the_terms( $post_id, $taxonomy );
  1072.  
  1073. // Check that categories were returned.
  1074. if ( $terms && ! is_wp_error( $terms ) ) {
  1075.  
  1076. // Sort the terms by ID and get the first category.
  1077. if ( function_exists( 'wp_list_sort' ) )
  1078. $terms = wp_list_sort( $terms, 'term_id' );
  1079.  
  1080. else
  1081. usort( $terms, '_usort_terms_by_ID' );
  1082.  
  1083. $term = get_term( $terms[0], $taxonomy );
  1084.  
  1085. // If the category has a parent, add the hierarchy to the trail.
  1086. if ( 0 < $term->parent )
  1087. $this->add_term_parents( $term->parent, $taxonomy );
  1088.  
  1089. // Add the category archive link to the trail.
  1090. $this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_term_link( $term, $taxonomy ) ), $term->name );
  1091. }
  1092. }
  1093.  
  1094. /**
  1095. * Get parent posts by path. Currently, this method only supports getting parents of the 'page'
  1096. * post type. The goal of this function is to create a clear path back to home given what would
  1097. * normally be a "ghost" directory. If any page matches the given path, it'll be added.
  1098. *
  1099. * @since 1.0.0
  1100. * @access protected
  1101. * @param string $path The path (slug) to search for posts by.
  1102. * @return void
  1103. */
  1104. function add_path_parents( $path ) {
  1105.  
  1106. // Trim '/' off $path in case we just got a simple '/' instead of a real path.
  1107. $path = trim( $path, '/' );
  1108.  
  1109. // If there's no path, return.
  1110. if ( empty( $path ) )
  1111. return;
  1112.  
  1113. // Get parent post by the path.
  1114. $post = get_page_by_path( $path );
  1115.  
  1116. if ( ! empty( $post ) ) {
  1117. $this->add_post_parents( $post->ID );
  1118. }
  1119.  
  1120. elseif ( is_null( $post ) ) {
  1121.  
  1122. // Separate post names into separate paths by '/'.
  1123. $path = trim( $path, '/' );
  1124. preg_match_all( "/\/.*?\z/", $path, $matches );
  1125.  
  1126. // If matches are found for the path.
  1127. if ( isset( $matches ) ) {
  1128.  
  1129. // Reverse the array of matches to search for posts in the proper order.
  1130. $matches = array_reverse( $matches );
  1131.  
  1132. // Loop through each of the path matches.
  1133. foreach ( $matches as $match ) {
  1134.  
  1135. // If a match is found.
  1136. if ( isset( $match[0] ) ) {
  1137.  
  1138. // Get the parent post by the given path.
  1139. $path = str_replace( $match[0], '', $path );
  1140. $post = get_page_by_path( trim( $path, '/' ) );
  1141.  
  1142. // If a parent post is found, set the $post_id and break out of the loop.
  1143. if ( ! empty( $post ) && 0 < $post->ID ) {
  1144. $this->add_post_parents( $post->ID );
  1145. break;
  1146. }
  1147. }
  1148. }
  1149. }
  1150. }
  1151. }
  1152.  
  1153. /**
  1154. * Searches for term parents of hierarchical taxonomies. This function is similar to the WordPress
  1155. * function get_category_parents() but handles any type of taxonomy.
  1156. *
  1157. * @since 1.0.0
  1158. * @param int $term_id ID of the term to get the parents of.
  1159. * @param string $taxonomy Name of the taxonomy for the given term.
  1160. * @return void
  1161. */
  1162. function add_term_parents( $term_id, $taxonomy ) {
  1163.  
  1164. // Set up some default arrays.
  1165. $parents = array();
  1166.  
  1167. // While there is a parent ID, add the parent term link to the $parents array.
  1168. while ( $term_id ) {
  1169.  
  1170. // Get the parent term.
  1171. $term = get_term( $term_id, $taxonomy );
  1172.  
  1173. // Add the formatted term link to the array of parent terms.
  1174. $parents[] = sprintf( '<a href="%s">%s</a>', esc_url( get_term_link( $term, $taxonomy ) ), $term->name );
  1175.  
  1176. // Set the parent term's parent as the parent ID.
  1177. $term_id = $term->parent;
  1178. }
  1179.  
  1180. // If we have parent terms, reverse the array to put them in the proper order for the trail.
  1181. if ( ! empty( $parents ) )
  1182. $this->items = array_merge( $this->items, array_reverse( $parents ) );
  1183. }
  1184.  
  1185. /**
  1186. * Turns %tag% from permalink structures into usable links for the breadcrumb trail. This feels kind of
  1187. * hackish for now because we're checking for specific %tag% examples and only doing it for the 'post'
  1188. * post type. In the future, maybe it'll handle a wider variety of possibilities, especially for custom post
  1189. * types.
  1190. *
  1191. * @since 0.6.0
  1192. * @access protected
  1193. * @param int $post_id ID of the post whose parents we want.
  1194. * @param string $path Path of a potential parent page.
  1195. * @param array $args Mixed arguments for the menu.
  1196. * @return array
  1197. */
  1198. protected function map_rewrite_tags( $post_id, $path ) {
  1199.  
  1200. $post = get_post( $post_id );
  1201.  
  1202. // Trim '/' from both sides of the $path.
  1203. $path = trim( $path, '/' );
  1204.  
  1205. // Split the $path into an array of strings.
  1206. $matches = explode( '/', $path );
  1207.  
  1208. // If matches are found for the path.
  1209. if ( is_array( $matches ) ) {
  1210.  
  1211. // Loop through each of the matches, adding each to the $trail array.
  1212. foreach ( $matches as $match ) {
  1213.  
  1214. // Trim any '/' from the $match.
  1215. $tag = trim( $match, '/' );
  1216.  
  1217. // If using the %year% tag, add a link to the yearly archive.
  1218. if ( '%year%' == $tag )
  1219. $this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_year_link( get_the_time( 'Y', $post_id ) ) ), sprintf( $this->labels['archive_year'], get_the_time( esc_html_x( 'Y', 'yearly archives date format', 'breadcrumb-trail' ) ) ) );
  1220.  
  1221. // If using the %monthnum% tag, add a link to the monthly archive.
  1222. elseif ( '%monthnum%' == $tag )
  1223. $this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_month_link( get_the_time( 'Y', $post_id ), get_the_time( 'm', $post_id ) ) ), sprintf( $this->labels['archive_month'], get_the_time( esc_html_x( 'F', 'monthly archives date format', 'breadcrumb-trail' ) ) ) );
  1224.  
  1225. // If using the %day% tag, add a link to the daily archive.
  1226. elseif ( '%day%' == $tag )
  1227. $this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_day_link( get_the_time( 'Y', $post_id ), get_the_time( 'm', $post_id ), get_the_time( 'd', $post_id ) ) ), sprintf( $this->labels['archive_day'], get_the_time( esc_html_x( 'j', 'daily archives date format', 'breadcrumb-trail' ) ) ) );
  1228.  
  1229. // If using the %author% tag, add a link to the post author archive.
  1230. elseif ( '%author%' == $tag )
  1231. $this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_author_posts_url( $post->post_author ) ), get_the_author_meta( 'display_name', $post->post_author ) );
  1232.  
  1233. // If using the %category% tag, add a link to the first category archive to match permalinks.
  1234. elseif ( taxonomy_exists( trim( $tag, '%' ) ) ) {
  1235.  
  1236. // Force override terms in this post type.
  1237. $this->post_taxonomy[ $post->post_type ] = false;
  1238.  
  1239. // Add the post categories.
  1240. $this->add_post_terms( $post_id, trim( $tag, '%' ) );
  1241. }
  1242. }
  1243. }
  1244. }
  1245. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement