• Hi,

    I’m trying to add a media filter link to the top of the Media page, like the existing ones for Images, Videos, Audio, etc. Here’s the code I’m using:

    function kml_modify_post_mime_types( $post_mime_types ) {
    		$post_mime_types['application/vnd.google-earth.kml+xml'] = array(__('KML'), __('Manage KML'), _n_noop('KML <span class="count">(%s)</span>', 'KML <span class="count">(%s)</span>'));
    		return $post_mime_types;
    }

    Called by:

    add_filter( 'post_mime_types', array( &$ELLGmapKML, 'kml_modify_post_mime_types' ) );

    I also had to use the following to allow file of this type to be uploaded:

    function kml_modify_upload_mime_types( $upload_mime_types ) {
    		$mimes = array_merge( $upload_mime_types, array(
    			'kml' => 'application/vnd.google-earth.kml+xml',
    			'kmz' => 'application/vnd.google-earth.kmz+xml'
    		));
    		return $mimes;
    }
    add_filter( 'upload_mimes', array( &$ELLGmapKML, 'kml_modify_upload_mime_types' ) );

    (the functions are inside a class, hence the ‘&$ELLGmapKML’).

    It’s just not working. I’m able to upload files of this MIME-type, but no filter link appears.

    Also, another part of the plugin I’m developing is supposed to return a list of media of this same MIME-type, and this also fails to work, so somewhere along the way, WordPress is failing to recognise the MIME-type of this kind of file. If I click on the KML file in the Media list, though, the Edit page for the media does in fact show the correct MIME information (application/vnd.google-earth.kml+xml) in the ‘File Type’ field of the edit form.

    Also, I’ve been able to add custom fields to the edit form for this type of media, based again, on the MIME-type string from the meta-information for the file, so it seems that for the purposes of the filter links at the top of the Media list, and for querying the database for posts by MIME, the MIME type is not recognised, whereas in other contexts, it is.

    Very frustrating. Can anyone throw any light on this issue? Could it possibly have anything to do with the ‘+’ character in ‘application/vnd.google-earth.kml+xml’? Probably a stupid question, but I’m a bit stuck here. I can think of a workaround for the issue of querying posts- ie search for posts with a specific custom meta-field, which I can add only to posts with that MIME-type, but can’t think of a workaround for the issue of the Media list filter links. I’d rather this just worked as intended, anyway.

    Thanks in advance for your help, guys,

    Cheers,

    a|x

    [ Please do not bump, it’s not permitted here. ]

Viewing 1 replies (of 1 total)
  • Thread Starter toneburst

    (@toneburst)

    Sorry for the bump last time. I’ve done a bit more poking around, and I can now say pretty-much for sure that the problem IS with the ‘+’ character in the KML MIME-type string. If I add a fake MIME-type to the post_mime_types array, that looks like this:

    $post_mime_types['application/vnd.google-earth.kml'] = array(__('KML'), __('Manage KML'), _n_noop('KML <span class="count">(%s)</span>', 'KML <span class="count">(%s)</span>'));

    and hack the post_mime_type value for a KML file I’ve already uploaded so that it’s the same (ie ‘application/vnd.google-earth.kml’), I now get a filter tab named ‘KML’ at the top of the Media list, and my KML file is listed.

    Also, I’m able to find posts based on this MIME-type string using

    $args = array(
    	'orderby' => 'post_date',
    	'order'	=> 'ASC',
    	'post_type' => 'attachment',
    	'post_mime_type' => 'application/vnd.google-earth.kml'
    );
    $kmlmedia_posts = get_posts( $args );
    if($kmlmedia_posts) {
    	$kmlmedia_posts_array = array();
    	foreach( $kmlmedia_posts as $post ) {
    		$postdat = array(
    			'title'	=> $post->post_title,
    			'id'	=> $post->ID
    		);
    		$kmlmedia_posts_array[] = $postdat;
    	}
    	echo json_encode( $kmlmedia_posts_array );
    }

    Of course, this doesn’t solve my problem, just goes some way to tying down the cause.

    I’ve also done some content searches on the WordPress system files, and I think I’ve managed to narrow-down the cause of the problem to one or both of the functions

    wp_match_mime_types() [line 1877]
    wp_post_mime_type_where() [line 1910]

    in post.php. Unfortunately, I’m not a hardcore enough coder to be able to unpick how these two functions work. There don’t seem to be any filter hooks around here that I can use to override them/it, even if I knew how to fix the problem.

    Should I report this as a bug?

    a|x

Viewing 1 replies (of 1 total)
  • The topic ‘Post Mime Types for KML File’ is closed to new replies.