Skip to content

Fix PHP warning for array offset on bool in generate_meta_tags#130

Open
enescala wants to merge 1 commit into
sailthru:masterfrom
enescala:fix/meta-tags-array-offset-warning
Open

Fix PHP warning for array offset on bool in generate_meta_tags#130
enescala wants to merge 1 commit into
sailthru:masterfrom
enescala:fix/meta-tags-array-offset-warning

Conversation

@enescala

@enescala enescala commented Mar 10, 2026

Copy link
Copy Markdown

Summary

  • Fixes $post->ID$post_object->ID in generate_meta_tags() to match the rest of the method
  • Adds is_array() checks before accessing wp_get_attachment_image_src() return values, which returns false when the attachment is missing

Test plan

  • Verify no PHP warnings on posts with thumbnails
  • Verify no PHP warnings on posts without thumbnails
  • Verify Sailthru meta tags still render correctly for image.full and image.thumb

Fixes #129

Copilot AI review requested due to automatic review settings March 10, 2026 20:37
@enescala
enescala force-pushed the fix/meta-tags-array-offset-warning branch from d722e31 to 7ef8994 Compare March 10, 2026 20:39

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.

Pull request overview

This PR addresses PHP warnings in the Sailthru Horizon meta tag generation path by fixing post ID usage and safely handling missing attachment image data in generate_meta_tags().

Changes:

  • Replace $post->ID with $post_object->ID when fetching the post thumbnail ID.
  • Guard accesses to wp_get_attachment_image_src() results with is_array() checks to avoid array-offset-on-bool warnings.

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

Comment thread classes/class-sailthru-content.php Outdated
Comment thread classes/class-sailthru-content.php Outdated
- Use $post_object->ID instead of $post->ID for consistency with
  the rest of the method
- Add is_array() checks on wp_get_attachment_image_src() return
  values before accessing array offsets
- Store get_post_thumbnail_id() result in a local variable to
  avoid duplicate calls
- Remove redundant esc_attr() to prevent double-escaping since
  the output loop already escapes tag values

Fixes sailthru#129
@enescala
enescala force-pushed the fix/meta-tags-array-offset-warning branch from fb81bd8 to ffd6f0a Compare March 10, 2026 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PHP Warning: Trying to access array offset on value of type bool in generate_meta_tags

2 participants