Changeset 48170 for trunk/src/wp-includes/media.php
- Timestamp:
- 06/25/2020 06:43:25 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/media.php
r48110 r48170 1496 1496 * 1497 1497 * @since 4.4.0 1498 * @since 5.5.0 `width` and `height` are now added if not already present. 1498 1499 * 1499 1500 * @see wp_calculate_image_srcset() … … 1525 1526 return $image; 1526 1527 } 1528 1529 $attr = ''; 1527 1530 1528 1531 $width = preg_match( '/ width="([0-9]+)"/', $image, $match_width ) ? (int) $match_width[1] : 0; … … 1548 1551 } 1549 1552 } 1550 } 1551 1552 if ( ! $width || ! $height ) { 1553 return $image; 1553 1554 if ( ! $width || ! $height ) { 1555 return $image; 1556 } 1557 1558 // Add width and height if not present. 1559 $attr .= ' ' . trim( image_hwstring( $width, $height ) ); 1554 1560 } 1555 1561 … … 1568 1574 if ( $srcset && $sizes ) { 1569 1575 // Format the 'srcset' and 'sizes' string and escape attributes. 1570 $attr = sprintf( ' srcset="%s"', esc_attr( $srcset ) );1576 $attr .= sprintf( ' srcset="%s"', esc_attr( $srcset ) ); 1571 1577 1572 1578 if ( is_string( $sizes ) ) { 1573 1579 $attr .= sprintf( ' sizes="%s"', esc_attr( $sizes ) ); 1574 1580 } 1575 1576 // Add 'srcset' and 'sizes' attributes to the image markup. 1577 $image = preg_replace( '/<img ([^>]+?)[\/ ]*>/', '<img $1' . $attr . ' />', $image ); 1578 } 1579 1580 return $image; 1581 } 1582 1583 if ( empty( $attr ) ) { 1584 return $image; 1585 } 1586 1587 // Add extra attributes to the image markup. 1588 return preg_replace( '/<img ([^>]+?)[\/ ]*>/', '<img $1' . $attr . ' />', $image ); 1581 1589 } 1582 1590 … … 1713 1721 if ( ! in_array( $value, array( 'lazy', 'eager' ), true ) ) { 1714 1722 $value = 'lazy'; 1723 } 1724 1725 // Images should have dimension attributes for the `loading` attribute 1726 // to be added. 1727 if ( false === strpos( $image, ' width=' ) || false === strpos( $image, ' height=' ) ) { 1728 return $image; 1715 1729 } 1716 1730
Note: See TracChangeset
for help on using the changeset viewer.