Skip to content

Commit

Permalink
Fixes #6814 Prevent PHP warning undefined property type (#6834)
Browse files Browse the repository at this point in the history
  • Loading branch information
remyperona authored Aug 9, 2024
1 parent 48d8afa commit c427503
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion inc/Engine/Media/AboveTheFold/AJAX/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use WP_Rocket\Engine\Media\AboveTheFold\Database\Queries\AboveTheFold as ATFQuery;
use WP_Rocket\Engine\Common\Context\ContextInterface;
use WP_Rocket\Engine\Optimization\UrlTrait;
use WP_Rocket\Logger\Logger;
use WP_Rocket\Engine\Common\PerformanceHints\AJAX\ControllerInterface;

class Controller implements ControllerInterface {
Expand Down Expand Up @@ -182,7 +183,24 @@ private function create_object( $image, $keys ) {
if ( isset( $image->src ) && ! empty( $image->src ) && is_string( $image->src ) ) {
$object->src = $this->sanitize_image_url( $image->src );
}
$object->sources = $image->sources;
$object->sources = array_map(
function ( $source ) {
if ( empty( $source->type ) ) {
Logger::notice( 'The source type is missing in the image object.', [ 'source' => $source ] );
}

return (object) wp_parse_args(
$source,
[
'media' => '',
'sizes' => '',
'srcset' => '',
'type' => '',
]
);
},
$image->sources
);
break;
default:
// For other types, add the first non-empty key to the object.
Expand Down

0 comments on commit c427503

Please sign in to comment.