diff --git a/source/wp-content/themes/wporg-developer-2023/functions.php b/source/wp-content/themes/wporg-developer-2023/functions.php index 0a7433ee4..38958af8b 100644 --- a/source/wp-content/themes/wporg-developer-2023/functions.php +++ b/source/wp-content/themes/wporg-developer-2023/functions.php @@ -36,7 +36,7 @@ require __DIR__ . '/inc/loop-pagination.php'; } -if ( ! function_exists( 'breadcrumb_trail' ) ) { +if ( ! function_exists( 'get_breadcrumbs' ) ) { require __DIR__ . '/inc/breadcrumb-trail.php'; } @@ -156,6 +156,7 @@ require_once __DIR__ . '/src/search-usage-info/index.php'; add_action( 'init', __NAMESPACE__ . '\\init' ); +add_filter( 'wporg_block_site_breadcrumbs', __NAMESPACE__ . '\set_site_breadcrumbs' ); /** * Set up the theme. @@ -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() && ! is_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 ); + return ( false === $result ); + } + ); +} + /** * Fix breadcrumb for handbook root pages. * @@ -352,3 +377,24 @@ function rename_comments_meta_box( $post_type, $post ) { function update_prism_css_path( $path ) { return '/stylesheets/prism.css'; } + +/** + * Filters breadcrumb items for the site-breadcrumb block. + * + * @return array + */ +function set_site_breadcrumbs() { + $breadcrumbs = array(); + + foreach ( get_breadcrumbs()->items as $crumb ) { + // Get the link and title from the breadcrumb. + preg_match( '!]+href="(?P[^"]+)"[^>]*>(?P.+)</a>!', $crumb, $matches ); + + $breadcrumbs[] = array( + 'url' => $matches['href'] ?? '', + 'title' => $matches['title'] ?? $crumb, + ); + } + + return $breadcrumbs; +} 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..fd2fcaaaa 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 @@ -31,14 +31,14 @@ * @param array $args Arguments to pass to Breadcrumb_Trail. * @return void */ -function breadcrumb_trail( $args = array() ) { +function get_breadcrumbs( $args = array() ) { if ( function_exists( 'is_bbpress' ) && is_bbpress() ) $breadcrumb = new bbPress_Breadcrumb_Trail( $args ); else $breadcrumb = new Breadcrumb_Trail( $args ); - $breadcrumb->trail(); + return $breadcrumb; } /** @@ -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( @@ -110,72 +110,6 @@ public function __construct( $args = array() ) { $this->do_trail_items(); } - /** - * Formats and outputs the breadcrumb trail. - * - * @since 0.6.0 - * @access public - * @return string - */ - public function trail() { - - $breadcrumb = ''; - - /* Connect the breadcrumb trail if there are items in the trail. */ - if ( !empty( $this->items ) && is_array( $this->items ) ) { - - /* Make sure we have a unique array of items. */ - $this->items = array_unique( $this->items ); - - /* Open the breadcrumb trail containers. */ - $breadcrumb = "\n\t\t" . '<' . tag_escape( $this->args['container'] ) . ' class="breadcrumb-trail breadcrumbs" itemprop="breadcrumb">'; - - /* If $before was set, wrap it in a container. */ - $breadcrumb .= ( !empty( $this->args['before'] ) ? "\n\t\t\t" . '<' . tag_escape( $this->args['item_container'] ) . ' class="trail-before">' . $this->args['before'] . '</' . tag_escape( $this->args['item_container'] ) . '> ' . "\n\t\t\t" : '' ); - - /* Add 'browse' label if it should be shown. */ - if ( true === $this->args['show_browse'] ) - $breadcrumb .= "\n\t\t\t" . '<' . tag_escape( $this->args['item_container'] ) . ' class="trail-browse">' . $this->args['labels']['browse'] . '</' . tag_escape( $this->args['item_container'] ) . '> '; - - /* Format the separator. */ - $separator = false === $this->args['separator'] ? - '' : - ' <' . tag_escape( $this->args['item_container'] ) . ' class="sep">' . ( ! empty( $this->args['separator'] ) ? $this->args['separator'] : '/' ) . '</' . tag_escape( $this->args['item_container'] ) . '> '; - - /* Adds the 'trail-begin' class around first item if there's more than one item. */ - if ( 1 < count( $this->items ) ) { - $breadcrumb .= "\n\t\t\t" . '<' . tag_escape( $this->args['item_container'] ) . ' class="trail-begin">' . array_shift( $this->items ) . '</' . tag_escape( $this->args['item_container'] ) . '>'; - $breadcrumb .= $separator; - } - - /* Adds the 'trail-end' class around last item. */ - $last = '<' . tag_escape( $this->args['item_container'] ) . ' class="trail-end">' . array_pop( $this->items ) . '</' . tag_escape( $this->args['item_container'] ) . '>'; - - /* Join the individual trail items. */ - foreach ( $this->items as $item ) { - $breadcrumb .= "\n\t\t\t" . '<' . tag_escape( $this->args['item_container'] ) . ' class="trail-inner">' . $item . '</' . tag_escape( $this->args['item_container'] ) . '>'; - $breadcrumb .= $separator; - } - - /* Append the last item. */ - $breadcrumb .= $last; - - /* If $after was set, wrap it in a container. */ - $breadcrumb .= ( !empty( $this->args['after'] ) ? "\n\t\t\t" . ' <' . tag_escape( $this->args['item_container'] ) . ' class="trail-after">' . $this->args['after'] . '</' . tag_escape( $this->args['item_container'] ) . '>' : '' ); - - /* Close the breadcrumb trail containers. */ - $breadcrumb .= "\n\t\t" . '</' . tag_escape( $this->args['container'] ) . '>'; - } - - /* Allow developers to filter the breadcrumb trail HTML. */ - $breadcrumb = apply_filters( 'breadcrumb_trail', $breadcrumb, $this->args ); - - if ( true === $this->args['echo'] ) - echo $breadcrumb; - else - return $breadcrumb; - } - /** * Returns an array of the default labels. * @@ -187,8 +121,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/inc/cli.php b/source/wp-content/themes/wporg-developer-2023/inc/cli.php index ea8729c34..4627e7277 100644 --- a/source/wp-content/themes/wporg-developer-2023/inc/cli.php +++ b/source/wp-content/themes/wporg-developer-2023/inc/cli.php @@ -21,7 +21,6 @@ public static function init() { add_action( 'pre_get_posts', array( __CLASS__, 'action_pre_get_posts' ) ); add_action( 'devhub_cli_manifest_import', array( __CLASS__, 'action_devhub_cli_manifest_import' ) ); add_action( 'devhub_cli_markdown_import', array( __CLASS__, 'action_devhub_cli_markdown_import' ) ); - add_filter( 'breadcrumb_trail', array( __CLASS__, 'filter_breadcrumb_trail' ) ); add_filter( 'the_content', array( __CLASS__, 'filter_the_content' ) ); } @@ -277,29 +276,6 @@ public static function get_markdown_source( $post_id ) { return $markdown_source; } - /** - * Filter the breadcrumb trail to include quick links - */ - public static function filter_breadcrumb_trail( $breadcrumbs ) { - if ( 'command' !== get_post_type() || ! is_singular() ) { - return $breadcrumbs; - } - - $content = get_queried_object()->post_content; - $content = self::prepend_installation( $content ); - $content = self::append_subcommands( $content ); - $items = self::get_tags( 'h([1-4])', $content ); - if ( count( $items ) > 1 ) { - $quick_links = '<span class="quick-links">('; - foreach( $items as $item ) { - $quick_links .= '<a href="#' . sanitize_title_with_dashes( $item[3] ) . '">' . strtolower( $item[3] ) . '</a>|'; - } - $quick_links = rtrim( $quick_links, '|' ) . ')</span>'; - $breadcrumbs = str_replace( '</div>', $quick_links . '</div>', $breadcrumbs ); - } - return $breadcrumbs; - } - /** * Filter the content of command pages */ 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..d05013f2a 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 @@ <!-- wp:group {"align":"full","style":{"spacing":{"padding":{"top":"16px","right":"var:preset|spacing|edge-space","bottom":"16px","left":"var:preset|spacing|edge-space"}},"elements":{"link":{"color":{"text":"var:preset|color|white"}}}},"backgroundColor":"blueberry-1","textColor":"white","className":"is-sticky","layout":{"type":"constrained"}} --> <div class="wp-block-group alignfull is-sticky has-white-color has-blueberry-1-background-color has-text-color has-background has-link-color" style="padding-top:16px;padding-right:var(--wp--preset--spacing--edge-space);padding-bottom:16px;padding-left:var(--wp--preset--spacing--edge-space)"><!-- wp:group {"align":"full","layout":{"type":"flex","flexWrap":"wrap","justifyContent":"space-between"}} --> -<div class="wp-block-group alignfull"><!-- wp:group {"layout":{"type":"flex","flexWrap":"nowrap"},"className":"wporg-site-breadcrumbs-container"} --> -<div class="wp-block-group wporg-site-breadcrumbs-container"><!-- wp:wporg/site-breadcrumbs {"fontSize":"small"} /--></div> +<div class="wp-block-group alignfull"><!-- wp:group {"layout":{"type":"flex","flexWrap":"nowrap"}} --> +<div class="wp-block-group"><!-- wp:wporg/site-breadcrumbs /--></div> <!-- /wp:group --> <!-- wp:navigation {"textColor":"white","backgroundColor":"blueberry-1","className":"is-style-dropdown-on-mobile","style":{"spacing":{"blockGap":"24px"}},"fontSize":"small"} -->