-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update how custom svg dimesions are applied #216
base: develop
Are you sure you want to change the base?
Conversation
Update how custom svg dimesions are applied for `get_image_tag` and `wp_get_attachment_image` functions Separate the logic for defining custom dimensions in a `set_svg_dimension` function
@gabriel-glo thanks for the PR! Could you please fill out the PR template with description, changelog, and credits information so that we can properly review and merge this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for the PR @gabriel-glo. Code looks good and it tests well. (Added one minor doc update suggestion)
@dkotter The PR looks good to me. However, since we had 2-3 size/dimension-related PRs on this plugin earlier and you have better context on those, I wanted to have a quick review from your side to ensure these changes align with those PRs.
Thank you.
safe-svg.php
Outdated
if ( is_array( $size ) ) { | ||
$width = $size[0]; | ||
$height = $size[1]; | ||
} elseif ( 'full' === $size && $dimensions ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the output of svg_dimensions
can be filtered, I think we'll need to be more defensive in a few places here to ensure 1 - $dimensions
is an array and 2 - it contains the height
and width
keys
safe-svg.php
Outdated
* | ||
* @return int|false Width or height of the SVG image, or false if not found. | ||
*/ | ||
protected function set_svg_dimensions( $id, $size ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to add unit tests to cover this new method
safe-svg.php
Outdated
@@ -728,6 +717,37 @@ protected function str_ends_with( $haystack, $needle ) { | |||
return 0 === substr_compare( $haystack, $needle, -$len, $len ); | |||
} | |||
|
|||
/** | |||
* Set custom width or height of the SVG image. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this method doesn't actually set anything, it returns these values, we should probably update this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And thinking about it more, might be worth renaming this method to be get_svg_dimensions
instead, or something similar
Co-authored-by: Darin Kotter <[email protected]>
Description of the Change
get_image_tag
andwp_get_attachment_image
functionsset_svg_dimension
functionCloses #6
How to test the Change
In any template output the image markup either by using
get_image_tag
orwp_get_attachment_image
functions.Set the custom image size to either one of the registered image size names or a custom one via array
[$width, $height]
.Output should match the set dimensions.
Changelog Entry
Credits
Props @
Checklist: