Use WordPress 3.5 new Media Uploader for your plugin and theme options panel development

wordpress-new-media-uploader

As you all may have noticed, since WordPress 3.5 the CMS got a lot of enhancements especially regarding the user interface which surely looks sexier and one of the most noticeable changes is the new Media Uploader.

Whether you are developing a plugin or creating options panel for your theme, you want to use the new Media Uploader because you want to offer your users a seamless user experience through all sections of WordPress admin panel, on the other side, it’s easier than the old thick box media uploader to implement and work with.

First of all, let’s prepare the view, you may have something similar to the following:

Your form may look like this:

wordpress-new-media-uploader-html

Create a javascript file “custom-script.js” and copy and paste the following code to it:

The hard work is now done, in order for this to work, we need to enqueue the following scripts

That will be it! This is a very basic example, if you need more flexibility over the Media Uploader you may need to read more about the options you pass to wp.media. Please don’t hesitate to comment if you have a better way to do it.