Category Archives: Snippet

Upload Flash Files in Media Library

I learned something new today and I thought I would share. I discovered that it was no longer possible to upload Shockwave Flash files in the WordPress Media Library. Not that I have to upload flash files very often but I had a client that wanted to add a flash game in their website and could not for the life of them get it uploaded.

This change was apparently added in WordPress 3.6.1.

Additional security hardening:

Updated security restrictions around file uploads to mitigate the potential for cross-site scripting. The extensions .swf and .exe are no longer allowed by default, and .htm and .html are only allowed if the user has the ability to use unfiltered HTML

While I can understand the reasoning behind it, I still had to find a way to allow my client to upload their swf file. Well a little searching and a little tweaking here and there and I came up with the following snippet of code. I added it to their theme functions file and presto they could upload their swf file and everyone was happy again.

// Add SWF mime type to upload to media manager
function lgr_mime_types($mime_types){
	if (current_user_can('install_plugins')) {
		$mime_types['swf'] = 'application/x-shockwave-flash'; 
    return $mime_types;
add_filter('upload_mimes', 'lgr_mime_types', 1, 1);

I could have done the code without the current_user_can check, but the clients site in question has multiple users and I only wanted people that had Administrator rights to be able to add swf files in case you were wondering what that check was for.

Seems to be working so far. Will want to move it into a site specific plugin in the future but for the next couple of days this will do nicely.

Control Automatic Updates in WordPress

One of the new features in the WordPress 3.7 is the ability for WordPress to be able to update itself. This has also been one of the more controversial features, but personally the new ability to had WordPress automatically update when a new security update is available is a fantastic idea. If you are not… Continue Reading

Automatically Set Featured Images

I have a love/hate relationship with featured images on WordPress. I love them but I often forget to set them. Usually I am just forgetful and end up publishing posts before I have the feature image set. That is ok for me who knows what I have done and can go back and set the… Continue Reading