Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Fix handling of uploading of font files #6407
base: trunk
Are you sure you want to change the base?
Fix handling of uploading of font files #6407
Changes from 5 commits
30225fc
78fc27b
1617d81
48339ed
b583c93
50e91f4
abc2610
c4b4eb5
5c4039b
fe6d3b9
41ec0e8
86612b6
8d9e9d8
d391259
4bad2e3
076854a
d8c1cba
f5b0d01
0a21712
95bb189
4908744
22b071c
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
This function attempts to create the directory but it doesn't appear that
_wp_handle_upload()
does (correct me if I am wrong).Given these changes allow developers to define the uploads dir, I think it should either:
If the second approach is taken then the override docs will need to include a note that the directory needs to be created before attempting an upload.
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.
Good catch! Yes, you're right, there is some repetition in
wp_upload_bits()
as the directory should be checked or created when callingwp_upload_dir()
, and is later checked again and eventually created withwp_mkdir_p()
. Thinking perhaps the use ofwp_mkdir_p()
here is mostly to catch edge cases when theupload_dir
filter was used.On the other hand
_wp_handle_upload()
relies only on the call towp_upload_dir()
to create the directory or ensure that it exists. That seems to be working well enough, been like that "forever" :)Frankly I'm a bit unsure which fix would be better here.
$upload_dir
param must exist. This would give the developers a bit more freedom in how to check, and how to create it if needed.wp_mkdir_p()
to confirm or create the directory, same as inwp_upload_bits()
. Think there was a slight difference with howis_dir()
works with wrappers (perhaps that was only in older PHP versions) so using it to confirm might not be advisable as it might return a different result.Which do you think is better?
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.
Same to be 100% honest, I could go either way too. If the upload handlers attempt to create the directory then it seems redundant that
wp_upload|font_dir()
does too, but this change would complicate that.Let's sleep on it and hopefully our unconscious can decide for us overnight.
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.
Great idea! Unfortunately my subconscious did not take that opportunity :)
Joking aside, I tend to very slightly prefer letting plugins handle creation and confirmation of the uploads directory. That would give them a little more freedom in how to do it and whether and how to cache it. Of course they can just use
wp_mkdir_p()
. Thinking that checking the type and withis_dir()
, and adding a longer description there would be sufficient.Also tried to figure out if there are any differences between PHPs
mkdir()
andis_dir()
when using wrappers. Think there may have been in the past but seems now there isn't (or at least I wasn't able to find anything).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.
This is the back-compat break I am concerned about. If this approach was desired an enhancement should have been opened in June, 2023 WordPress/gutenberg#52704 (comment)
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.
Thinking we have to "agree to disagree" here :)
Don't think this is a back-compat problem but rather a fix to a bug that allows plugins to "behave badly" and disable part of the WP plugins API. Another good reason to fix this is the fact that there are no known plugins that do this "bad behavior".