post = get_post( apply_filters( 'fusion_breadcrumb_post_id', get_queried_object_id() ) ); // Setup default array for changeable variables. $defaults = [ 'home_prefix' => $fusion_settings->get( 'breacrumb_prefix' ) ? $fusion_settings->get( 'breacrumb_prefix' ) : '', 'separator' => $fusion_settings->get( 'breadcrumb_separator' ) ? $fusion_settings->get( 'breadcrumb_separator' ) : '', 'show_post_type_archive' => $fusion_settings->get( 'breadcrumb_show_post_type_archive' ) ? $fusion_settings->get( 'breadcrumb_show_post_type_archive' ) : '', 'show_leaf' => $fusion_settings->get( 'breadcrumb_show_leaf' ) ? $fusion_settings->get( 'breadcrumb_show_leaf' ) : '', 'show_terms' => $fusion_settings->get( 'breadcrumb_show_categories' ) ? $fusion_settings->get( 'breadcrumb_show_categories' ) : '', 'home_label' => $fusion_settings->get( 'breacrumb_home_label' ) ? $fusion_settings->get( 'breacrumb_home_label' ) : esc_html__( 'Home', 'Avada' ), 'tag_archive_prefix' => esc_html__( 'Tag:', 'Avada' ), 'search_prefix' => esc_html__( 'Search:', 'Avada' ), 'error_prefix' => esc_html__( '404 - Page not Found', 'Avada' ), 'use_microdata' => $fusion_settings->get( 'disable_date_rich_snippet_pages' ) && $fusion_settings->get( 'disable_rich_snippet_title' ), ]; // Setup a filter for changeable variables and merge it with the defaults. $defaults = apply_filters( 'fusion_breadcrumbs_defaults', $defaults ); if ( ! empty( $element_args ) ) { $defaults = wp_parse_args( $element_args, $defaults ); } $this->home_prefix = $defaults['home_prefix']; $this->separator = $defaults['separator']; $this->show_post_type_archive = $defaults['show_post_type_archive']; $this->show_leaf = $defaults['show_leaf']; $this->show_terms = $defaults['show_terms']; $this->home_label = $defaults['home_label']; $this->tag_archive_prefix = $defaults['tag_archive_prefix']; $this->search_prefix = $defaults['search_prefix']; $this->error_prefix = $defaults['error_prefix']; $this->use_microdata = $defaults['use_microdata']; } /** * Get a unique instance of this object. * * @access public * @since 2.2 * @return object */ public static function get_instance() { if ( null === self::$instance ) { self::$instance = new Fusion_Breadcrumbs(); } return self::$instance; } /** * Publicly accessible function to get the full breadcrumb HTML markup. * * @access public * @since 2.2 * @return void */ public function get_breadcrumbs() { // Support for Yoast Breadcrumbs. if ( function_exists( 'yoast_breadcrumb' ) ) { $this->html_markup = yoast_breadcrumb( '', '', false ); } // Support for RankMath breadcrumbs. if ( empty( $this->html_markup ) && function_exists( 'rank_math_get_breadcrumbs' ) ) { $this->html_markup = rank_math_get_breadcrumbs( [] ); } // ThemeFusion Breadcrumbs. if ( empty( $this->html_markup ) ) { $this->prepare_breadcrumb_data(); $this->set_breadcrumbs_output(); } $this->wrap_breadcrumbs(); $this->output_breadcrumbs_html(); } /** * Publicly accessible function to get breadcrumbs data for element. * * @access public * @since 2.2 * @return string HTML output. */ public function get_element_breadcrumbs() { // Support for Yoast Breadcrumbs. if ( function_exists( 'yoast_breadcrumb' ) ) { $this->html_markup = yoast_breadcrumb( '', '', false ); } // Support for RankMath breadcrumbs. if ( empty( $this->html_markup ) && function_exists( 'rank_math_get_breadcrumbs' ) ) { $this->html_markup = rank_math_get_breadcrumbs( [] ); } // ThemeFusion Breadcrumbs. if ( empty( $this->html_markup ) ) { $this->prepare_breadcrumb_data(); $this->set_breadcrumbs_output(); } return $this->html_markup; } /** * Wrap the breadcrumb path in a nav tag. * * @access private * @since 2.2 * @return void */ private function wrap_breadcrumbs() { $class = 'fusion-breadcrumbs'; $class = function_exists( 'yoast_breadcrumb' ) ? $class . ' awb-yoast-breadcrumbs' : $class; $class = ( 'fusion-breadcrumbs' !== $class && function_exists( 'rank_math_get_breadcrumbs' ) ) ? $class . ' awb-rankmath-breadcrumbs' : $class; $this->html_markup = ''; } /** * Output the full breadcrumb HTML markup. * * @access private * @since 2.2 * @return void */ private function output_breadcrumbs_html() { echo $this->html_markup; // phpcs:ignore WordPress.Security.EscapeOutput } /** * Prepares breadcrumb data. * * @access private * @since 2.2 * @return void */ private function prepare_breadcrumb_data() { $fusion_settings = awb_get_fusion_settings(); // Add breadcrumb prefix. $this->breadcrumbs_parts['prefix'] = $this->get_single_breadcrumb_data( $this->home_prefix, '', false, false, false, '' ); // Add the "Home" link. if ( is_home() && is_front_page() && $fusion_settings->get( 'blog_title' ) ) { // If the home page is the main blog page. $this->breadcrumbs_parts['home'] = $this->get_single_breadcrumb_data( $fusion_settings->get( 'blog_title' ), '', false, true, true ); } else { $separator = is_front_page() ? false : true; $this->breadcrumbs_parts['home'] = $this->get_single_breadcrumb_data( $this->home_label, get_home_url(), $separator, true, false, 'awb-home' ); // Make sure the breadcrumb does not get doubled up. if ( is_front_page() ) { return; } } // Woocommerce path prefix (e.g "Shop" ). if ( class_exists( 'WooCommerce' ) && ( ( Fusion_Helper::is_woocommerce() && is_archive() && ! is_shop() ) || is_cart() || is_checkout() || is_account_page() ) && $this->show_post_type_archive ) { $this->breadcrumbs_parts['shop'] = $this->get_woocommerce_shop_page_data(); } // Path prefix for bbPress (e.g "Forums" ). if ( class_exists( 'bbPress' ) && Fusion_Helper::is_bbpress() && ( Fusion_Helper::bbp_is_topic_archive() || bbp_is_single_user() || Fusion_Helper::bbp_is_search() ) ) { $this->breadcrumbs_parts['bbpress'] = $this->get_single_breadcrumb_data( bbp_get_forum_archive_title(), get_post_type_archive_link( 'forum' ) ); } // Single Posts and Pages (of all post types). if ( is_singular() ) { // If the post type of the current post has an archive link, display the archive breadcrumb. if ( isset( $this->post->post_type ) && get_post_type_archive_link( $this->post->post_type ) && $this->show_post_type_archive ) { $this->breadcrumbs_parts['post_type_archive'] = $this->get_post_type_archive_data(); } // If the post doesn't have parents. if ( isset( $this->post->post_parent ) && 0 == $this->post->post_parent ) { // phpcs:ignore WordPress.PHP.StrictComparisons.LooseComparison $this->set_post_terms_data(); } else { // If there are parents; mostly for pages. $this->set_post_ancestors_data(); } $this->breadcrumbs_parts['leaf'] = $this->get_single_breadcrumb_data( $this->get_breadcrumb_leaf_label(), '', false, false, true, '' ); } else { // Blog page is a dedicated page. if ( is_home() && ! is_front_page() ) { // If TEC events page is set as front page. if ( function_exists( 'tribe_is_event_query' ) && tribe_is_event_query() ) { return; } $posts_page = get_option( 'page_for_posts' ); $posts_page_title = get_the_title( $posts_page ); $this->breadcrumbs_parts['posts_page'] = $this->get_single_breadcrumb_data( $posts_page_title, '', true, true, true ); } elseif ( ( is_tax() || is_tag() || is_category() || is_date() || is_author() ) && $this->show_post_type_archive && ! Fusion_Helper::is_woocommerce() && ! Fusion_Helper::is_bbpress() ) { $this->breadcrumbs_parts['post_type_archive'] = $this->get_post_type_archive_data(); } // Custom post types archives. if ( is_post_type_archive() ) { // Search on custom post type (e.g. Woocommerce). if ( is_search() ) { $this->breadcrumbs_parts['post_type_archive'] = $this->get_post_type_archive_data(); $this->breadcrumbs_parts['leaf'] = $this->get_single_breadcrumb_data( $this->get_breadcrumb_leaf_label( 'search' ), '', false, false, true, '' ); } else { $this->breadcrumbs_parts['post_type_archive'] = $this->get_post_type_archive_data( false ); } } elseif ( is_tax() || is_tag() || is_category() ) { // Taxonomy Archives. if ( is_tag() ) { // If we have a tag archive, add the tag prefix. $this->breadcrumbs_parts['tags_prefix'] = $this->get_single_breadcrumb_data( $this->tag_archive_prefix . ' ', '', false, false, false, '' ); } $this->set_taxonomies_data(); $this->breadcrumbs_parts['leaf'] = $this->get_single_breadcrumb_data( $this->get_breadcrumb_leaf_label( 'term' ), '', false, false, true, '' ); } elseif ( is_date() ) { // Date Archives. global $wp_locale; $year = esc_html( get_query_var( 'year' ) ); if ( ! $year ) { $year = substr( esc_html( get_query_var( 'm' ) ), 0, 4 ); } // Year Archive, only is a leaf. if ( is_year() ) { $this->breadcrumbs_parts['leaf'] = $this->get_single_breadcrumb_data( $this->get_breadcrumb_leaf_label( 'year' ), '', false, false, true, '' ); } elseif ( is_month() ) { // Month Archive, needs year link and month leaf. $this->breadcrumbs_parts['year'] = $this->get_single_breadcrumb_data( $year, get_year_link( $year ) ); $this->breadcrumbs_parts['leaf'] = $this->get_single_breadcrumb_data( $this->get_breadcrumb_leaf_label( 'month' ), '', false, false, true, '' ); } elseif ( is_day() ) { // Day Archive, needs year and month link and day leaf. global $wp_locale; $month = get_query_var( 'monthnum' ); if ( ! $month ) { $month = substr( esc_html( get_query_var( 'm' ) ), 4, 2 ); } $month_name = $wp_locale->get_month( $month ); $this->breadcrumbs_parts['year'] = $this->get_single_breadcrumb_data( $year, get_year_link( $year ) ); $this->breadcrumbs_parts['month'] = $this->get_single_breadcrumb_data( $month_name, get_month_link( $year, $month ) ); $this->breadcrumbs_parts['leaf'] = $this->get_single_breadcrumb_data( $this->get_breadcrumb_leaf_label( 'day' ), '', false, false, true, '' ); } } elseif ( is_author() ) { // Author Archives. $this->breadcrumbs_parts['leaf'] = $this->get_single_breadcrumb_data( $this->get_breadcrumb_leaf_label( 'author' ), '', false, false, true, '' ); } elseif ( is_search() ) { // Search Page. $this->breadcrumbs_parts['leaf'] = $this->get_single_breadcrumb_data( $this->get_breadcrumb_leaf_label( 'search' ), '', false, false, false, '' ); } elseif ( is_404() ) { // 404 Page. // Special treatment for Events Calendar to avoid 404 messages on list view. if ( Fusion_Helper::tribe_is_event() || Fusion_Helper::is_events_archive() ) { $this->breadcrumbs_parts['leaf'] = $this->get_single_breadcrumb_data( $this->get_breadcrumb_leaf_label( 'events' ), '', false, false, false, '' ); } else { $this->breadcrumbs_parts['leaf'] = $this->get_single_breadcrumb_data( $this->get_breadcrumb_leaf_label( '404' ), '', false, false, false, '' ); } } elseif ( class_exists( 'bbPress' ) ) { // bbPress. // Search Page. if ( Fusion_Helper::bbp_is_search() ) { $this->breadcrumbs_parts['leaf'] = $this->get_single_breadcrumb_data( $this->get_breadcrumb_leaf_label( 'bbpress_search' ), '', false, false, true, '' ); } elseif ( bbp_is_single_user() ) { // User page. $this->breadcrumbs_parts['leaf'] = $this->get_single_breadcrumb_data( $this->get_breadcrumb_leaf_label( 'bbpress_user' ), '', false, false, true, '' ); } } } } /** * Constructs an array with all information for a single part of a breadcrumbs path. * * @access private * @since 2.2 * @param string $label The label that should be displayed. * @param string $url The URL of the breadcrumb. * @param bool $separator Set to TRUE to show the separator at the end of the breadcrumb. * @param bool $microdata Set to FALSE to make sure we get a link not being part of the breadcrumb microdata path. * @param bool $is_leaf Set to TRUE to make sure leaf markup is added to the span. * @param string $extra_class An extra class to be added. * @return array The data of a single breadcrumb. */ private function get_single_breadcrumb_data( $label, $url = '', $separator = true, $microdata = true, $is_leaf = false, $extra_class = '' ) { $breadcrumb_data = [ 'label' => $label, 'url' => $url, 'extra_class' => $extra_class, 'separator' => $separator, 'microdata' => $microdata, 'is_leaf' => $is_leaf, ]; return $breadcrumb_data; } /** * Returns the markup of a single breadcrumb. * * @access private * @since 2.2 * @param array $data The breadcrumb data. * @return string The HTML markup of a single breadcrumb. */ private function get_breadcrumb_markup( $data ) { if ( empty( $data['label'] ) || ( $data['is_leaf'] && ! $this->show_leaf ) ) { return ''; } // Create JSON-lD for structured data output. if ( $data['microdata'] && $this->use_microdata ) { // Add item to JSON-LD. new Fusion_JSON_LD( 'fusion-breadcrumbs', [ '@context' => 'https://schema.org', '@type' => 'BreadcrumbList', 'itemListElement' => [ [ '@type' => 'ListItem', 'position' => $this->item_position, 'name' => $data['label'], 'item' => $data['url'], ], ], ] ); // Increment position. $this->item_position++; } $leaf_markup = $data['is_leaf'] ? ' class="breadcrumb-leaf"' : ''; // Set the home prefix item. $leaf_markup = isset( $data['home_prefix'] ) ? ' class="fusion-breadcrumb-prefix"' : $leaf_markup; $breadcrumb_content = '' . wp_strip_all_tags( $data['label'] ) . ''; // If a link is set add its markup. if ( $data['url'] ) { $breadcrumb_content = '' . $breadcrumb_content . ''; } // If a separator should be added, add the needed class for it. $classes = $data['separator'] ? ' awb-breadcrumb-sep' : ''; // If an extra class was set, add it in. $classes = $data['extra_class'] ? $classes . ' ' . $data['extra_class'] : $classes; // If we need the leaf araia attribute, add it. $leaf_markup = $data['is_leaf'] ? ' aria-current="page"' : ''; // Set the home prefix item. $leaf_markup = isset( $data['home_prefix'] ) ? ' aria-hidden="true"' : $leaf_markup; return '