media

Adding the Media Uploader in WordPress

…without including the Editor. In the Admin. That was a really long title, so I hope you don’t feel mislead! I was recently working on a project that required a Custom Post Type without the editor, but needed the Media Uploader.

Note: This is not a full-blown tutorial. The purpose of this post is to help those troubleshoot the fact that the media uploader is not working, given the conditions above. 

Here is how I define the media custom meta box (this is only part of a bigger array of arguments):

array(
    'title' => __( 'Upload File', 'jlc' ),
    'type' => array( 'custom-post-type' ),
    'id' => 'upload-file',
    'items' => array(
        array(
            'type' => 'media',
            'name' => '_upload_file',
            'label' => __( 'Upload File', 'jlc' ),
            'label_position' => 'before',
        ),
    ),
),

In the post type definition, here’s what the ‘supports’ argument looks like:

'supports' => array(
    'title',
    'page-attributes',
    )

Note that the editor is not listed. If it were, the media uploader scripts would be automatically added. Instead, you get an error that wp.media is undefined. Luckily, there’s an easy fix for this. Simply add this line in where you custom post type is defined:

add_action( 'admin_init', 'wp_enqueue_media' );

This says that when you are on the admin, add the required media scripts. That way, even if the editor isn’t loaded, the media uploader will be.

Some Thoughts on the Xbox One

I remember when the the original Xbox came out. I was 15 when it was announced and essentially did a proposal for my parents on why they should buy it for me. Must have worked because I got it for Christmas (I was 16 by then). When the Xbox 360 came out, I waited until the very last minute before deciding I should buy it, which means there were no preorders left. I waited in line, at Best Buy, from 7:30pm-9am. Thank God my friends showed up a little after me, so I had someone to wait with, talk to, and take shifts while we each took turns warming up in the car. I’m very fond of the console and the brand, so when the Xbox One was announced, I was pretty excited about it. Here are some of my thoughts.

Favorites of 2012

I’m going to be honest here. 2012 was a pretty great year for me. A lot of amazing things happened in both my personal and professional life; most publicly, I got my first book published, and I hope do the same in 2013. While I don’t have too many traditions on this blog (something I hope to change in 2013), my Favorites of the year post has been a pretty good staple.