An ID or a WP_Post object.
* @param array $taxonomies An array of taxonomy names.
* @param false $skipUnselectedTerms Allow unselected terms to be filtered out from the crumbs.
* @return array An array of the taxonomy name + a term hierarchy.
*/
public function getPostTaxTermHierarchy( $post, $taxonomies = [], $skipUnselectedTerms = false ) {
// Get all taxonomies attached to the post.
if ( empty( $taxonomies ) ) {
$taxonomies = get_object_taxonomies( get_post_type( $post ), 'objects' );
$taxonomies = wp_filter_object_list( $taxonomies, [ 'public' => true ], 'and', 'name' );
}
foreach ( $taxonomies as $taxonomy ) {
$primaryTerm = aioseo()->standalone->primaryTerm->getPrimaryTerm( $post->ID, $taxonomy );
$terms = wp_get_object_terms( $post->ID, $taxonomy );
// Use the first taxonomy with terms.
if ( empty( $terms ) || is_wp_error( $terms ) ) {
continue;
}
// Determines the lengthier term hierarchy.
$termHierarchy = [];
foreach ( $terms as $term ) {
// Gets our filtered ancestors.
$ancestors = $this->getFilteredTermHierarchy( $term->term_id, $term->taxonomy, $skipUnselectedTerms ? $terms : [] );
// Merge the current term to be used in the breadcrumbs.
$ancestors = array_merge( $ancestors, [ $term->term_id ] );
// If the current term is the primary term, use it.
if ( is_a( $primaryTerm, 'WP_Term' ) && $primaryTerm->term_id === $term->term_id ) {
$termHierarchy = $ancestors;
break;
}
$termHierarchy = ( count( $termHierarchy ) < count( $ancestors ) ) ? $ancestors : $termHierarchy;
}
// Return a top to bottom hierarchy.
return [
'taxonomy' => $taxonomy,
'terms' => $termHierarchy
];
}
return [];
}
/**
* Filters a term's parent hierarchy against other terms.
*
* @since 4.1.1
*
* @param int $termId A term id.
* @param string $taxonomy The taxonomy name.
* @param array $termsToFilterAgainst Terms to filter out of the hierarchy.
* @return array The term's parent hierarchy.
*/
public function getFilteredTermHierarchy( $termId, $taxonomy, $termsToFilterAgainst = [] ) {
$ancestors = $this->getTermHierarchy( $termId, $taxonomy );
// Keep only selected terms in the hierarchy.
if ( ! empty( $termsToFilterAgainst ) ) {
// If it's a WP_Term array make it a term_id array.
if ( is_a( current( $termsToFilterAgainst ), 'WP_Term' ) ) {
$termsToFilterAgainst = wp_list_pluck( $termsToFilterAgainst, 'term_id' );
}
$ancestors = array_intersect( $ancestors, $termsToFilterAgainst );
}
return $ancestors;
}
/**
* Gets a term's parent hierarchy.
*
* @since 4.1.1
*
* @param int $termId A term id.
* @param string $taxonomy A taxonomy name.
* @return array The term parent hierarchy.
*/
public function getTermHierarchy( $termId, $taxonomy ) {
// Return a top to bottom hierarchy.
return array_reverse( get_ancestors( $termId, $taxonomy, 'taxonomy' ) );
}
/**
* Gets a post's parent hierarchy.
*
* @since 4.1.1
*
* @param int|\WP_Post $post An ID or a WP_Post object.
* @return array The post parent hierarchy.
*/
public function getPostHierarchy( $post ) {
$postId = ! empty( $post->ID ) ? $post->ID : $post;
// Return a top to bottom hierarchy.
return array_reverse( get_ancestors( $postId, '', 'post_type' ) );
}
/**
* Register our breadcrumb widget.
*
* @since 4.1.1
*
* @return void
*/
public function registerWidget() {
if ( aioseo()->helpers->canRegisterLegacyWidget( 'aioseo-breadcrumb-widget' ) ) {
register_widget( 'AIOSEO\Plugin\Common\Breadcrumbs\Widget' );
}
}
}
}
namespace {
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! function_exists( 'aioseo_breadcrumbs' ) ) {
/**
* Global function for breadcrumbs output.
*
* @since 4.1.1
*
* @param boolean $echo Echo or return the output.
* @return string|void The output.
*/
function aioseo_breadcrumbs( $echo = true ) {
return aioseo()->breadcrumbs->frontend->display( $echo );
}
}
}
Fatal error: Uncaught Error: Class "AIOSEO\Plugin\Common\Breadcrumbs\Breadcrumbs" not found in /home/valigeria/public_html/wp-content/plugins/all-in-one-seo-pack-pro/app/Pro/Breadcrumbs/Breadcrumbs.php:14
Stack trace:
#0 /home/valigeria/public_html/wp-content/plugins/all-in-one-seo-pack-pro/vendor/composer/ClassLoader.php(576): include()
#1 /home/valigeria/public_html/wp-content/plugins/all-in-one-seo-pack-pro/vendor/composer/ClassLoader.php(427): Composer\Autoload\{closure}('/home/valigeria...')
#2 /home/valigeria/public_html/wp-content/plugins/all-in-one-seo-pack-pro/app/AIOSEO.php(285): Composer\Autoload\ClassLoader->loadClass('AIOSEO\\Plugin\\P...')
#3 /home/valigeria/public_html/wp-content/plugins/all-in-one-seo-pack-pro/app/AIOSEO.php(97): AIOSEO\Plugin\AIOSEO->load()
#4 /home/valigeria/public_html/wp-content/plugins/all-in-one-seo-pack-pro/app/AIOSEO.php(76): AIOSEO\Plugin\AIOSEO->init()
#5 /home/valigeria/public_html/wp-content/plugins/all-in-one-seo-pack-pro/app/AIOSEO.php(414): AIOSEO\Plugin\AIOSEO::instance()
#6 /home/valigeria/public_html/wp-content/plugins/all-in-one-seo-pack-pro/all_in_one_seo_pack.php(96): aioseo()
#7 /home/valigeria/public_html/wp-settings.php(517): include_once('/home/valigeria...')
#8 /home/valigeria/public_html/wp-config.php(111): require_once('/home/valigeria...')
#9 /home/valigeria/public_html/wp-load.php(50): require_once('/home/valigeria...')
#10 /home/valigeria/public_html/wp-blog-header.php(13): require_once('/home/valigeria...')
#11 /home/valigeria/public_html/index.php(17): require('/home/valigeria...')
#12 {main}
thrown in /home/valigeria/public_html/wp-content/plugins/all-in-one-seo-pack-pro/app/Pro/Breadcrumbs/Breadcrumbs.php on line 14