Skip to content

Fix array offset warning in slider for non-library images - #88

Open
deepench wants to merge 1 commit into
developfrom
fix/slider-image-size-warning
Open

deepench wants to merge 1 commit into
developfrom
fix/slider-image-size-warning

Conversation

@deepench

@deepench deepench commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Free-theme counterpart of themegrill/accelerate-pro#48 (also tracked as the closed #79).

Changes proposed in this Pull Request:

The slider threw "Trying to access array offset on value of type bool" for any slide whose image isn't in the media library (an external URL, or one that was removed). attachment_url_to_postid() returns 0 for those, so wp_get_attachment_image_src() returns false, and header-functions.php then read [1] and [2] from it for the <img> width and height without checking. The width and height are now only printed when the image data exists; the image still renders from its URL either way.

Verified live on the front page with a slide pointing at an external image URL (forced temporarily, since removed): before, two warnings (width and height); after, none, and the <img> still renders with its src and alt.

How to test the changes in this Pull Request:

  1. Enable WP_DEBUG and WP_DEBUG_DISPLAY.
  2. In Appearance > Customize > Slider Options, activate the slider and set Slider Introduced Grunt Tasks #1's image to a URL that isn't in the media library (for example https://example.com/a.jpg).
  3. Load the front page and confirm there is no "Trying to access array offset" warning and the slide still shows.
  4. Set the image from the media library and confirm the <img> still gets width and height.

Types of changes:

  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (modification of the currently available functionality)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Other information:

  • Have you added an explanation of what your changes do and why you would like us to include them?
  • Have you successfully ran tests with your changes locally?
  • Have you updated the documentation accordingly?

Changelog entry

Fix - PHP warning in the slider when a slide image is not in the media library.

…edia library

attachment_url_to_postid() returns 0 for a slide image that isn't in the
media library, so wp_get_attachment_image_src() returns false and the
width/height were read from it unguarded. They are now only printed when
the image data exists; the image itself still renders from its URL.

Verified live: a slide with an external image URL logged two "Trying to
access array offset on false" warnings before and none after, and the
image still renders.
@deepench deepench added the bug label Oct 1, 2026
@tg-autopilot
tg-autopilot requested a lite review from Copilot October 1, 2026 04:24
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown

QA suite — refused, no regression spec

This PR changes product source but adds no spec, so the suite was
refused before booting WordPress — running it just to report the same
thing at the end costs runner minutes for nothing. Run
/claudegrill:verify-fix locally and let write-spec add the guard
to this branch, then push again.

Source files changed with no matching spec
inc/header-functions.php

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

No unresolved review issues remain.

Review effort: Lite
Findings: None

What changed in this PR

Fixes slider warnings for images not associated with media-library attachments while preserving image rendering.

Changes:

  • Guards optional width and height attributes.
  • Preserves external or missing-library image URLs.
File Description
inc/​header-functions.php Safely renders slider image dimensions.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@deepench deepench self-assigned this Oct 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants