janboddez / share-on-mastodon

Easily share WordPress posts on Mastodon.
https://jan.boddez.net/wordpress/share-on-mastodon
GNU General Public License v3.0
39 stars 5 forks source link

Error message: Uncaught Error: Call to undefined function Share_On_Mastodon\mime_content_type() #117

Closed janboddez closed 2 weeks ago

janboddez commented 2 weeks ago

From WP.org.

I was under the impression that the Fileinfo extension and related functions would be enabled by default, but guessing this is a "too restrictive of a web host" thingy.

We can either:

janboddez commented 2 weeks ago

Thought I could steal something from IndieBlocks, but it uses this bit of code (to generate a file extension off a mime type):

if ( '' === pathinfo( $file_path, PATHINFO_EXTENSION ) && function_exists( 'mime_content_type' ) ) {
    // Some filesystem drivers--looking at you, S3 Uploads--take issue with
    // extensionless files.
    $mime = mime_content_type( $temp_file );

    if ( is_string( $mime ) ) {
        $mimes = new Mimey\MimeTypes(); // A MIME type to file extension map, essentially.
        $ext   = $mimes->getExtension( $mime );
    }
}

We're looking to do the opposite.

So I could do function_exists( 'mime_content_type' ) and then leave things as is, or else (1) use finfo_file() (if it exists!) or (2) look for a file extension and use "Mimey." (Even WordPress has a "MIME map" of its own, although it's hidden in a filter hook someplace, which can be extended to add support for certain images like SVG. So maybe we should just do apply_filters and then whatever it's called instead of relying on a third-party package!)

janboddez commented 2 weeks ago

Or else (if there's no file extension, or if it isn't recognized) we could fall back to application/octet-stream, which may or may not work.