Media

If you have ever lagged to use the WordPress Media Uploader and have not quite got to use it efficiently, well here is something you would love to use over and over. Boots Media makes it so easy to use the wordpress media uploader and as an extra bite, it gives you an auto resize image utility for you to consume. So let’s dig into the details.

Overview

Dependencies

This extension requires the Enqueue extension.

You DO NOT NEED to require the enqueue extension in your composer.json. It will automatically be loaded when you require this media extension.

Delegate

This extension acts as a delegate (as in “used by”) for the form extension. Moreover, it may be a delegate for many others.

How to install

Make sure you have read the extension installation guide first.

To install this extension, place the following inside the “require” block of the composer.json file.

Now run composer install  in your terminal. Thats it!

Usage - Media Uploader

Step 1/2 - Hooking up the scripts

At first, we will need to enqueue the media script as well as our js script to work with the media uploader. We will also display an html button element (in an ugly way for this demonstration).

So that was very simple, wasn’t it? We just enqueued the media script (by the extension) on line 40 and our media.js script on line 43.

Notice the data-title  and data-button  attributes for the button element. These will be the title and the button text for the media uploader respectively.

Do not output html like demonstrated here for the button.

Step 2/2 - Our javascript

This will be our javascript (create a js file and name it ‘media.js’):

Go ahead! Open up the admin dashboard, click the button on the top and see how it goes.

Usage - Image Resizing

To demonstrate the use of the image resizing utility, lets just use the $this->Boots  (Boots) object.

The following code will simply resize the image having an id of 344 into a 64/64 pixel image.

Khan

A die hard programmer!