humanmade / humanmade/asset-manager-framework

Empty image sizes file values

Open
#53 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
188
Forks
6
Avg merge
6d 21h
Merged PRs (30d)
1

Description

In our implementation when writing a provider for AMF, on local environments where production images are missing, I'm seeing a number of [media.php](https://github.com/WordPress/WordPress/blob/73157386d069425c5e6ea7c4fc0122e8a9b58a7b/wp-includes/media.php#L1357) warnings `strpos(): Empty needle`.

When debugging it appears that for these images, both `$dirname` and `$file` are empty.

I added this workaround, to repopulate the file value with the one from `$image_meta`:
```php
add_filter( 'wp_calculate_image_srcset_meta', __NAMESPACE__ . '\\insert_missing_meta_sizes_values', 10, 1 );
[..]

/**
* Some images that are not locally available, have empty values causing warnings.
*
* @param array $image_meta
*
* @return array Updated image meta sizes array with empty file values replaced.
*/
function insert_missing_meta_sizes_values( array $image_meta ) : array {
foreach ( $image_meta['sizes'] as $key => $size ) {
if ( empty( $size['file'] ) ) {
$image_meta['sizes'][ $key ]['file'] = $image_meta['file'];
}
}
return $image_meta;
}
```

When I have AMF/Provider disabled, I don't see these warnings. It could be an assumption on AMF's part or something else in our codebase, but wanted to report this in case this helps solving the issue should it be AMF related.

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.