wp-plugin-creativecommons
wp-plugin-creativecommons copied to clipboard
Refactor: Update getimagesize() Function to Accept Image Paths Instead of URLs
Fixes
Fixes #187 by @brylie
Description
The function getimagesize()
takes image as parameter and returns the image size i.e height and width. In this PR, we replace image url with image path to fix this issue.
Technical details
This issue doesn't occur everytime, however in some cases when a website:
- Has basic auth
- Timesout while loading the image
the image may not be accessible through the image url, hence calling the getimagesize()
with image url may not work always. Also everytime getimagesize()
function is called, the server sends a request to load the image increasing execution time. Hence I've chosen to pass image path instead of image url in getimagesize()
. This solution handles the above 2 cases as well as addresses the performace issue of the code.
Tests
As described above, this situation doesn't always occur, so it may be difficult to test.
Checklist
- [x] My pull request has a descriptive title (not a vague title like
Update index.md
). - [x] My pull request targets the default branch of the repository (
main
ormaster
). - [x] My commit messages follow best practices.
- [x] My code follows the established code style of the repository.
- [x] I added or updated tests for the changes I made (if applicable).
- [x] I added or updated documentation (if applicable).
- [x] I tried running the project locally and verified that there are no visible errors.
Developer Certificate of Origin
For the purposes of this DCO, "license" is equivalent to "license or public domain dedication," and "open source license" is equivalent to "open content license or public domain dedication."
Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1
Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129
Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.
Developer's Certificate of Origin 1.1
By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or
(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or
(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.
(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.
@ArchanRD Thank you for this contribution!
Maybe I'm missing something, but why not make the change further up the chain of functionality like here, so that the image_url
when passed to the function later behaves normally rather than relying on the function to further modify/cleanup the url?
- https://github.com/creativecommons/wp-plugin-creativecommons/blob/2871fd257a642d75dcc23054949f71787954d4ac/includes/class-creativecommons.php#L1061C4-L1061C50
Hey @possumbilities, I tried to do that but I found that the image_url is comming from license
in wp_options. If I change the update_site_option
call here to add a new key image_path
, then anyone updating to this plugin will break it's functionality, since they won't have image_path
key in the DB. We will likely require a small migration change for that solution to work. Since that would become more complicated solution I thought we should go with this simpler approach.
I have simplified the implementation a bit, so it's essentially a one liner change ( but GH is showing it a bit differently though ).
Hey @possumbilities! Sorry I took a lot time to get back to this. I have properly escaped the global variables using esc_attr()
. Please have a loot at it.
@ArchanRD Wonderful, thank you! I'll move to testing this one more time and if all is well we'll move it to Approved!