Open brian-mit opened 5 years ago
Thanks for letting us know about this issue. It appears the "problem" is around from Wordpress 5.0.1 onwards, and was propagated to 4.9.9 also. according to the Wordpress tracker. I found a github gist wirth a workaround here and adapted it for the bibtex case and added at the papercite-wp-plugin.php (I'm using version 0.5.20, which was pushed by me, @digfish). The code is below
/**
* by digfish (09 Apr 2019)
* Restore .bib upload functionality in Media Library for WordPress 4.9.9 and up
* adapted from https://gist.github.com/rmpel/e1e2452ca06ab621fe061e0fde7ae150
*/
add_filter('wp_check_filetype_and_ext', function($values, $file, $filename, $mimes) {
if ( extension_loaded( 'fileinfo' ) ) {
// with the php-extension, a bib file is issues type text/plain so we fix that back to
// application/x-bibtex by trusting the file extension.
$finfo = finfo_open( FILEINFO_MIME_TYPE );
$real_mime = finfo_file( $finfo, $file );
finfo_close( $finfo );
if ( $real_mime === 'text/plain' && preg_match( '/\.(bib)$/i', $filename ) ) {
$values['ext'] = 'bib';
$values['type'] = 'application/x-bibtex';
}
} else {
// without the php- extension, we probably don't have the issue at all, but just to be sure...
if ( preg_match( '/\.(bib)$/i', $filename ) ) {
$values['ext'] = 'bib';
$values['type'] = 'application/x-bibtex';
}
}
return $values;
}, PHP_INT_MAX, 4);
You can add it to your theme's functions.php
until a new commit with the fix is pushed.
Other threads that I stumbled upon regarding this issue in case anyone comes to this topic by Google results:
Pushed the last commit with the fix (v. 0.5.22)
Thanks, that seems to work for me. One note in case anyone else finds this: I needed to re-upload my bibtex files. After adding the above code to functions.php, the bibtex files that were currently in my media library still did not seem to be found. After re-uploading them though, they were.
I'm using the Media Library to store my bibtex files and after upgrading Wordpress core from 4.9.9 to 5.1.1 and the papercite plugin from 0.5.15 to 0.5.18, I'm having the following issues:
I'm not sure, but it looks like line 2558 in wp-includes/functions.php might be where the mime type of a file is found:
I check my bibtex file using the following command:
and got the response 'text/plain'.
If I create the directory wp-content/papercite-data/bib and put my bibtex files in there, things seem to work, so I can do that as a workaround. Being able to use the Media Library is more convenient though.