Author Archives: CodeMunkyX


Aug

11

Add Mime Types to WordPress

Posted by CodeMunkyX

If you have ever tried to upload media that WordPress does not allow by default, you have probably gotten the dreaded mime types error. Below, we will show you a quick way to get any mime type (such as CSV files) supported by the Media Library.

You will need to add the following 2 code snippets into your functions.php file for your active theme.

<?php
add_filter('upload_mimes', 'addUploadMimes');
?>

The above code will utilize the add_filter function to inject upload_mimes with a return array from the internal function addUploadMimes.

<?php
function addUploadMimes($mimes) {
    $mimes = array_merge($mimes, array(
                'csv' => 'text/csv'
             ));
    return $mimes;
}
?>

The above function accepts the existing mime types in the $mimes input and merges your new mime type and returns it to the upload_mimes filter. Save the code to your functions.php file in your theme folder and you should now be able to upload CSV files to your WordPress Media Library.

Bonus Tip

If you have any reason to place the above code in a PHP class file… you will want to use the following add_filter code instead so that WordPress will know how to call the function correctly.

<?php
add_filter('upload_mimes', array(&$this, 'addUploadMimes'));
?>

Aug

11

On Optimization in PHP

Posted by CodeMunkyX

Anthony Ferrara posted an in-depth article on his blog that weighs in on the different viewpoints of code maintainability versus performance. This is quite a good read… go check it out.

When it comes to optimization, there are two competing viewpoints in the PHP community. Some say that optimization should only ever be an after thought and to avoid premature optimization at all costs. Others will say that this is impractical, and you should make your application fast as you write it, since then you won’t have to go back and clean it up to make it faster. While I can understand the viewpoints of both sides, I am firmly in the former category. Given the number of discussions that I’ve had as of late on the topic, I’ve decided to write a post as to why I believe my viewpoint is better and more sustainable in the long run.

Aug

11

Smarty PHP Template Engine: Building PHP Apps

Posted by CodeMunkyX

Over at PHPBuilder they have posted a quick tutorial on how to get started with the Smarty PHP Template Engine and a sample ‘Hello World’ application.

Smarty is a template engine for PHP whose main goal is to facilitate a very useful way to separate the business logic from the presentation logic. This article introduces Smarty and demonstrates how to install the template, create an application from scratch and interact with a database.

Aug

11

Can’t live without Subversion (Webinar) – Aug 18

Posted by CodeMunkyX

If you are a software developer, chances are you deal with the question of which source code version control software to use. Subversion is widely used and has come to the forefront of anyone’s list.

Most teams that use Subversion quickly fall in love with it based on the simple fact that its easy to use, easy to administer, and easy to deploy.  And it sure costs a lot less than some of those other enterprise solutions we used to know and love.  This webinar takes a light-hearted view of why Subversion is so popular and why you too shouldn’t live without it!

featured wordpress themes