From 062a675158322a742b5d1c423768eb1a14bc8266 Mon Sep 17 00:00:00 2001 From: deepench Date: Mon, 28 Sep 2026 08:11:29 +0100 Subject: [PATCH] Fix three breadcrumb bugs: date archive links, comma in category names, PHP warning on bad author URLs All three confirmed live, not just from source: 1. Date archive month link pointed at /YYYY/00/, a dead URL that still 200s. get_month_link() takes a numeric month, but the code passed get_the_time('M') (the month name, e.g. "Sep") instead of get_the_time('m'). Also added the missing space between the day suffix and month name ("15thMar" -> "15th Mar"), and stopped passing date-format codes ('Y', 'M', 'm', 'jS') through __() - they're PHP date() format characters, not translatable text, and only ever collided with the month-link bug because nobody noticed the untranslated fallback still worked. 2. A category name containing a comma (a perfectly normal name, e.g. "Food, Drink") broke the breadcrumb markup. The code built one comma-joined string via get_category_parents(..., ',') then split it back apart with explode(',', ...), so the comma in the name itself got mistaken for the separator - opening an in one
  • and closing it in the next. Rebuilt from actual term objects via get_ancestors()/get_term(), which can't confuse a name for a separator. 3. A non-existent author archive URL (which WordPress core still answers with HTTP 200) logged "PHP Warning: Attempt to read property 'display_name' on false" on every anonymous visit, since get_userdata() was used unchecked. Added the missing existence check. Same code, same bugs, in both Free and Pro's inc/extras.php. --- inc/extras.php | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/inc/extras.php b/inc/extras.php index 0541d2a..a43e8f2 100644 --- a/inc/extras.php +++ b/inc/extras.php @@ -218,14 +218,18 @@ function flash_breadcrumbs() { $slice_array = array_slice( $category, -1 ); $last_category = array_pop( $slice_array ); - // Get parent any categories and create array - $get_cat_parents = rtrim( get_category_parents( $last_category->term_id, true, ',' ), ',' ); - $cat_parents = explode( ',', $get_cat_parents ); + // Get parent categories and the category itself, top-most ancestor first. + $cat_ancestors = array_reverse( get_ancestors( $last_category->term_id, 'category' ) ); + $cat_ancestors[] = $last_category->term_id; // Loop through parent categories and store in variable $cat_display $cat_display = ''; - foreach ( $cat_parents as $parents ) { - $cat_display .= '
  • ' . $parents . '
  • '; + foreach ( $cat_ancestors as $cat_id ) { + $cat_term = get_term( $cat_id, 'category' ); + + if ( $cat_term && ! is_wp_error( $cat_term ) ) { + $cat_display .= '
  • ' . esc_html( $cat_term->name ) . '
  • '; + } } } @@ -294,28 +298,28 @@ function flash_breadcrumbs() { // Day archive // Year link - echo '
  • ' . esc_html( get_the_time( __( 'Y', 'flash' ) ) ) . '
  • '; + echo '
  • ' . esc_html( get_the_time( 'Y' ) ) . '
  • '; // Month link - echo '
  • ' . esc_html( get_the_time( __( 'M', 'flash' ) ) ) . '
  • '; + echo '
  • ' . esc_html( get_the_time( 'M' ) ) . '
  • '; // Day display - echo '
  • ' . esc_html( get_the_time( __( 'jS', 'flash' ) ) . get_the_time( __( 'M', 'flash' ) ) ) . '
  • '; + echo '
  • ' . esc_html( get_the_time( 'jS' ) . ' ' . get_the_time( 'M' ) ) . '
  • '; } elseif ( is_month() ) { // Month Archive // Year link - echo '
  • ' . esc_html( get_the_time( __( 'Y', 'flash' ) ) ) . '
  • '; + echo '
  • ' . esc_html( get_the_time( 'Y' ) ) . '
  • '; // Month link - echo '
  • ' . esc_html( get_the_time( __( 'M', 'flash' ) ) ) . '
  • '; + echo '
  • ' . esc_html( get_the_time( 'M' ) ) . '
  • '; } elseif ( is_year() ) { // Display year archive - echo '
  • ' . esc_html( get_the_time( __( 'Y', 'flash' ) ) ) . '
  • '; + echo '
  • ' . esc_html( get_the_time( 'Y' ) ) . '
  • '; } elseif ( is_author() ) { @@ -326,7 +330,9 @@ function flash_breadcrumbs() { $userdata = get_userdata( $author ); // Display author name - echo '
  • ' . esc_html( $userdata->display_name ) . '
  • '; + if ( $userdata ) { + echo '
  • ' . esc_html( $userdata->display_name ) . '
  • '; + } } elseif ( get_query_var( 'paged' ) ) {