WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 5 months ago

#34064 new enhancement

Filter the file type error message

Reported by: kraftbj Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Filesystem API Keywords:
Focuses: Cc:
PR Number:

Description

When uploading a file type that is not permitted, the error Sorry, this file type is not permitted for security reasons. is returned.

By adding a filter, a plugin/site admin can add a customized message.

An example use case: A plugin that allows a front-end post submission system that allow file add-ons. By filtering the response, the author/admin can give more detailed specifications including allowable file types, if desired.

Example function of the filter in psudocode:

add_filter( 'upload_filetype_error', 'bk_test_error' );
function bk_test_error() {
	$allowed = get_allowed_mime_types();
	$message = "This type of file is not allowed! Please use one of the following: " . implode( ', ', array_keys( $allowed ) );
	return $message;
}

Attachments (1)

34064.diff (955 bytes) - added by kraftbj 4 years ago.
first pass at filter.

Download all attachments as: .zip

Change History (1)

@kraftbj
4 years ago

first pass at filter.

Note: See TracTickets for help on using tickets.