Skip to content

Empty image sizes file values #53

@svandragt

Description

@svandragt

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 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:

	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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions