About this plugin
CodeCaste Media and Safe SVG File Upload Rules lets you decide which files can be uploaded to your site and how big they can be. You set the rules once, and they are applied everywhere files can come in.
What you can do
- Set one size limit for all files. For example, nothing larger than 5 MB.
- Give a file type its own limit. For example, 2 MB for PNG, 50 MB for MP4 and 10 MB for PDF.
- Block a file type completely. Any file with that extension is refused, whatever its size.
- Allow SVG files safely. WordPress blocks SVG by default because SVG files can hide harmful code. Turn SVG on and the plugin cleans every SVG before it is saved.
- Clear error messages. When a file is refused, the person uploading sees the reason, such as the file being too large or its type being blocked.
Where the rules apply
The same rules are used for:
- The Media Library and the “Add Media” button
- The WordPress REST API ( /wp/v2/media )
- Files added by importers and other code
- File manager plugins such as WP File Manager
- Other plugins that accept uploads in their own way, such as form builders and page builders
This means a file cannot slip past your limits just because it was uploaded through a different plugin. If you prefer not to check other plugins, you can turn that part off in the settings.
Why you might want this
- Stop very large files from filling up your hosting space.
- Stop team members or visitors from uploading file types you do not want.
- Use SVG logos and icons without opening your site to attacks.
- Keep all upload rules in one place instead of one setting per plugin.
Light and simple
No extra database tables and no background tasks. Settings are stored in the normal WordPress options.
Getting started
Set the default limit
Open Media upload restrictions, go to the General tab, choose a maximum file size and click Save settings. This limit applies to every file type that has no rule of its own.
Add a rule for one file type
- Open the Extension rules tab.
- Under Add extension rule, pick the file type (for example pdf ).
- Enter its maximum size, or switch on Block this extension to refuse it completely.
- Click Add rule.
You can edit, switch off or delete a rule at any time from the Configured rules list.
Allow SVG files
On the Extension rules tab, switch on Allow SVG uploads and choose a maximum SVG size. Every SVG is cleaned before it is saved. SVG stays off until you turn it on.
For developers
Other plugins and themes can use the same rules.
Functions
- gupc_evaluate_upload( array $file, string $route = 'custom_adapter' ) checks a file and returns a result object with the reason and message.
- gupc_is_upload_allowed( array $file, string $route = 'custom_adapter' ) returns true or false.
- gupc_get_effective_limit( string $extension ) returns the size limit in bytes for a file type (0 means blocked).
Always check that the function exists first, for example if ( function_exists( 'gupc_is_upload_allowed' ) ).
Hooks
- gupc_pre_evaluate_decision (filter): replace a decision before the rules run.
- gupc_upload_evaluated (action): runs after every decision, for logging.
- gupc_register_adapters (action): register your own upload adapter that implements GlobalUploadPolicyController\Adapters\Upload_Adapter_Interface.
- gupc_skip_request_guard (filter): skip the check for a request from another plugin.
- gupc_request_guard_skip_fields (filter): list upload field names the check should ignore.
- gupc_file_manager_ajax_actions (filter): add the AJAX action name of another file manager.