Skip to content

Fixed PHP undefined array key warning#2769

Merged
vytisbulkevicius merged 2 commits intodevelopmentfrom
bugfix/2768
Apr 1, 2026
Merged

Fixed PHP undefined array key warning#2769
vytisbulkevicius merged 2 commits intodevelopmentfrom
bugfix/2768

Conversation

@girishpanchal30
Copy link
Copy Markdown
Contributor

Closes #2768

Summary

Checked that the fontVariant is set and not empty.

Checklist before the final review

  • Included E2E or unit tests for the changes in this PR.
  • Visual elements are not affected by independent changes.
  • It is at least compatible with the minimum WordPress version.
  • It loads additional script in frontend only if it is required.
  • Does not impact the Core Web Vitals.
  • In case of deprecation, old blocks are safely migrated.
  • It is usable in Widgets and FSE.
  • Copy/Paste is working if the attributes are modified.
  • PR is following the best practices

@girishpanchal30 girishpanchal30 requested a review from Copilot April 1, 2026 06:52
@girishpanchal30 girishpanchal30 added the pr-checklist-skip Allow this Pull Request to skip checklist. label Apr 1, 2026
@pirate-bot pirate-bot added the pr-checklist-complete The Pull Request checklist is complete. (automatic label) label Apr 1, 2026
@pirate-bot
Copy link
Copy Markdown
Contributor

Bundle Size Diff

Package Old Size New Size Diff
Animations 276.77 KB 276.77 KB 0 B (0.00%)
Blocks 1.55 MB 1.55 MB 0 B (0.00%)
CSS 105.9 KB 105.9 KB 0 B (0.00%)
Dashboard 204.08 KB 204.08 KB 0 B (0.00%)
Onboarding 165.94 KB 165.94 KB 0 B (0.00%)
Export Import 102.86 KB 102.86 KB 0 B (0.00%)
Pro 412.21 KB 412.21 KB 0 B (0.00%)

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 for fontVariant before using it in the in_array() variant de-duplication logic.
  • Prevents get_google_fonts() from reading a missing fontVariant key during static block CSS generation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 153 to 154
} 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'] );
Copy link

Copilot AI Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
} 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;
}

Copilot uses AI. Check for mistakes.
@pirate-bot
Copy link
Copy Markdown
Contributor

pirate-bot commented Apr 1, 2026

Plugin build for 779830a is ready 🛎️!

@pirate-bot
Copy link
Copy Markdown
Contributor

pirate-bot commented Apr 1, 2026

E2E Tests

Playwright Test Status:

Performance Results serverResponse: {"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}

@vytisbulkevicius vytisbulkevicius merged commit 7ebde40 into development Apr 1, 2026
11 checks passed
@vytisbulkevicius vytisbulkevicius deleted the bugfix/2768 branch April 1, 2026 10:07
@pirate-bot
Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 3.1.8 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@pirate-bot pirate-bot added the released Indicate that an issue has been resolved and released in a particular version of the product. label Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-checklist-complete The Pull Request checklist is complete. (automatic label) pr-checklist-skip Allow this Pull Request to skip checklist. released Indicate that an issue has been resolved and released in a particular version of the product.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants