Skip to content

Commit

Permalink
php notices under reproducible condition - fixes #33
Browse files Browse the repository at this point in the history
  • Loading branch information
sanzeeb3 committed May 28, 2021
1 parent 067d143 commit aef89df
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,19 +169,20 @@ public function real_file_type( $file_data, $file, $filename ) {
$extension = pathinfo( $filename, PATHINFO_EXTENSION );
$enabled_types = $this->enabled_types();

// We don't need to do anything if there's no multiple mimes for this extension.
if ( isset( $enabled_types[ $extension ] ) && ! is_array( $enabled_types[ $extension ] ) ) {
// We don't need to do anything if the file uploads normally.
if ( empty( $file_data['ext'] ) && empty( $file_data['type'] ) ) {

return $file_data;

} elseif ( empty( $file_data['ext'] ) && empty( $file_data['type'] ) ) {
// We don't need to do anything if there's no multiple mimes for this extension.
if ( empty( $enabled_types[ $extension ] ) || ! is_array( $enabled_types[ $extension ] ) ) {
return $file_data;
}

$mimes = $enabled_types[ $extension ];
$mimes = $enabled_types[ $extension ];

// First mime will not need this extra behaviour.
unset( $mimes[0] );
// First mime will not need this extra behaviour.
unset( $mimes[0] );

$mimes = array_map( 'sanitize_mime_type', $mimes );
$mimes = array_map( 'sanitize_mime_type', $mimes );

foreach ( $mimes as $mime ) {

Expand All @@ -195,17 +196,17 @@ public function real_file_type( $file_data, $file, $filename ) {
return $mime_types;
};

// Add alias mime to the allowed mime types.
add_filter( 'upload_mimes', $mime_filter );
// Add alias mime to the allowed mime types.
add_filter( 'upload_mimes', $mime_filter );

// Validate the new mime/extension pair.
$file_data = wp_check_filetype_and_ext( $file, $filename, array( $extension => $mime ) );
// Validate the new mime/extension pair.
$file_data = wp_check_filetype_and_ext( $file, $filename, array( $extension => $mime ) );

// Remove filter to add another mime type.
remove_filter( 'upload_mimes', $mime_filter );
// Remove filter to add another mime type.
remove_filter( 'upload_mimes', $mime_filter );

// Continue the process.
add_filter( 'wp_check_filetype_and_ext', array( $this, 'real_file_type' ), 999, 3 );
// Continue the process.
add_filter( 'wp_check_filetype_and_ext', array( $this, 'real_file_type' ), 999, 3 );

if ( ! empty( $file_data['ext'] ) || ! empty( $file_data['type'] ) ) {
return $file_data;
Expand Down

0 comments on commit aef89df

Please sign in to comment.