-
Notifications
You must be signed in to change notification settings - Fork 825
Media Uploader: Restrict unsupported files from being uploaded #44798
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
base: trunk
Are you sure you want to change the base?
Media Uploader: Restrict unsupported files from being uploaded #44798
Conversation
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Wpcomsh plugin:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Code Coverage SummaryCoverage changed in 1 file.
Coverage check overridden by
Covered by non-unit tests
|
e219dfc
to
7069ce1
Compare
f1a67b2
to
16eb110
Compare
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.
Pull Request Overview
This PR restricts file selection in the WordPress media uploader to prevent users from selecting unsupported media types (video/audio) based on their site's features, providing immediate feedback without requiring upload attempts.
- Adds client-side file type filtering using Plupload to restrict selectable files based on site features
- Implements feature-based restrictions for audio files (UPLOAD_AUDIO_FILES) and video files (VIDEOPRESS)
- Registers the restrictions only when the media library is enqueued to avoid affecting other upload contexts
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
projects/plugins/wpcomsh/feature-plugins/hooks.php | Implements Plupload file filtering logic and registration |
projects/plugins/wpcomsh/changelog/update-restrict-files-upload-summer-special | Adds changelog entry for the feature |
Comments suppressed due to low confidence (1)
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
$options['filters'] = array(); | ||
} | ||
$options['filters']['mime_types'] = array( | ||
array( 'extensions' => implode( ',', $allowed_extensions ) ), |
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.
The hardcoded 'mime_types' key assumes a specific Plupload filter structure. Consider checking if this key already exists and merging with existing filters to avoid overwriting user-defined filters.
array( 'extensions' => implode( ',', $allowed_extensions ) ), | |
// Merge with existing mime_types filters if present | |
$merged_extensions = $allowed_extensions; | |
if ( isset( $options['filters']['mime_types'] ) && is_array( $options['filters']['mime_types'] ) ) { | |
foreach ( $options['filters']['mime_types'] as $filter ) { | |
if ( isset( $filter['extensions'] ) ) { | |
$existing_exts = explode( ',', $filter['extensions'] ); | |
$merged_extensions = array_merge( $merged_extensions, $existing_exts ); | |
} | |
} | |
$merged_extensions = array_values( array_unique( $merged_extensions ) ); | |
} | |
$options['filters']['mime_types'] = array( | |
array( 'extensions' => implode( ',', $merged_extensions ) ), |
Copilot uses AI. Check for mistakes.
Fixes DOTOBRD-293
Proposed changes:
Other information:
Jetpack product discussion
Does this pull request change what data or activity we track or use?
Testing instructions:
/wp-admin/media-new.php