Fixed PHP undefined array key warning#2769
Conversation
Bundle Size Diff
|
There was a problem hiding this comment.
Pull request overview
This PR addresses a PHP warning reported in Sentry (Undefined array key "fontVariant") by guarding access to the fontVariant block attribute when collecting Google Fonts data in the CSS pipeline.
Changes:
- Adds
isset()/!empty()checks forfontVariantbefore using it in thein_array()variant de-duplication logic. - Prevents
get_google_fonts()from reading a missingfontVariantkey during static block CSS generation.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
inc/class-base-css.php
Outdated
| } elseif ( isset( $attr['fontVariant'] ) && ! empty( $attr['fontVariant'] ) && ! in_array( $attr['fontVariant'], self::$google_fonts[ $attr['fontFamily'] ]['fontvariant'], true ) ) { | ||
| array_push( self::$google_fonts[ $attr['fontFamily'] ]['fontvariant'], ( isset( $attr['fontStyle'] ) && 'italic' === $attr['fontStyle'] ) ? $attr['fontVariant'] . ':i' : $attr['fontVariant'] ); |
There was a problem hiding this comment.
get_google_fonts() currently checks for duplicates using the raw fontVariant, but may push a different value when fontStyle is italic (appending :i). This makes the de-duplication inconsistent and can also generate an invalid Google Fonts css2 :wght@... URL downstream (see get_fonts() which expects plain numeric weights). Consider normalizing the variant once (including any italic representation) and using that same normalized value for both the in_array check and what gets stored, and/or updating the font URL builder to support ital/wght syntax if italic variants are required.
| } elseif ( isset( $attr['fontVariant'] ) && ! empty( $attr['fontVariant'] ) && ! in_array( $attr['fontVariant'], self::$google_fonts[ $attr['fontFamily'] ]['fontvariant'], true ) ) { | |
| array_push( self::$google_fonts[ $attr['fontFamily'] ]['fontvariant'], ( isset( $attr['fontStyle'] ) && 'italic' === $attr['fontStyle'] ) ? $attr['fontVariant'] . ':i' : $attr['fontVariant'] ); | |
| } elseif ( isset( $attr['fontVariant'] ) && ! empty( $attr['fontVariant'] ) ) { | |
| $font_variant = $attr['fontVariant']; | |
| if ( ! in_array( $font_variant, self::$google_fonts[ $attr['fontFamily'] ]['fontvariant'], true ) ) { | |
| self::$google_fonts[ $attr['fontFamily'] ]['fontvariant'][] = $font_variant; | |
| } |
|
Plugin build for 779830a is ready 🛎️!
|
E2E TestsPlaywright Test Status: Performance ResultsserverResponse: {"q25":428,"q50":430.65,"q75":465.6,"cnt":10}, firstPaint: {"q25":325.1,"q50":414.5,"q75":440.4,"cnt":10}, domContentLoaded: {"q25":1595.6,"q50":1627.35,"q75":1648,"cnt":10}, loaded: {"q25":1596,"q50":1627.85,"q75":1648.3,"cnt":10}, firstContentfulPaint: {"q25":3425.1,"q50":3454.95,"q75":3477.8,"cnt":10}, firstBlock: {"q25":7004.4,"q50":7086,"q75":7167.9,"cnt":10}, type: {"q25":14.57,"q50":15.24,"q75":15.63,"cnt":10}, typeWithoutInspector: {"q25":13.32,"q50":13.69,"q75":13.87,"cnt":10}, typeWithTopToolbar: {"q25":18.22,"q50":18.37,"q75":19.52,"cnt":10}, typeContainer: {"q25":7.88,"q50":8.18,"q75":9.47,"cnt":10}, focus: {"q25":58.54,"q50":61.32,"q75":64.25,"cnt":10}, inserterOpen: {"q25":17.53,"q50":18.27,"q75":20.89,"cnt":10}, inserterSearch: {"q25":5.87,"q50":6.14,"q75":6.66,"cnt":10}, inserterHover: {"q25":3.06,"q50":3.14,"q75":3.31,"cnt":20}, loadPatterns: {"q25":1129.73,"q50":1143,"q75":1183.09,"cnt":10}, listViewOpen: {"q25":96.04,"q50":98.77,"q75":106.59,"cnt":10} |
|
🎉 This PR is included in version 3.1.8 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Closes #2768
Summary
Checked that the
fontVariantis set and not empty.Checklist before the final review