Advertisement
rdusnr

Untitled

Jul 5th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 46.36 KB | None | 0 0
  1. <?php
  2. /**
  3. * @package SeventhQueen Framework
  4. * @subpackage Breadcrumb
  5. * @since 1.0
  6. *
  7. * Shows a breadcrumb for all types of pages.
  8. */
  9.  
  10.  
  11. if ( ! function_exists( 'kleo_breadcrumb' ) ) {
  12. /**
  13. * Shows a breadcrumb for all types of pages. This is a wrapper function for the Breadcrumb_Trail class,
  14. * which should be used in theme templates.
  15. *
  16. * @since 0.1.0
  17. * @access public
  18. *
  19. * @param array $args Arguments to pass to Breadcrumb_Trail.
  20. *
  21. * @return string|bool
  22. */
  23. function kleo_breadcrumb( $args = array() ) {
  24. $breadcrumb_filter = false;
  25.  
  26. if ( function_exists('yoast_breadcrumb') ) {
  27. $yoast_breadcrumb = yoast_breadcrumb('<div class="kleo_framework breadcrumb">','</div>','false');
  28.  
  29. if($yoast_breadcrumb) {
  30. $breadcrumb_filter = yoast_breadcrumb('<div class="kleo_framework breadcrumb">','</div>','false');
  31. }
  32. }
  33.  
  34. $breadcrumb_filter = apply_filters( 'kleo_breadcrumb_data', $breadcrumb_filter );
  35. if ( $breadcrumb_filter ) {
  36. return $breadcrumb_filter;
  37. }
  38.  
  39. if ( function_exists( 'bp_is_active' ) && ! bp_is_blog_page() ) {
  40. $breadcrumb = new buddypress_Breadcrumb_Trail( $args );
  41. } elseif ( function_exists( 'is_bbpress' ) && is_bbpress() ) {
  42. $breadcrumb = new bbPress_Breadcrumb_Trail( $args );
  43. } else {
  44. $breadcrumb = new Breadcrumb_Trail( $args );
  45. }
  46.  
  47. return $breadcrumb->trail();
  48. }
  49. }
  50.  
  51. /**
  52. * Creates a breadcrumbs menu for the site based on the current page that's being viewed by the user.
  53. *
  54. * @since 0.6.0
  55. */
  56. class Breadcrumb_Trail {
  57.  
  58. /**
  59. * Array of items belonging to the current breadcrumb trail.
  60. *
  61. * @since 0.1.0
  62. * @access public
  63. * @var array
  64. */
  65. public $items = array();
  66.  
  67. /**
  68. * Arguments used to build the breadcrumb trail.
  69. *
  70. * @since 0.1.0
  71. * @access public
  72. * @var array
  73. */
  74. public $args = array();
  75.  
  76. /**
  77. * Sets up the breadcrumb trail.
  78. *
  79. * @since 0.6.0
  80. * @access public
  81. *
  82. * @param array $args The arguments for how to build the breadcrumb trail.
  83. */
  84. public function __construct( $args = array() ) {
  85.  
  86. /* Remove the bbPress breadcrumbs. */
  87. add_filter( 'bbp_get_breadcrumb', '__return_false' );
  88.  
  89. $defaults = array(
  90. 'container' => 'div',
  91. 'item_tag' => 'span',
  92. 'separator' => '&#47;',
  93. 'before' => '',
  94. 'after' => '',
  95. 'show_on_front' => true,
  96. 'network' => false,
  97. //'show_edit_link' => false,
  98. 'show_title' => true,
  99. 'show_browse' => true,
  100. 'echo' => true,
  101. 'rich_snippet' => true,
  102.  
  103. /* Post taxonomy (examples follow). */
  104. 'post_taxonomy' => array(
  105. // 'post' => 'post_tag',
  106. // 'book' => 'genre',
  107. ),
  108.  
  109. /* Labels for text used (see Breadcrumb_Trail::default_labels). */
  110. 'labels' => array(),
  111. );
  112.  
  113. $this->args = apply_filters( 'breadcrumb_trail_args', wp_parse_args( $args, $defaults ) );
  114.  
  115. /* Merge the user-added labels with the defaults. */
  116. $this->args['labels'] = wp_parse_args( $this->args['labels'], $this->default_labels() );
  117.  
  118. $this->do_trail_items();
  119. }
  120.  
  121. /**
  122. * Formats and outputs the breadcrumb trail.
  123. *
  124. * @since 0.6.0
  125. * @access public
  126. * @return string
  127. */
  128. public function trail() {
  129.  
  130. $breadcrumb = '';
  131.  
  132. /* Connect the breadcrumb trail if there are items in the trail. */
  133. if ( ! empty( $this->items ) && is_array( $this->items ) ) {
  134.  
  135. /* Make sure we have a unique array of items. */
  136. $this->items = array_unique( $this->items );
  137.  
  138. //google rich snippets
  139. $vocabulary = '';
  140. if ( true === $this->args['rich_snippet'] ) {
  141. $vocabulary = ' xmlns:v="http://rdf.data-vocabulary.org/#"';
  142. }
  143.  
  144. /* Open the breadcrumb trail containers. */
  145. $breadcrumb = "\n\t\t" . '<' . tag_escape( $this->args['container'] ) . ' class="kleo_framework breadcrumb"' . $vocabulary . '>';
  146.  
  147. /* If $before was set, wrap it in a container. */
  148. $breadcrumb .= ( ! empty( $this->args['before'] ) ? "\n\t\t\t" . '<span class="trail-before">' . $this->args['before'] . '</span> ' . "\n\t\t\t" : '' );
  149.  
  150. /* Add 'browse' label if it should be shown. */
  151. if ( true === $this->args['show_browse'] ) {
  152. $breadcrumb .= "\n\t\t\t" . '<span class="trail-browse">' . $this->args['labels']['browse'] . '</span> ';
  153. }
  154.  
  155. /* Adds the 'trail-begin' class around first item if there's more than one item. */
  156. //if (1 < count($this->items))
  157. // array_unshift($this->items, '<span class="trail-begin">' . array_shift($this->items) . '</span>');
  158.  
  159. /* Adds the 'trail-end' class around last item. */
  160. //array_push($this->items, '<span class="trail-end">' . array_pop($this->items) . '</span>');
  161.  
  162. /* Format the separator. */
  163. $separator = ( ! empty( $this->args['separator'] ) ? '<span class="sep">' . $this->args['separator'] . '</span>' : '' );
  164.  
  165. $count = 0;
  166. foreach ( $this->items as &$link ) {
  167. $count ++;
  168. $class = '';
  169. if ( count( $this->items ) == $count ) {
  170. $class = ' class="active"';
  171. }
  172. if ( true === $this->args['rich_snippet'] ) {
  173. $link = preg_replace( '!rel=".+?"|rel=\'.+?\'|!', '', $link );
  174. $link = str_replace( '<a ', '<a rel="v:url" property="v:title" ', $link, $count_replace );
  175. $micro_data = '';
  176. if ( $count_replace > 0 ) {
  177. $micro_data = ' typeof="v:Breadcrumb"';
  178. }
  179. $link = '<' . $this->args['item_tag'] . $micro_data . $class . '>' . $link . '</' . $this->args['item_tag'] . '>';
  180. } else {
  181. $link = '<' . $this->args['item_tag'] . $class . '>' . $link . '</' . $this->args['item_tag'] . '>';
  182. }
  183. }
  184.  
  185. /* Join the individual trail items into a single string. */
  186. $breadcrumb .= join( "\n\t\t\t {$separator} ", $this->items );
  187.  
  188. /* If $after was set, wrap it in a container. */
  189. $breadcrumb .= ( ! empty( $this->args['after'] ) ? "\n\t\t\t" . ' <span class="trail-after">' . $this->args['after'] . '</span>' : '' );
  190.  
  191. /* Close the breadcrumb trail containers. */
  192. $breadcrumb .= "\n\t\t" . '</' . tag_escape( $this->args['container'] ) . '>';
  193. }
  194.  
  195. /* Allow developers to filter the breadcrumb trail HTML. */
  196. $breadcrumb = apply_filters( 'breadcrumb_trail', $breadcrumb, $this->args );
  197.  
  198. if ( true === $this->args['echo'] ) {
  199. echo $breadcrumb;
  200. } else {
  201. return $breadcrumb;
  202. }
  203. }
  204.  
  205. /**
  206. * Returns an array of the default labels.
  207. *
  208. * @since 0.6.0
  209. * @access public
  210. * @return array
  211. */
  212. public function default_labels() {
  213.  
  214. $labels = array(
  215. 'browse' => __( 'Browse:', 'kleo_framework' ),
  216. 'home' => __( 'Home', 'kleo_framework' ),
  217. 'error_404' => __( '404 Not Found', 'kleo_framework' ),
  218. 'archives' => __( 'Archives', 'kleo_framework' ),
  219. /* Translators: %s is the search query. The HTML entities are opening and closing curly quotes. */
  220. 'search' => __( 'Search results for &#8220;%s&#8221;', 'kleo_framework' ),
  221. /* Translators: %s is the page number. */
  222. 'paged' => __( 'Page %s', 'kleo_framework' ),
  223. /* Translators: Minute archive title. %s is the minute time format. */
  224. 'archive_minute' => __( 'Minute %s', 'kleo_framework' ),
  225. /* Translators: Weekly archive title. %s is the week date format. */
  226. 'archive_week' => __( 'Week %s', 'kleo_framework' ),
  227.  
  228. /* "%s" is replaced with the translated date/time format. */
  229. 'archive_minute_hour' => '%s',
  230. 'archive_hour' => '%s',
  231. 'archive_day' => '%s',
  232. 'archive_month' => '%s',
  233. 'archive_year' => '%s',
  234. );
  235.  
  236. return $labels;
  237. }
  238.  
  239. /**
  240. * Runs through the various WordPress conditional tags to check the current page being viewed. Once
  241. * a condition is met, a specific method is launched to add items to the $items array.
  242. *
  243. * @since 0.6.0
  244. * @access public
  245. * @return void
  246. */
  247. public function do_trail_items() {
  248.  
  249. /* If viewing the front page. */
  250. if ( is_front_page() ) {
  251. $this->do_front_page_items();
  252. } /* If not viewing the front page. */
  253. else {
  254.  
  255. /* Add the network and site home links. */
  256. $this->do_network_home_link();
  257. $this->do_site_home_link();
  258.  
  259. /* If viewing the home/blog page. */
  260. if ( is_home() ) {
  261. $this->do_posts_page_items();
  262. } /* If viewing a single post. */
  263. elseif ( is_singular() ) {
  264. $this->do_singular_items();
  265. } /* If viewing an archive page. */
  266. elseif ( is_archive() ) {
  267.  
  268. if ( is_post_type_archive() ) {
  269. $this->do_post_type_archive_items();
  270. } elseif ( is_category() || is_tag() || is_tax() ) {
  271. $this->do_term_archive_items();
  272. } elseif ( is_author() ) {
  273. $this->do_user_archive_items();
  274. } elseif ( get_query_var( 'minute' ) && get_query_var( 'hour' ) ) {
  275. $this->do_minute_hour_archive_items();
  276. } elseif ( get_query_var( 'minute' ) ) {
  277. $this->do_minute_archive_items();
  278. } elseif ( get_query_var( 'hour' ) ) {
  279. $this->do_hour_archive_items();
  280. } elseif ( is_day() ) {
  281. $this->do_day_archive_items();
  282. } elseif ( get_query_var( 'w' ) ) {
  283. $this->do_week_archive_items();
  284. } elseif ( is_month() ) {
  285. $this->do_month_archive_items();
  286. } elseif ( is_year() ) {
  287. $this->do_year_archive_items();
  288. } else {
  289. $this->do_default_archive_items();
  290. }
  291. } /* If viewing a search results page. */
  292. elseif ( is_search() ) {
  293. $this->do_search_items();
  294. } /* If viewing the 404 page. */
  295. elseif ( is_404() ) {
  296. $this->do_404_items();
  297. }
  298. }
  299.  
  300. /* Add paged items if they exist. */
  301. $this->do_paged_items();
  302.  
  303. /* Allow developers to overwrite the items for the breadcrumb trail. */
  304. $this->items = apply_filters( 'breadcrumb_trail_items', $this->items, $this->args );
  305. }
  306.  
  307. /**
  308. * Gets front items based on $wp_rewrite->front.
  309. *
  310. * @since 0.6.0
  311. * @access public
  312. * @return void
  313. */
  314. public function do_rewrite_front_items() {
  315. global $wp_rewrite;
  316.  
  317. if ( $wp_rewrite->front ) {
  318. $this->do_path_parents( $wp_rewrite->front );
  319. }
  320. }
  321.  
  322. /**
  323. * Adds the page/paged number to the items array.
  324. *
  325. * @since 0.6.0
  326. * @access public
  327. * @return void
  328. */
  329. public function do_paged_items() {
  330.  
  331. /* If viewing a paged singular post. */
  332. if ( is_singular() && 1 < get_query_var( 'page' ) && true === $this->args['show_title'] ) {
  333. $this->items[] = sprintf( $this->args['labels']['paged'], number_format_i18n( absint( get_query_var( 'page' ) ) ) );
  334. } /* If viewing a paged archive-type page. */
  335. elseif ( is_paged() && true === $this->args['show_title'] ) {
  336. $this->items[] = sprintf( $this->args['labels']['paged'], number_format_i18n( absint( get_query_var( 'paged' ) ) ) );
  337. }
  338.  
  339. }
  340.  
  341. /**
  342. * Adds the network (all sites) home page link to the items array.
  343. *
  344. * @since 0.6.0
  345. * @access public
  346. * @return void
  347. */
  348. public function do_network_home_link() {
  349. if ( is_multisite() && ! is_main_site() && true === $this->args['network'] ) {
  350. $this->items[] = '<a href="' . network_home_url() . '" title="' . esc_attr( $this->args['labels']['home'] ) . '" rel="home">' . $this->args['labels']['home'] . '</a>';
  351. }
  352. }
  353.  
  354. /**
  355. * Adds the current site's home page link to the items array.
  356. *
  357. * @since 0.6.0
  358. * @access public
  359. * @return void
  360. */
  361. public function do_site_home_link() {
  362. $label = ( is_multisite() && ! is_main_site() && true === $this->args['network'] ) ? get_bloginfo( 'name' ) : $this->args['labels']['home'];
  363. $rel = ( is_multisite() && ! is_main_site() && true === $this->args['network'] ) ? '' : ' rel="home"';
  364. $this->items[] = '<a href="' . home_url() . '" title="' . esc_attr( get_bloginfo( 'name' ) ) . '"' . $rel . '>' . $label . '</a>';
  365. }
  366.  
  367. /**
  368. * Adds items for the front page to the items array.
  369. *
  370. * @since 0.6.0
  371. * @access public
  372. * @return void
  373. */
  374. public function do_front_page_items() {
  375. /* Only show front items if the 'show_on_front' argument is set to 'true'. */
  376. if ( true === $this->args['show_on_front'] || is_paged() || ( is_singular() && 1 < get_query_var( 'page' ) ) ) {
  377.  
  378. /* If on a paged view, add the home link items. */
  379. if ( is_paged() ) {
  380. $this->do_network_home_link();
  381. $this->do_site_home_link();
  382. } /* If on the main front page, add the network home link item and the home item. */
  383. else {
  384. $this->do_network_home_link();
  385.  
  386. if ( true === $this->args['show_title'] ) {
  387. $this->items[] = ( is_multisite() && true === $this->args['network'] ) ? get_bloginfo( 'name' ) : $this->args['labels']['home'];
  388. }
  389. }
  390. }
  391. }
  392.  
  393. /**
  394. * Adds items for the posts page (i.e., is_home()) to the items array.
  395. *
  396. * @since 0.6.0
  397. * @access public
  398. * @return void
  399. */
  400. public function do_posts_page_items() {
  401. if ( is_main_query() ) {
  402. return;
  403. }
  404. /* Get the post ID and post. */
  405. $post_id = get_queried_object_id();
  406. $post = get_post( $post_id );
  407.  
  408. /* If the post has parents, add them to the trail. */
  409. if ( isset( $post->post_parent ) && 0 < $post->post_parent ) {
  410. $this->do_post_parents( $post->post_parent );
  411. }
  412.  
  413. /* Get the page title. */
  414. $title = get_the_title( $post_id );
  415. if ( get_cfield( 'custom_title', $post_id ) && get_cfield( 'custom_title', $post_id ) != '' ) {
  416. $title = get_cfield( 'custom_title', $post_id );
  417. }
  418.  
  419.  
  420. /* Add the posts page item. */
  421. if ( is_paged() ) {
  422. $this->items[] = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( $title ) . '">' . $title . '</a>';
  423. } elseif ( $title && true === $this->args['show_title'] ) {
  424. $this->items[] = $title;
  425. }
  426. }
  427.  
  428. /**
  429. * Adds singular post items to the items array.
  430. *
  431. * @since 0.6.0
  432. * @access public
  433. * @return void
  434. */
  435. public function do_singular_items() {
  436.  
  437. /* Get the queried post. */
  438. $post = get_queried_object();
  439. $post_id = get_queried_object_id();
  440.  
  441. /* If the post has a parent, follow the parent trail. */
  442. if ( 0 < $post->post_parent ) {
  443. $this->do_post_parents( $post->post_parent );
  444. } /* If the post doesn't have a parent, get its hierarchy based off the post type. */
  445. else {
  446. $this->do_post_hierarchy( $post_id );
  447. }
  448.  
  449. /* Display terms for specific post type taxonomy if requested. */
  450. $this->do_post_terms( $post_id );
  451.  
  452. /* End with the post title. */
  453. if ( $post_title = single_post_title( '', false ) ) {
  454.  
  455. if ( get_cfield( 'custom_title', $post_id ) && get_cfield( 'custom_title', $post_id ) != '' ) {
  456. $post_title = get_cfield( 'custom_title', $post_id );
  457. }
  458.  
  459. if ( 1 < get_query_var( 'page' ) ) {
  460. $this->items[] = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( $post_title ) . '">' . $post_title . '</a>';
  461. } elseif ( true === $this->args['show_title'] ) {
  462. $this->items[] = $post_title;
  463. }
  464. }
  465. }
  466.  
  467. /**
  468. * Adds a specific post's parents to the items array.
  469. *
  470. * @since 0.6.0
  471. * @access public
  472. *
  473. * @param int $post_id The ID of the post to get the parents of.
  474. *
  475. * @return void
  476. */
  477. public function do_post_parents( $post_id ) {
  478. $parents = array();
  479.  
  480. while ( $post_id ) {
  481.  
  482. /* Get the post by ID. */
  483. $post = get_post( $post_id );
  484.  
  485. $page_title = get_the_title( $post_id );
  486.  
  487. if ( get_cfield( 'custom_title', $post_id ) && get_cfield( 'custom_title', $post_id ) != '' ) {
  488. $page_title = get_cfield( 'custom_title', $post_id );
  489. }
  490.  
  491. /* Add the formatted post link to the array of parents. */
  492. $parents[] = '<a href="' . get_permalink( $post_id ) . '" title="' . $page_title . '">' . $page_title . '</a>';
  493.  
  494. /* If there's no longer a post parent, brea out of the loop. */
  495. if ( 0 >= $post->post_parent ) {
  496. break;
  497. }
  498.  
  499. /* Change the post ID to the parent post to continue looping. */
  500. $post_id = $post->post_parent;
  501. }
  502.  
  503. /* Get the post hierarchy based off the final parent post. */
  504. $this->do_post_hierarchy( $post_id );
  505.  
  506. /* Merge the parent items into the items array. */
  507. $this->items = array_merge( $this->items, array_reverse( $parents ) );
  508. }
  509.  
  510. /**
  511. * Adds a post's terms from a specific taxonomy to the items array.
  512. *
  513. * @since 0.6.0
  514. * @access public
  515. *
  516. * @param int $post_id The ID of the post to get the terms for.
  517. *
  518. * @return void
  519. */
  520. public function do_post_terms( $post_id ) {
  521.  
  522. /* Get the post type. */
  523. $post_type = get_post_type( $post_id );
  524.  
  525. /* Add the terms of the taxonomy for this post. */
  526. if ( ! empty( $this->args['post_taxonomy'][ $post_type ] ) ) {
  527. $this->add_post_terms( $post_id, $this->args['post_taxonomy'][ $post_type ] );
  528. }
  529. }
  530.  
  531. /**
  532. * Adds a post's terms from a specific taxonomy to the items array.
  533. *
  534. * @since 1.0.0
  535. * @access protected
  536. *
  537. * @param int $post_id The ID of the post to get the terms for.
  538. * @param string $taxonomy The taxonomy to get the terms from.
  539. *
  540. * @return void
  541. */
  542. protected function add_post_terms( $post_id, $taxonomy ) {
  543.  
  544. // Get the post categories.
  545. $terms = get_the_terms( $post_id, $taxonomy );
  546.  
  547. // Check that categories were returned.
  548. if ( $terms && ! is_wp_error( $terms ) ) {
  549.  
  550. // Sort the terms by ID and get the first category.
  551. usort( $terms, '_usort_terms_by_ID' );
  552. $term = get_term( $terms[0], $taxonomy );
  553.  
  554. // If the category has a parent, add the hierarchy to the trail.
  555. if ( 0 < $term->parent ) {
  556. $this->do_term_parents( $term->parent, $taxonomy );
  557. }
  558.  
  559. // Add the category archive link to the trail.
  560. $this->items[] = sprintf( '<a href="%s">%s</a>', esc_url( get_term_link( $term, $taxonomy ) ), $term->name );
  561. }
  562. }
  563.  
  564. /**
  565. * Adds a specific post's hierarchy to the items array. The hierarchy is determined by post type's
  566. * rewrite arguments and whether it has an archive page.
  567. *
  568. * @since 0.6.0
  569. * @access public
  570. *
  571. * @param int $post_id The ID of the post to get the hierarchy for.
  572. *
  573. * @return void
  574. */
  575. public function do_post_hierarchy( $post_id ) {
  576.  
  577. /* Get the post type. */
  578. $post_type = get_post_type( $post_id );
  579. $post_type_object = get_post_type_object( $post_type );
  580.  
  581. /* If this is the 'post' post type, get the rewrite front items and map the rewrite tags. */
  582. if ( 'post' === $post_type ) {
  583.  
  584. /* Add $wp_rewrite->front to the trail. */
  585. $this->do_rewrite_front_items();
  586.  
  587. /* Map the rewrite tags. */
  588. $this->map_rewrite_tags( $post_id, get_option( 'permalink_structure' ) );
  589. } /* If the post type has rewrite rules. */
  590. elseif ( false !== $post_type_object->rewrite ) {
  591.  
  592. /* If 'with_front' is true, add $wp_rewrite->front to the trail. */
  593. if ( $post_type_object->rewrite['with_front'] ) {
  594. $this->do_rewrite_front_items();
  595. }
  596.  
  597. /* If there's a path, check for parents. */
  598. if ( ! empty( $post_type_object->rewrite['slug'] ) && ! $post_type_object->has_archive ) {
  599. $this->do_path_parents( $post_type_object->rewrite['slug'] );
  600. }
  601. }
  602.  
  603. /* If there's an archive page, add it to the trail. */
  604. if ( ! empty( $post_type_object->has_archive ) ) {
  605.  
  606. $label = ! empty( $post_type_object->labels->archive_title ) ? $post_type_object->labels->archive_title : $post_type_object->labels->name;
  607.  
  608. $this->items[] = '<a href="' . get_post_type_archive_link( $post_type ) . '">' . $label . '</a>';
  609. }
  610. }
  611.  
  612. /**
  613. * Gets post types by slug. This is needed because the get_post_types() function doesn't exactly
  614. * match the 'has_archive' argument when it's set as a string instead of a boolean.
  615. *
  616. * @since 0.6.0
  617. * @access public
  618. *
  619. * @param int $slug The post type archive slug to search for.
  620. *
  621. * @return void
  622. */
  623. public function get_post_types_by_slug( $slug ) {
  624.  
  625. $return = array();
  626.  
  627. $post_types = get_post_types( array(), 'objects' );
  628.  
  629. foreach ( $post_types as $type ) {
  630.  
  631. if ( $slug === $type->has_archive || ( true === $type->has_archive && $slug === $type->rewrite['slug'] ) ) {
  632. $return[] = $type;
  633. }
  634. }
  635.  
  636. return $return;
  637. }
  638.  
  639. /**
  640. * Adds the items to the trail items array for taxonomy term archives.
  641. *
  642. * @since 0.6.0
  643. * @access public
  644. * @global object $wp_rewrite
  645. * @return void
  646. */
  647. public function do_term_archive_items() {
  648. global $wp_rewrite;
  649.  
  650. /* Get some taxonomy and term variables. */
  651. $term = get_queried_object();
  652. $taxonomy = get_taxonomy( $term->taxonomy );
  653.  
  654. /* If there are rewrite rules for the taxonomy. */
  655. if ( false !== $taxonomy->rewrite ) {
  656.  
  657. /* If 'with_front' is true, dd $wp_rewrite->front to the trail. */
  658. if ( $taxonomy->rewrite['with_front'] && $wp_rewrite->front ) {
  659. $this->do_rewrite_front_items();
  660. }
  661.  
  662. /* Get parent pages by path if they exist. */
  663. $this->do_path_parents( $taxonomy->rewrite['slug'] );
  664.  
  665. /* Add post type archive if its 'has_archive' matches the taxonomy rewrite 'slug'. */
  666. if ( $taxonomy->rewrite['slug'] ) {
  667.  
  668. $slug = trim( $taxonomy->rewrite['slug'], '/' );
  669.  
  670. /**
  671. * Deals with the situation if the slug has a '/' between multiple strings. For
  672. * example, "movies/genres" where "movies" is the post type archive.
  673. */
  674. $matches = explode( '/', $slug );
  675.  
  676. /* If matches are found for the path. */
  677. if ( isset( $matches ) ) {
  678.  
  679. /* Reverse the array of matches to search for posts in the proper order. */
  680. $matches = array_reverse( $matches );
  681.  
  682. /* Loop through each of the path matches. */
  683. foreach ( $matches as $match ) {
  684.  
  685. /* If a match is found. */
  686. $slug = $match;
  687.  
  688. /* Get public post types that match the rewrite slug. */
  689. $post_types = $this->get_post_types_by_slug( $match );
  690.  
  691. if ( ! empty( $post_types ) ) {
  692.  
  693. $post_type_object = $post_types[0];
  694.  
  695. /* Add support for a non-standard label of 'archive_title' (special use case). */
  696. $label = ! empty( $post_type_object->labels->archive_title ) ? $post_type_object->labels->archive_title : $post_type_object->labels->name;
  697.  
  698. /* Add the post type archive link to the trail. */
  699. $this->items[] = '<a href="' . get_post_type_archive_link( $post_type_object->name ) . '" title="' . esc_attr( $label ) . '">' . $label . '</a>';
  700.  
  701. /* Break out of the loop. */
  702. break;
  703. }
  704. }
  705. }
  706. }
  707. }
  708.  
  709. /* If the taxonomy is hierarchical, list its parent terms. */
  710. if ( is_taxonomy_hierarchical( $term->taxonomy ) && $term->parent ) {
  711. $this->do_term_parents( $term->parent, $term->taxonomy );
  712. }
  713.  
  714. /* Add the term name to the trail end. */
  715. if ( is_paged() ) {
  716. $this->items[] = '<a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '" title="' . esc_attr( single_term_title( '', false ) ) . '">' . single_term_title( '', false ) . '</a>';
  717. } elseif ( true === $this->args['show_title'] ) {
  718. $this->items[] = single_term_title( '', false );
  719. }
  720. }
  721.  
  722. /**
  723. * Adds the items to the trail items array for post type archives.
  724. *
  725. * @since 0.6.0
  726. * @access public
  727. * @return void
  728. */
  729. public function do_post_type_archive_items() {
  730.  
  731. /* Get the post type object. */
  732. $post_type_object = get_post_type_object( get_query_var( 'post_type' ) );
  733.  
  734. if ( false !== $post_type_object->rewrite ) {
  735.  
  736. /* If 'with_front' is true, add $wp_rewrite->front to the trail. */
  737. if ( $post_type_object->rewrite['with_front'] ) {
  738. $this->do_rewrite_front_items();
  739. }
  740.  
  741. /* If there's a rewrite slug, check for parents. */
  742. /*if (!empty($post_type_object->rewrite['slug']))
  743. $this->do_path_parents($post_type_object->rewrite['slug']);*/
  744. }
  745.  
  746. /* Add the post type [plural] name to the trail end. */
  747. if ( is_paged() ) {
  748. $this->items[] = '<a href="' . esc_url( get_post_type_archive_link( $post_type_object->name ) ) . '" title="' . esc_attr( post_type_archive_title( '', false ) ) . '">' . post_type_archive_title( '', false ) . '</a>';
  749. } elseif ( true === $this->args['show_title'] ) {
  750. $this->items[] = post_type_archive_title( '', false );
  751. }
  752. }
  753.  
  754. /**
  755. * Adds the items to the trail items array for user (author) archives.
  756. *
  757. * @since 0.6.0
  758. * @access public
  759. * @global object $wp_rewrite
  760. * @return void
  761. */
  762. public function do_user_archive_items() {
  763. global $wp_rewrite;
  764.  
  765. /* Add $wp_rewrite->front to the trail. */
  766. $this->do_rewrite_front_items();
  767.  
  768. /* Get the user ID. */
  769. $user_id = get_query_var( 'author' );
  770.  
  771. /* If $author_base exists, check for parent pages. */
  772. if ( ! empty( $wp_rewrite->author_base ) ) {
  773. $this->do_path_parents( $wp_rewrite->author_base );
  774. }
  775.  
  776. /* Add the author's display name to the trail end. */
  777. if ( is_paged() ) {
  778. $this->items[] = '<a href="' . esc_url( get_author_posts_url( $user_id ) ) . '" title="' . esc_attr( get_the_author_meta( 'display_name', $user_id ) ) . '">' . get_the_author_meta( 'display_name', $user_id ) . '</a>';
  779. } elseif ( true === $this->args['show_title'] ) {
  780. $this->items[] = get_the_author_meta( 'display_name', $user_id );
  781. }
  782. }
  783.  
  784. /**
  785. * Adds the items to the trail items array for minute + hour archives.
  786. *
  787. * @since 0.6.0
  788. * @access public
  789. * @return void
  790. */
  791. public function do_minute_hour_archive_items() {
  792.  
  793. /* Add $wp_rewrite->front to the trail. */
  794. $this->do_rewrite_front_items();
  795.  
  796. /* Add the minute + hour item. */
  797. if ( true === $this->args['show_title'] ) {
  798. $this->items[] = sprintf( $this->args['labels']['archive_minute_hour'], get_the_time( _x( 'g:i a', 'minute and hour archives time format', 'kleo_framework' ) ) );
  799. }
  800. }
  801.  
  802. /**
  803. * Adds the items to the trail items array for minute archives.
  804. *
  805. * @since 0.6.0
  806. * @access public
  807. * @return void
  808. */
  809. public function do_minute_archive_items() {
  810.  
  811. /* Add $wp_rewrite->front to the trail. */
  812. $this->do_rewrite_front_items();
  813.  
  814. /* Add the minute item. */
  815. if ( true === $this->args['show_title'] ) {
  816. $this->items[] = sprintf( $this->args['labels']['archive_minute'], get_the_time( _x( 'i', 'minute archives time format', 'kleo_framework' ) ) );
  817. }
  818. }
  819.  
  820. /**
  821. * Adds the items to the trail items array for hour archives.
  822. *
  823. * @since 0.6.0
  824. * @access public
  825. * @return void
  826. */
  827. public function do_hour_archive_items() {
  828.  
  829. /* Add $wp_rewrite->front to the trail. */
  830. $this->do_rewrite_front_items();
  831.  
  832. /* Add the hour item. */
  833. if ( true === $this->args['show_title'] ) {
  834. $this->items[] = sprintf( $this->args['labels']['archive_hour'], get_the_time( _x( 'g a', 'hour archives time format', 'kleo_framework' ) ) );
  835. }
  836. }
  837.  
  838. /**
  839. * Adds the items to the trail items array for day archives.
  840. *
  841. * @since 0.6.0
  842. * @access public
  843. * @return void
  844. */
  845. public function do_day_archive_items() {
  846.  
  847. /* Add $wp_rewrite->front to the trail. */
  848. $this->do_rewrite_front_items();
  849.  
  850. /* Get year, month, and day. */
  851. $year = sprintf( $this->args['labels']['archive_year'], get_the_time( _x( 'Y', 'yearly archives date format', 'kleo_framework' ) ) );
  852. $month = sprintf( $this->args['labels']['archive_month'], get_the_time( _x( 'F', 'monthly archives date format', 'kleo_framework' ) ) );
  853. $day = sprintf( $this->args['labels']['archive_day'], get_the_time( _x( 'j', 'daily archives date format', 'kleo_framework' ) ) );
  854.  
  855. /* Add the year and month items. */
  856. $this->items[] = '<a href="' . get_year_link( get_the_time( 'Y' ) ) . '" title="' . esc_attr( $year ) . '">' . $year . '</a>';
  857. $this->items[] = '<a href="' . get_month_link( get_the_time( 'Y' ), get_the_time( 'm' ) ) . '" title="' . esc_attr( $month ) . '">' . $month . '</a>';
  858.  
  859. /* Add the day item. */
  860. if ( is_paged() ) {
  861. $this->items[] = '<a href="' . get_day_link( get_the_time( 'Y' ), get_the_time( 'm' ), get_the_time( 'd' ) ) . '" title="' . esc_attr( $day ) . '">' . $day . '</a>';
  862. } elseif ( true === $this->args['show_title'] ) {
  863. $this->items[] = $day;
  864. }
  865. }
  866.  
  867. /**
  868. * Adds the items to the trail items array for week archives.
  869. *
  870. * @since 0.6.0
  871. * @access public
  872. * @return void
  873. */
  874. public function do_week_archive_items() {
  875.  
  876. /* Add $wp_rewrite->front to the trail. */
  877. $this->do_rewrite_front_items();
  878.  
  879. /* Get the year and week. */
  880. $year = sprintf( $this->args['labels']['archive_year'], get_the_time( _x( 'Y', 'yearly archives date format', 'kleo_framework' ) ) );
  881. $week = sprintf( $this->args['labels']['archive_week'], get_the_time( _x( 'W', 'weekly archives date format', 'kleo_framework' ) ) );
  882.  
  883. /* Add the year item. */
  884. $this->items[] = '<a href="' . get_year_link( get_the_time( 'Y' ) ) . '" title="' . esc_attr( $year ) . '">' . $year . '</a>';
  885.  
  886. /* Add the week item. */
  887. if ( is_paged() ) {
  888. $this->items[] = get_archives_link( add_query_arg( array(
  889. 'm' => get_the_time( 'Y' ),
  890. 'w' => get_the_time( 'W' )
  891. ), home_url() ), $week, false );
  892. } elseif ( true === $this->args['show_title'] ) {
  893. $this->items[] = $week;
  894. }
  895. }
  896.  
  897. /**
  898. * Adds the items to the trail items array for month archives.
  899. *
  900. * @since 0.6.0
  901. * @access public
  902. * @return void
  903. */
  904. public function do_month_archive_items() {
  905.  
  906. /* Add $wp_rewrite->front to the trail. */
  907. $this->do_rewrite_front_items();
  908.  
  909. /* Get the year and month. */
  910. $year = sprintf( $this->args['labels']['archive_year'], get_the_time( _x( 'Y', 'yearly archives date format', 'kleo_framework' ) ) );
  911. $month = sprintf( $this->args['labels']['archive_month'], get_the_time( _x( 'F', 'monthly archives date format', 'kleo_framework' ) ) );
  912.  
  913. /* Add the year item. */
  914. $this->items[] = '<a href="' . get_year_link( get_the_time( 'Y' ) ) . '" title="' . esc_attr( $year ) . '">' . $year . '</a>';
  915.  
  916. /* Add the month item. */
  917. if ( is_paged() ) {
  918. $this->items[] = '<a href="' . get_month_link( get_the_time( 'Y' ), get_the_time( 'm' ) ) . '" title="' . esc_attr( $month ) . '">' . $month . '</a>';
  919. } elseif ( true === $this->args['show_title'] ) {
  920. $this->items[] = $month;
  921. }
  922. }
  923.  
  924. /**
  925. * Adds the items to the trail items array for year archives.
  926. *
  927. * @since 0.6.0
  928. * @access public
  929. * @return void
  930. */
  931. public function do_year_archive_items() {
  932.  
  933. /* Add $wp_rewrite->front to the trail. */
  934. $this->do_rewrite_front_items();
  935.  
  936. /* Get the year. */
  937. $year = sprintf( $this->args['labels']['archive_year'], get_the_time( _x( 'Y', 'yearly archives date format', 'kleo_framework' ) ) );
  938.  
  939. /* Add the year item. */
  940. if ( is_paged() ) {
  941. $this->items[] = '<a href="' . get_year_link( get_the_time( 'Y' ) ) . '" title="' . esc_attr( $year ) . '">' . $year . '</a>';
  942. } elseif ( true === $this->args['show_title'] ) {
  943. $this->items[] = $year;
  944. }
  945. }
  946.  
  947. /**
  948. * Adds the items to the trail items array for archives that don't have a more specific method
  949. * defined in this class.
  950. *
  951. * @since 0.6.0
  952. * @access public
  953. * @return void
  954. */
  955. public function do_default_archive_items() {
  956.  
  957. /* If this is a date-/time-based archive, add $wp_rewrite->front to the trail. */
  958. if ( is_date() || is_time() ) {
  959. $this->do_rewrite_front_items();
  960. }
  961.  
  962. if ( true === $this->args['show_title'] ) {
  963. $this->items[] = $this->args['labels']['archives'];
  964. }
  965. }
  966.  
  967. /**
  968. * Adds the items to the trail items array for search results.
  969. *
  970. * @since 0.6.0
  971. * @access public
  972. * @return void
  973. */
  974. public function do_search_items() {
  975.  
  976. if ( is_paged() ) {
  977. $this->items[] = '<a href="' . get_search_link() . '" title="' . esc_attr( sprintf( $this->args['labels']['search'], get_search_query() ) ) . '">' . sprintf( $this->args['labels']['search'], get_search_query() ) . '</a>';
  978. } elseif ( true === $this->args['show_title'] ) {
  979. $this->items[] = sprintf( $this->args['labels']['search'], get_search_query() );
  980. }
  981. }
  982.  
  983. /**
  984. * Adds the items to the trail items array for 404 pages.
  985. *
  986. * @since 0.6.0
  987. * @access public
  988. * @return void
  989. */
  990. public function do_404_items() {
  991.  
  992. if ( true === $this->args['show_title'] ) {
  993. $this->items[] = $this->args['labels']['error_404'];
  994. }
  995. }
  996.  
  997. /**
  998. * Get parent posts by path. Currently, this method only supports getting parents of the 'page'
  999. * post type. The goal of this function is to create a clear path back to home given what would
  1000. * normally be a "ghost" directory. If any page matches the given path, it'll be added.
  1001. *
  1002. * @since 0.6.0
  1003. * @access public
  1004. *
  1005. * @param string $path The path (slug) to search for posts by.
  1006. *
  1007. * @return void
  1008. */
  1009. function do_path_parents( $path ) {
  1010.  
  1011. /* Trim '/' off $path in case we just got a simple '/' instead of a real path. */
  1012. $path = trim( $path, '/' );
  1013.  
  1014. /* If there's no path, return. */
  1015. if ( empty( $path ) ) {
  1016. return;
  1017. }
  1018.  
  1019. /* Get parent post by the path. */
  1020. $post = get_page_by_path( $path );
  1021.  
  1022. if ( ! empty( $post ) ) {
  1023. $this->do_post_parents( $post->ID );
  1024. } elseif ( is_null( $post ) ) {
  1025.  
  1026. /* Separate post names into separate paths by '/'. */
  1027. $path = trim( $path, '/' );
  1028. preg_match_all( "/\/.*?\z/", $path, $matches );
  1029.  
  1030. /* If matches are found for the path. */
  1031. if ( isset( $matches ) ) {
  1032.  
  1033. /* Reverse the array of matches to search for posts in the proper order. */
  1034. $matches = array_reverse( $matches );
  1035.  
  1036. /* Loop through each of the path matches. */
  1037. foreach ( $matches as $match ) {
  1038.  
  1039. /* If a match is found. */
  1040. if ( isset( $match[0] ) ) {
  1041.  
  1042. /* Get the parent post by the given path. */
  1043. $path = str_replace( $match[0], '', $path );
  1044. $post = get_page_by_path( trim( $path, '/' ) );
  1045.  
  1046. /* If a parent post is found, set the $post_id and break out of the loop. */
  1047. if ( ! empty( $post ) && 0 < $post->ID ) {
  1048. $this->do_post_parents( $post->ID );
  1049. break;
  1050. }
  1051. }
  1052. }
  1053. }
  1054. }
  1055. }
  1056.  
  1057. /**
  1058. * Searches for term parents of hierarchical taxonomies. This function is similar to the WordPress
  1059. * function get_category_parents() but handles any type of taxonomy.
  1060. *
  1061. * @since 0.6.0
  1062. *
  1063. * @param int $term_id ID of the term to get the parents of.
  1064. * @param string $taxonomy Name of the taxonomy for the given term.
  1065. *
  1066. * @return void
  1067. */
  1068. function do_term_parents( $term_id, $taxonomy ) {
  1069.  
  1070. /* Set up some default arrays. */
  1071. $parents = array();
  1072.  
  1073. /* While there is a parent ID, add the parent term link to the $parents array. */
  1074. while ( $term_id ) {
  1075.  
  1076. /* Get the parent term. */
  1077. $term = get_term( $term_id, $taxonomy );
  1078.  
  1079. /* Add the formatted term link to the array of parent terms. */
  1080. $parents[] = '<a href="' . get_term_link( $term, $taxonomy ) . '" title="' . esc_attr( $term->name ) . '">' . $term->name . '</a>';
  1081.  
  1082. /* Set the parent term's parent as the parent ID. */
  1083. $term_id = $term->parent;
  1084. }
  1085.  
  1086. /* If we have parent terms, reverse the array to put them in the proper order for the trail. */
  1087. if ( ! empty( $parents ) ) {
  1088. $parents = array_reverse( $parents );
  1089. }
  1090. $this->items = array_merge( $this->items, $parents );
  1091. }
  1092.  
  1093. /**
  1094. * Turns %tag% from permalink structures into usable links for the breadcrumb trail. This feels kind of
  1095. * hackish for now because we're checking for specific %tag% examples and only doing it for the 'post'
  1096. * post type. In the future, maybe it'll handle a wider variety of possibilities, especially for custom post
  1097. * types.
  1098. *
  1099. * @since 0.6.0
  1100. * @access public
  1101. *
  1102. * @param int $post_id ID of the post whose parents we want.
  1103. * @param string $path Path of a potential parent page.
  1104. * @param array $args Mixed arguments for the menu.
  1105. *
  1106. * @return array
  1107. */
  1108. public function map_rewrite_tags( $post_id, $path ) {
  1109.  
  1110. /* Get the post based on the post ID. */
  1111. $post = get_post( $post_id );
  1112.  
  1113. /* If no post is returned, an error is returned, or the post does not have a 'post' post type, return. */
  1114. if ( empty( $post ) || is_wp_error( $post ) || 'post' !== $post->post_type ) {
  1115. return $trail;
  1116. }
  1117.  
  1118. /* Trim '/' from both sides of the $path. */
  1119. $path = trim( $path, '/' );
  1120.  
  1121. /* Split the $path into an array of strings. */
  1122. $matches = explode( '/', $path );
  1123.  
  1124. /* If matches are found for the path. */
  1125. if ( is_array( $matches ) ) {
  1126.  
  1127. /* Loop through each of the matches, adding each to the $trail array. */
  1128. foreach ( $matches as $match ) {
  1129.  
  1130. /* Trim any '/' from the $match. */
  1131. $tag = trim( $match, '/' );
  1132.  
  1133. /* If using the %year% tag, add a link to the yearly archive. */
  1134. if ( '%year%' == $tag ) {
  1135. $this->items[] = '<a href="' . get_year_link( get_the_time( 'Y', $post_id ) ) . '">' . sprintf( $this->args['labels']['archive_year'], get_the_time( _x( 'Y', 'yearly archives date format', 'kleo_framework' ) ) ) . '</a>';
  1136. } /* If using the %monthnum% tag, add a link to the monthly archive. */
  1137. elseif ( '%monthnum%' == $tag ) {
  1138. $this->items[] = '<a href="' . get_month_link( get_the_time( 'Y', $post_id ), get_the_time( 'm', $post_id ) ) . '">' . sprintf( $this->args['labels']['archive_month'], get_the_time( _x( 'F', 'monthly archives date format', 'kleo_framework' ) ) ) . '</a>';
  1139. } /* If using the %day% tag, add a link to the daily archive. */
  1140. elseif ( '%day%' == $tag ) {
  1141. $this->items[] = '<a href="' . get_day_link( get_the_time( 'Y', $post_id ), get_the_time( 'm', $post_id ), get_the_time( 'd', $post_id ) ) . '">' . sprintf( $this->args['labels']['archive_day'], get_the_time( _x( 'j', 'daily archives date format', 'kleo_framework' ) ) ) . '</a>';
  1142. } /* If using the %author% tag, add a link to the post author archive. */
  1143. elseif ( '%author%' == $tag ) {
  1144. $this->items[] = '<a href="' . get_author_posts_url( $post->post_author ) . '" title="' . esc_attr( get_the_author_meta( 'display_name', $post->post_author ) ) . '">' . get_the_author_meta( 'display_name', $post->post_author ) . '</a>';
  1145. } /* If using the %category% tag, add a link to the first category archive to match permalinks. */
  1146. elseif ( '%category%' == $tag ) {
  1147.  
  1148. /* Force override terms in this post type. */
  1149. $this->args['post_taxonomy'][ $post->post_type ] = false;
  1150.  
  1151. /* Get the post categories. */
  1152. $terms = get_the_category( $post_id );
  1153.  
  1154. /* Check that categories were returned. */
  1155. if ( $terms ) {
  1156.  
  1157. /* Sort the terms by ID and get the first category. */
  1158. usort( $terms, '_usort_terms_by_ID' );
  1159. $term = get_term( $terms[0], 'category' );
  1160.  
  1161. /* If the category has a parent, add the hierarchy to the trail. */
  1162. if ( 0 < $term->parent ) {
  1163. $this->do_term_parents( $term->parent, 'category' );
  1164. }
  1165.  
  1166. /* Add the category archive link to the trail. */
  1167. $this->items[] = '<a href="' . get_term_link( $term, 'category' ) . '" title="' . esc_attr( $term->name ) . '">' . $term->name . '</a>';
  1168. }
  1169. }
  1170. }
  1171. }
  1172. }
  1173. }
  1174.  
  1175. /**
  1176. * Extends the Breadcrumb_Trail class for bbPress. Only use this if bbPress is in use. This should
  1177. * serve as an example for other plugin developers to build custom breadcrumb items.
  1178. *
  1179. * @since 0.6.0
  1180. * @access public
  1181. */
  1182. class bbPress_Breadcrumb_Trail extends Breadcrumb_Trail {
  1183.  
  1184. /**
  1185. * Runs through the various bbPress conditional tags to check the current page being viewed. Once
  1186. * a condition is met, add items to the $items array.
  1187. *
  1188. * @since 0.6.0
  1189. * @access public
  1190. * @return void
  1191. */
  1192. public function do_trail_items() {
  1193.  
  1194. /* Add the network and site home links. */
  1195. $this->do_network_home_link();
  1196. $this->do_site_home_link();
  1197.  
  1198. /* Get the forum post type object. */
  1199. $post_type_object = get_post_type_object( bbp_get_forum_post_type() );
  1200.  
  1201. /* If not viewing the forum root/archive page and a forum archive exists, add it. */
  1202. if ( ! empty( $post_type_object->has_archive ) && ! bbp_is_forum_archive() ) {
  1203. $this->items[] = '<a href="' . get_post_type_archive_link( bbp_get_forum_post_type() ) . '">' . bbp_get_forum_archive_title() . '</a>';
  1204. }
  1205.  
  1206. /* If viewing the forum root/archive. */
  1207. if ( bbp_is_forum_archive() ) {
  1208.  
  1209. if ( true === $this->args['show_title'] ) {
  1210. $this->items[] = bbp_get_forum_archive_title();
  1211. }
  1212. } /* If viewing the topics archive. */
  1213. elseif ( bbp_is_topic_archive() ) {
  1214.  
  1215. if ( true === $this->args['show_title'] ) {
  1216. $this->items[] = bbp_get_topic_archive_title();
  1217. }
  1218. } /* If viewing a topic tag archive. */
  1219. elseif ( bbp_is_topic_tag() ) {
  1220.  
  1221. if ( true === $this->args['show_title'] ) {
  1222. $this->items[] = bbp_get_topic_tag_name();
  1223. }
  1224. } /* If viewing a topic tag edit page. */
  1225. elseif ( bbp_is_topic_tag_edit() ) {
  1226. $this->items[] = '<a href="' . bbp_get_topic_tag_link() . '">' . bbp_get_topic_tag_name() . '</a>';
  1227.  
  1228. if ( true === $this->args['show_title'] ) {
  1229. $this->items[] = __( 'Edit', 'kleo_framework' );
  1230. }
  1231. } /* If viewing a "view" page. */
  1232. elseif ( bbp_is_single_view() ) {
  1233.  
  1234. if ( true === $this->args['show_title'] ) {
  1235. $this->items[] = bbp_get_view_title();
  1236. }
  1237. } /* If viewing a single topic page. */
  1238. elseif ( bbp_is_single_topic() ) {
  1239.  
  1240. /* Get the queried topic. */
  1241. $topic_id = get_queried_object_id();
  1242.  
  1243. /* Get the parent items for the topic, which would be its forum (and possibly forum grandparents). */
  1244. $this->do_post_parents( bbp_get_topic_forum_id( $topic_id ) );
  1245.  
  1246. /* If viewing a split, merge, or edit topic page, show the link back to the topic. Else, display topic title. */
  1247. if ( bbp_is_topic_split() || bbp_is_topic_merge() || bbp_is_topic_edit() ) {
  1248. $this->items[] = '<a href="' . bbp_get_topic_permalink( $topic_id ) . '">' . bbp_get_topic_title( $topic_id ) . '</a>';
  1249. } elseif ( true === $this->args['show_title'] ) {
  1250. $this->items[] = bbp_get_topic_title( $topic_id );
  1251. }
  1252.  
  1253. /* If viewing a topic split page. */
  1254. if ( bbp_is_topic_split() && true === $this->args['show_title'] ) {
  1255. $this->items[] = __( 'Split', 'kleo_framework' );
  1256. } /* If viewing a topic merge page. */
  1257. elseif ( bbp_is_topic_merge() && true === $this->args['show_title'] ) {
  1258. $this->items[] = __( 'Merge', 'kleo_framework' );
  1259. } /* If viewing a topic edit page. */
  1260. elseif ( bbp_is_topic_edit() && true === $this->args['show_title'] ) {
  1261. $this->items[] = __( 'Edit', 'kleo_framework' );
  1262. }
  1263. } /* If viewing a single reply page. */
  1264. elseif ( bbp_is_single_reply() ) {
  1265.  
  1266. /* Get the queried reply object ID. */
  1267. $reply_id = get_queried_object_id();
  1268.  
  1269. /* Get the parent items for the reply, which should be its topic. */
  1270. $this->do_post_parents( bbp_get_reply_topic_id( $reply_id ) );
  1271.  
  1272. /* If viewing a reply edit page, link back to the reply. Else, display the reply title. */
  1273. if ( bbp_is_reply_edit() ) {
  1274. $this->items[] = '<a href="' . bbp_get_reply_url( $reply_id ) . '">' . bbp_get_reply_title( $reply_id ) . '</a>';
  1275.  
  1276. if ( true === $this->args['show_title'] ) {
  1277. $this->items[] = __( 'Edit', 'kleo_framework' );
  1278. }
  1279.  
  1280. } elseif ( true === $this->args['show_title'] ) {
  1281. $this->items[] = bbp_get_reply_title( $reply_id );
  1282. }
  1283.  
  1284. } /* If viewing a single forum. */
  1285. elseif ( bbp_is_single_forum() ) {
  1286.  
  1287. /* Get the queried forum ID and its parent forum ID. */
  1288. $forum_id = get_queried_object_id();
  1289. $forum_parent_id = bbp_get_forum_parent_id( $forum_id );
  1290.  
  1291. /* If the forum has a parent forum, get its parent(s). */
  1292. if ( 0 !== $forum_parent_id ) {
  1293. $this->do_post_parents( $forum_parent_id );
  1294. }
  1295.  
  1296. /* Add the forum title to the end of the trail. */
  1297. if ( true === $this->args['show_title'] ) {
  1298. $this->items[] = bbp_get_forum_title( $forum_id );
  1299. }
  1300. } /* If viewing a user page or user edit page. */
  1301. elseif ( bbp_is_single_user() || bbp_is_single_user_edit() ) {
  1302.  
  1303. if ( bbp_is_single_user_edit() ) {
  1304. $this->items[] = '<a href="' . bbp_get_user_profile_url() . '">' . bbp_get_displayed_user_field( 'display_name' ) . '</a>';
  1305.  
  1306. if ( true === $this->args['show_title'] ) {
  1307. $this->items[] = __( 'Edit', 'kleo_framework' );
  1308. }
  1309. } elseif ( true === $this->args['show_title'] ) {
  1310. $this->items[] = bbp_get_displayed_user_field( 'display_name' );
  1311. }
  1312. }
  1313.  
  1314. /* Return the bbPress breadcrumb trail items. */
  1315. $this->items = apply_filters( 'breadcrumb_trail_get_bbpress_items', $this->items, $this->args );
  1316. }
  1317. }
  1318.  
  1319.  
  1320. /**
  1321. * Generates the Buddypress breadcrumbs if Buddypress is installed
  1322. *
  1323. * @global Object $bp The BuddyPress $bp object
  1324. *
  1325. * @param array $trail A reference to the trail array from the above function
  1326. *
  1327. * @return array
  1328. */
  1329. class buddypress_Breadcrumb_Trail extends Breadcrumb_Trail {
  1330.  
  1331. /**
  1332. * Runs through the various buddyPress conditional tags to check the current page being viewed. Once
  1333. * a condition is met, add items to the $items array.
  1334. *
  1335. * @since 0.6.0
  1336. * @access public
  1337. * @return void
  1338. */
  1339. public function do_trail_items() {
  1340. global $bp;
  1341. /* Add the network and site home links. */
  1342. $this->do_network_home_link();
  1343. $this->do_site_home_link();
  1344.  
  1345. $trail_end = '';
  1346.  
  1347. if ( ! empty( $bp->displayed_user->fullname ) ) { // looking at a user or self
  1348. $this->items[] = '<a href="' . bp_get_members_directory_permalink() . '">' . get_the_title( $bp->pages->members->id ) . '</a>';
  1349. $this->items[] = '<a href="' . $bp->displayed_user->domain . '" title="' . strip_tags( $bp->displayed_user->userdata->display_name ) . '">' . strip_tags( $bp->displayed_user->userdata->display_name ) . '</a>';
  1350.  
  1351. } else if ( $bp->is_single_item ) { // we're on a single item page
  1352. $this->items[] = '<a href="' . get_permalink( $bp->pages->{$bp->current_component}->id ) . '" title="' . esc_attr( strip_tags( get_the_title( $bp->pages->{$bp->current_component}->id ) ) ) . '">' . get_the_title( $bp->pages->{$bp->current_component}->id ) . '</a>';
  1353. $this->items[] = '<a href="' . get_permalink() . '" title="' . esc_attr( $bp->bp_options_title ) . '">' . $bp->bp_options_title . '</a>';
  1354.  
  1355. } else if ( $bp->is_directory ) { // this is a top level directory page
  1356. $trail_end = get_the_title( $bp->pages->{$bp->current_component}->id );
  1357. } else if ( bp_is_register_page() ) {
  1358. $trail_end = __( 'Create an Account', 'buddypress' );
  1359. } else if ( bp_is_activation_page() ) {
  1360. $trail_end = __( 'Activate your Account', 'buddypress' );
  1361. } else if ( bp_is_group_create() ) {
  1362. $this->items[] = '<a href="' . get_permalink( $bp->pages->groups->id ) . '" title="' . esc_attr( get_the_title( $bp->pages->groups->id ) ) . '">' . get_the_title( $bp->pages->groups->id ) . '</a>';
  1363.  
  1364. $trail_end = __( 'Create a Group', 'buddypress' );
  1365.  
  1366. } else if ( bp_is_create_blog() ) {
  1367. $this->items[] = '<a href="' . home_url() . '/' . $bp->current_component . '" title="' . ucwords( $bp->current_component ) . '">' . ucwords( $bp->current_component ) . '</a>';
  1368. $trail_end = __( 'Create a Blog', 'buddypress' );
  1369. }
  1370. if ( $trail_end ) {
  1371. $this->items[] = $trail_end;
  1372. }
  1373.  
  1374. /* Return the bbPress breadcrumb trail items. */
  1375. $this->items = apply_filters( 'breadcrumb_trail_get_buddypress_items', $this->items, $this->args );
  1376. }
  1377. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement