From 3015814146de769b1053d2121544e562a77f98e6 Mon Sep 17 00:00:00 2001 From: dufresnesteven Date: Sun, 15 Jan 2023 13:00:18 +0900 Subject: [PATCH 01/10] Fix breadcrumbs. --- .../themes/wporg-developer-2023/functions.php | 25 +++++++++++ .../inc/breadcrumb-trail.php | 10 ++--- .../wporg-developer-2023/parts/header.html | 4 +- .../src/breadcrumbs/block.json | 30 +++++++++++++ .../src/breadcrumbs/index.js | 20 +++++++++ .../src/breadcrumbs/index.php | 45 +++++++++++++++++++ .../src/breadcrumbs/style.scss | 3 ++ 7 files changed, 130 insertions(+), 7 deletions(-) create mode 100644 source/wp-content/themes/wporg-developer-2023/src/breadcrumbs/block.json create mode 100644 source/wp-content/themes/wporg-developer-2023/src/breadcrumbs/index.js create mode 100644 source/wp-content/themes/wporg-developer-2023/src/breadcrumbs/index.php create mode 100644 source/wp-content/themes/wporg-developer-2023/src/breadcrumbs/style.scss diff --git a/source/wp-content/themes/wporg-developer-2023/functions.php b/source/wp-content/themes/wporg-developer-2023/functions.php index 0a7433ee4..602f368a2 100644 --- a/source/wp-content/themes/wporg-developer-2023/functions.php +++ b/source/wp-content/themes/wporg-developer-2023/functions.php @@ -137,6 +137,7 @@ require __DIR__ . '/inc/block-hooks.php'; // Block files +require_once __DIR__ . '/src/breadcrumbs/index.php'; require_once __DIR__ . '/src/code-changelog/block.php'; require_once __DIR__ . '/src/code-deprecated/block.php'; require_once __DIR__ . '/src/code-description/block.php'; @@ -177,6 +178,7 @@ function init() { // Modify default breadcrumbs. add_filter( 'breadcrumb_trail_items', __NAMESPACE__ . '\\breadcrumb_trail_items_for_hooks', 10, 2 ); + add_filter( 'breadcrumb_trail_items', __NAMESPACE__ . '\\breadcrumb_trail_items_remove_reference', 11, 2 ); add_filter( 'breadcrumb_trail_items', __NAMESPACE__ . '\\breadcrumb_trail_items_for_handbook_root', 10, 2 ); add_filter( 'mkaz_code_syntax_force_loading', '__return_true' ); @@ -214,6 +216,29 @@ function breadcrumb_trail_items_for_hooks( $items, $args ) { return $items; } +/** + * Remove the 'Reference' part of the breadcrumb trail. + * + * @param array $items The breadcrumb trail items. + * @param array $args Original args. + * @return array + */ +function breadcrumb_trail_items_remove_reference( $items, $args ) { + if ( ! is_singular() && ! is_single() && ! is_post_type_archive() ) { + return $items; + } + + return array_filter( + $items, + function( $item ) { + // Remove the 'reference' parent based on the presence of its URL. + // We can't use the label because of internationalization. + $result = (bool) preg_match( '/href=".*\/reference\/"/', $item, $matches ); + return ( false === $result ); + } + ); +} + /** * Fix breadcrumb for handbook root pages. * diff --git a/source/wp-content/themes/wporg-developer-2023/inc/breadcrumb-trail.php b/source/wp-content/themes/wporg-developer-2023/inc/breadcrumb-trail.php index 3229fb2bb..53e82a3b4 100644 --- a/source/wp-content/themes/wporg-developer-2023/inc/breadcrumb-trail.php +++ b/source/wp-content/themes/wporg-developer-2023/inc/breadcrumb-trail.php @@ -38,7 +38,7 @@ function breadcrumb_trail( $args = array() ) { else $breadcrumb = new Breadcrumb_Trail( $args ); - $breadcrumb->trail(); + return $breadcrumb->trail(); } /** @@ -89,8 +89,8 @@ public function __construct( $args = array() ) { 'network' => false, //'show_edit_link' => false, 'show_title' => true, - 'show_browse' => true, - 'echo' => true, + 'show_browse' => false, + 'echo' => false, /* Post taxonomy (examples follow). */ 'post_taxonomy' => array( @@ -187,8 +187,8 @@ public function default_labels() { $labels = array( 'browse' => __( 'Browse:', 'breadcrumb-trail' ), - 'home' => __( 'Home', 'breadcrumb-trail' ), - 'search' => __( 'Search results for "%s"', 'breadcrumb-trail' ), + 'home' => __( 'Developer', 'breadcrumb-trail' ), + 'search' => __( 'Result', 'breadcrumb-trail' ), 'error_404' => __( '404 Not Found', 'breadcrumb-trail' ), 'paged' => __( 'Page %d', 'breadcrumb-trail' ), 'archives' => __( 'Archives', 'breadcrumb-trail' ), diff --git a/source/wp-content/themes/wporg-developer-2023/parts/header.html b/source/wp-content/themes/wporg-developer-2023/parts/header.html index f2d6c343f..9a9e47cb5 100644 --- a/source/wp-content/themes/wporg-developer-2023/parts/header.html +++ b/source/wp-content/themes/wporg-developer-2023/parts/header.html @@ -2,8 +2,8 @@