Skip to content

Commit

Permalink
Update technique for secondary mime-check for .tex files.
Browse files Browse the repository at this point in the history
The logic in WP's wp_check_filetype_and_ext() recently changed
such that the "real" mime type identified by finfo_file() must
match the mime type identified by the extension in order to return
a passing value. This was not compatible with the workaround technique
introduced in 60f6393.

See #2476, #3425.
  • Loading branch information
boonebgorges committed Sep 5, 2024
1 parent 5aedc68 commit b0893a5
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions wp-content/plugins/wds-citytech/wds-citytech.php
Original file line number Diff line number Diff line change
Expand Up @@ -2893,27 +2893,31 @@ function( $types ) {
/**
* Strict mime-type fixes.
*/
function openlab_secondary_mime( $check, $filetype, $filename, $mimes ) {
function openlab_secondary_mime( $check, $filetype, $filename, $mimes, $real_mime ) {
if ( empty( $check['ext'] ) && empty( $check['type'] ) ) {
$secondary_mimes = [
[ 'tex' => 'text/x-tex' ],
];

$file_ext = pathinfo( $filename, PATHINFO_EXTENSION );

foreach ( $secondary_mimes as $secondary_mime ) {
// Run another check, but only for our secondary mime and not on core mime types.
remove_filter( 'wp_check_filetype_and_ext', 'openlab_secondary_mime', 99 );
$check = wp_check_filetype_and_ext( $filetype, $filename, $secondary_mime );
add_filter( 'wp_check_filetype_and_ext', 'openlab_secondary_mime', 99, 4 );
if ( ! isset( $secondary_mime[ $file_ext ] ) ) {
continue;
}

if ( ! empty( $check['ext'] ) || ! empty( $check['type'] ) ) {
return $check;
if ( $real_mime !== $secondary_mime[ $file_ext ] ) {
continue;
}

$check['ext'] = $file_ext;
$check['type'] = $secondary_mime[ $file_ext ];
}
}

return $check;
}
add_filter( 'wp_check_filetype_and_ext', 'openlab_secondary_mime', 99, 4 );
add_filter( 'wp_check_filetype_and_ext', 'openlab_secondary_mime', 99, 5 );

/** TablePress mods **********************************************************/

Expand Down

0 comments on commit b0893a5

Please sign in to comment.