Skip to content

Commit

Permalink
Wrapping $attributes['id'] in an isset check to catch undefined indexes
Browse files Browse the repository at this point in the history
Formatting
  • Loading branch information
ramonjd committed Oct 27, 2021
1 parent 585fc17 commit 6f594cc
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/block-library/src/image/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
* @return string Returns the block content with the data-id attribute added.
*/
function render_block_core_image( $attributes, $content ) {
if ( $attributes['id'] ) {
if ( isset( $attributes['id'] ) ) {
// Add the data-id="$id" attribute to the img element to retain backwards compatibility.
$data_id_attribute = 'data-id="' . esc_attr( $attributes['id'] ) . '"';
$data_id_attribute = 'data-id="' . esc_attr( $attributes['id'] ) . '"';
if ( ! strpos( $content, $data_id_attribute ) ) {
$content = str_replace( '<img', '<img ' . $data_id_attribute . ' ', $content );
}
Expand Down

0 comments on commit 6f594cc

Please sign in to comment.