Skip to content

Fix warnings when filter_the_content cannot find a valid attachment id #85

@mikelittle

Description

@mikelittle

This code in inc/class-tachyon.php. Can cause warnings.

$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

  • Is the title clear?
  • Is the description clear and detailed enough?
  • Are acceptance criteria listed?
  • Have any dependencies been identified? (Optional)
  • Have any documentation/playbook changes been identified? (Optional)
  • Is an estimate or time box assigned?
  • 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

  • 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugExisting functionality isn't behaving as expected

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions