humanmade / humanmade/tachyon-plugin

Fix warnings when `filter_the_content` cannot find a valid attachment id

Open
#85 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
PHP
Stars
86
Forks
16
PR merge metrics
No merged PRs in 30d

Description

This code in [inc/class-tachyon.php](https://github.com/humanmade/tachyon-plugin/blob/e41d716e7455f8f7a07cf2631bf93c5b58932176/inc/class-tachyon.php#L322). Can cause warnings.

```php
$src_per_wp = wp_get_attachment_image_src( $attachment_id, $size );

if ( self::validate_image_url( $src_per_wp[0] ) ) {
$src = $src_per_wp[0];
$fullsize_url = true;
...
```

If the return from `wp_get_attachment_image_src` is `false`, which it can be, the code should not continue as if it got the array of image data.

The call to `validate_image_url` generates a warning:
"Trying to access array offset on value of type bool"

and then the first line in `validate_image_url` generates another warning:
"parse_url(): Passing null parameter #1 ($url) of type string is deprecated"

I don't understand how the $attachement_id might be invalid, or reference an invalid image, but we know this does happen in the wild.

---

## Acceptance Criteria

- [ ] Content with invalid attachment id does not generate these warnings
- [ ] Document testing on the ticket

---

## For Altis Team Use

### Ready for Work Checklist

Is this ticket ready to be worked on? See
[the Play Book Definition of Ready](https://playbook.hmn.md/play/product/definition-of-ready/)

- [x] Is the title clear?
- [x] Is the description clear and detailed enough?
- [x] Are acceptance criteria listed?
- [x] Have any dependencies been identified? (Optional)
- [x] Have any documentation/playbook changes been identified? (Optional)
- [x] Is an estimate or time box assigned?
- [x] Is a priority label assigned?
- [ ] Is this ticket added to a milestone?
- [ ] Is this ticket added to an epic? (Optional)

### Completion Checklist

Is this ticket done? See
[the Play Book Definition of Done](https://playbook.hmn.md/play/product/definition-of-done-2/)

- [ ] Has the acceptance criteria been met?
- [ ] Is the documentation updated (including README)?
- [ ] Do any code/documentation changes meet project standards?
- [ ] Are automatic tests in place to verify the fix or new functionality?
- [ ] Or are manual tests documented (at least on this ticket)?
- [ ] Are any Playbook/Handbook pages updated?
- [ ] Has a new module release (patch/minor) been created/scheduled?
- [ ] Have the appropriate `backport` labels been added to the PR?
- [ ] Is there a roll-out (and roll-back) plan if required?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.