Skip to content

Commit

Permalink
Update based on CR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel-glo committed Aug 30, 2024
1 parent cece755 commit fdea6e0
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions safe-svg.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ public function fix_admin_preview( $response, $attachment, $meta ) {
*/
public function one_pixel_fix( $image, $attachment_id, $size, $icon ) {
if ( get_post_mime_type( $attachment_id ) === 'image/svg+xml' ) {
$dimensions = $this->set_svg_dimensions( $attachment_id, $size );
$dimensions = $this->get_svg_dimensions( $attachment_id, $size );

if ( $dimensions && $dimensions['height'] && $dimensions['width'] ) {
$image[1] = $dimensions['width'];
Expand Down Expand Up @@ -451,7 +451,7 @@ public function load_custom_admin_style() {
public function get_image_tag_override( $html, $id, $alt, $title, $align, $size ) {
$mime = get_post_mime_type( $id );
if ( 'image/svg+xml' === $mime ) {
$dimensions = $this->set_svg_dimensions( $id, $size );
$dimensions = $this->get_svg_dimensions( $id, $size );

if ( $dimensions['height'] && $dimensions['width'] ) {
$html = str_replace( 'width="1" ', sprintf( 'width="%s" ', $dimensions['width'] ), $html );
Expand Down Expand Up @@ -718,21 +718,21 @@ protected function str_ends_with( $haystack, $needle ) {
}

/**
* Set custom width or height of the SVG image.
* Return custom width or height of the SVG image.
*
* @param int $id Image attachment ID.
* @param string|array $size Size of image. Image size or array of width and height values
* (in that order). Default 'thumbnail'.
*
* @return int|false Width or height of the SVG image, or false if not found.
* @return array|bool Width or height of the SVG image, or false if not found.
*/
protected function set_svg_dimensions( $id, $size ) {
protected function get_svg_dimensions( $id, $size ) {
$dimensions = $this->svg_dimensions( $id );

if ( is_array( $size ) ) {
$width = $size[0];
$height = $size[1];
} elseif ( 'full' === $size && $dimensions ) {
} elseif ( 'full' === $size && is_array( $dimensions ) && isset( $dimensions['width'], $dimensions['height'] ) ) {
$width = $dimensions['width'];
$height = $dimensions['height'];
} else {
Expand Down

0 comments on commit fdea6e0

Please sign in to comment.