<?php
|
/**
|
* Breadcrumb Helper Functions
|
*
|
* These are backwards-compatible wrappers around BreadcrumbManager
|
* Use BreadcrumbManager directly for new code
|
*/
|
|
use JVBase\managers\SEO\BreadcrumbManager;
|
|
if (!defined('ABSPATH')) {
|
exit;
|
}
|
|
/**
|
* Get breadcrumb array for current page
|
*
|
* @deprecated Use BreadcrumbManager::getInstance()->getCrumbs() instead
|
* @return array
|
*/
|
function jvbGetCrumbs(): array
|
{
|
return BreadcrumbManager::getInstance()->getCrumbs();
|
}
|
|
/**
|
* Build and return breadcrumb navigation HTML
|
*
|
* @deprecated Use BreadcrumbManager::getInstance()->renderNavigation() instead
|
* @return string
|
*/
|
function jvbBuildBreadcrumbs(): string
|
{
|
return BreadcrumbManager::getInstance()->renderNavigation();
|
}
|
|
/**
|
* Build post hierarchy for breadcrumbs
|
*
|
* @deprecated Use BreadcrumbManager directly - this is now a private method
|
* @param WP_Post $post
|
* @param array $crumbs
|
* @return array
|
*/
|
function jvbGetBreadcrumbPostHierarchy(WP_Post $post, array $crumbs = []): array
|
{
|
// This functionality is now private in BreadcrumbManager
|
// If you need this, use the full getCrumbs() method instead
|
trigger_error('jvbGetBreadcrumbPostHierarchy is deprecated. Use BreadcrumbManager::getInstance()->getCrumbs()', E_USER_DEPRECATED);
|
|
array_unshift($crumbs, [
|
'name' => $post->post_title,
|
'url' => get_the_permalink($post->ID),
|
'id' => $post->ID,
|
]);
|
|
if ($post->post_parent !== 0) {
|
$parent = get_post($post->post_parent);
|
if ($parent) {
|
$crumbs = jvbGetBreadcrumbPostHierarchy($parent, $crumbs);
|
}
|
}
|
|
return $crumbs;
|
}
|
|
/**
|
* Build term hierarchy for breadcrumbs
|
*
|
* @deprecated Use BreadcrumbManager directly - this is now a private method
|
* @param WP_Term $term
|
* @param array $crumbs
|
* @return array
|
*/
|
function jvbGetBreadcrumbTermHierarchy(WP_Term $term, array $crumbs = []): array
|
{
|
// This functionality is now private in BreadcrumbManager
|
trigger_error('jvbGetBreadcrumbTermHierarchy is deprecated. Use BreadcrumbManager::getInstance()->getCrumbs()', E_USER_DEPRECATED);
|
|
$url = get_term_link($term->term_id);
|
array_unshift($crumbs, [
|
'name' => $term->name,
|
'url' => $url,
|
'id' => $term->term_id,
|
]);
|
|
if ($term->parent !== 0) {
|
$parent = get_term($term->parent, $term->taxonomy);
|
if ($parent && !is_wp_error($parent)) {
|
$crumbs = jvbGetBreadcrumbTermHierarchy($parent, $crumbs);
|
}
|
}
|
|
return $crumbs;
|
}
|
|
/**
|
* Get directory info (kept for now as it's not breadcrumb-specific)
|
*
|
* @return array
|
*/
|
function jvbGetDirectoryInfo(): array
|
{
|
if (is_post_type_archive(BASE.'directory')) {
|
return [
|
'title' => 'Directory of Directories',
|
'url' => get_post_type_archive_link(BASE.'directory'),
|
'slug' => 'directory',
|
'type' => 'directory'
|
];
|
}
|
|
if (is_singular(BASE.'directory')) {
|
$type = get_post_meta(get_the_ID(), BASE.'for_type_slug', true);
|
return jvbDirectories()[$type] ?? [];
|
}
|
|
$obj = get_queried_object();
|
$directories = jvbDirectories();
|
|
if (is_tax()) {
|
$tax = jvbNoBase($obj->taxonomy);
|
return array_key_exists($tax, $directories) ? $directories[$tax] : [];
|
}
|
|
$type = jvbNoBase($obj->post_type);
|
return array_key_exists($type, $directories) ? $directories[$type] : [];
|
}
|