Skip to content
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

Restricting file upload types #35

Open
sanzeeb3 opened this issue Sep 8, 2021 · 6 comments · May be fixed by #49
Open

Restricting file upload types #35

sanzeeb3 opened this issue Sep 8, 2021 · 6 comments · May be fixed by #49
Assignees
Labels

Comments

@sanzeeb3
Copy link
Contributor

sanzeeb3 commented Sep 8, 2021

A feature to restrict file upload types. Currently, the plugin can only allow additional file upload types.

Slack: https://awesomemotive.slack.com/archives/C2G5XRC9W/p1631056720207600

References:
https://www.wpbeginner.com/plugins/how-to-restrict-uploads-to-specified-file-types-only-in-wordpress/
https://wordpress.org/plugins/restrict-uploads/

@kkarpieszuk kkarpieszuk self-assigned this Mar 23, 2022
@kkarpieszuk
Copy link
Contributor

This is a nice task and like @sanzeeb3 said on slack it is quite complex (but that's why I like it, thanks @cheh for pointing me to this plugin repo). I will try to handle it.

I actually already started but as this is complex I don't want to do everything without consultation with the rest of you. (Also @slaFFik mentioned on slack we should, discuss it upon developing.

So here is my plan as the list of the checkboxes (I will mark what I already done or started):

  • When user updates plugin to the version with this feature, add all native file types to wp_option file_upload_types

We're already storing in file_upload_types indexes for 'enabled' and 'custom'. I am going to add next index 'native' and store there all types coming from unfiltered get_allowed_mime_types function.

(I was also considering storing there only those native types which user will disable later, but I found it will be easier to incorporate currently available logic to handle it the way I described in previous paragraph)

  • In the HTML table in the ENABLED section display native file types which are enabled (originally they will be enabled with the logic above).

It already displayed 'enabled' and 'custom' so this will be in par of what I described in previous point.

  • If the user disable one of native formats, remove it from wp_options file_upload_types the 'native' section.

Same as we are removing other enabled file types.

  • Then in HTML table it should be moved to the section AVAILABLE

And unchecked like the rest of available.

  • Update our filters for available file types (used for example when file is being uploaded) to check also for 'native' file types if they are still available.

That's it. No more special logic.

I am thinking also about small polishing:

  • maybe in the HTML table native file types should have some label/tag next to the description (or extension) informing user it is native file type coming from WordPress
  • Text above HTML table "Below is the list of files types that can be enabled, not including the files WordPress allows by default." have to be updated of course.

I will be extending this comment as I find any culprits or additional things to change.

@kkarpieszuk
Copy link
Contributor

@slaFFik @cheh I assigned this ticket to you to notify you I would like to see your comments about my plan above. If you want to involve anyone else, feel free.

@kkarpieszuk
Copy link
Contributor

kkarpieszuk commented Mar 23, 2022

I am not creating yet a merge request but here is the branch where I will be pushing commits.

https://github.com/awesomemotive/file-upload-types/tree/fut/35-restricting-file-upload-types

@kkarpieszuk
Copy link
Contributor

ok, status for now (currently in the branch above), I write ti down as a note to myself before short holidays:

  • works :)
  • displays additional section "Native" with native but disabled file types (enabled are in the section "Enabled")
  • when activated, it populates list of native file types in the wp_options and automatically make them enabled
  • the text over the table is updated (removed info the table does not contain native types, as it does contain now)

what still must be done:

  • the description next to native types is always "WordPress natively registered type". I will probably replace it by correct type descriptions
  • clean code, I left a few @todo comments and will clean them before the release
  • test it at front end (no logic applied yet, so probably does not work at all, but will be easy to fix)

@kkarpieszuk
Copy link
Contributor

status update: now it left only to additionally add types to ennabled array during the migration and the fix will be ready

@kkarpieszuk kkarpieszuk linked a pull request Jun 23, 2022 that will close this issue
@kkarpieszuk
Copy link
Contributor

PR is ready #49

@cheh cheh added the feature label Feb 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants