QNimate

  • CoursesVideos
  • WP PremiumPlugins
  • DemosLab
  • Home
  • QIdea
  • QTrack
Home Carbon Ads Using WordPress Media Uploader on Frontend

Using WordPress Media Uploader on Frontend

This post is a part 6 of Using WordPress Media Uploader in Plugins and Themes post series.
⎗ Previous: Adding a Video using WordPress Media Uploader.

WordPress media uploader is made up of Underscores and Backbone therefore to open the media uploader on frontend we just need to embed these dependencies and the core media uploader script.

Here is the code to enqueue to all these scripts on frontend

function enqueue_media_uploader()
{
    //this function enqueues all scripts required for media uploader to work
    wp_enqueue_media();
}

add_action("wp_enqueue_scripts", "enqueue_media_uploader");

Now you can use the media uploader provided interfaces to open it and let user upload or select images, videos and audio files.

For example, if you want to let user upload videos on frontend using media uploader then enqueue the below script

var media_uploader = null;

function open_media_uploader_video()
{
    media_uploader = wp.media({
        frame:    "video",
        state:    "video-details",
    });

    media_uploader.on("update", function(){

        var extension = media_uploader.state().media.extension;
        var video_url = media_uploader.state().media.attachment.changed.url;
        var video_icon = media_uploader.state().media.attachment.changed.icon;
        var video_title = media_uploader.state().media.attachment.changed.title;
        var video_desc = media_uploader.state().media.attachment.changed.description;
    });

    media_uploader.open();
}

Call the open_media_uploader_video() JavaScript function when you want user to upload video using media uploader

Feb 28, 2015Narayan Prusty
Adding a Video using WordPress Media UploaderGMail Removes "class", "id" and Styles from HTML EMail
Comments: 3
  1. Jan
    5 years ago

    Thanks for tutorial, but i have some error:
    media_uploader is undefined
    Please help me :)

    ReplyCancel
  2. nechux
    5 years ago

    This only works for registred users.
    Do know how to do it for non-registered users?
    Regards.

    ReplyCancel
  3. Patrick
    6 years ago

    I’m using the Wordpress Image Uploader on Frontend so users can upload images.
    Is it possible to customize the style of the Uploader? I want to make it smaller and only want the users to see the “Add media” tab (media library is hided).

    ReplyCancel

Leave a Reply to Patrick Cancel reply

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax

Narayan Prusty

I am a software engineer specialising in Blockchain, DevOps and Go/JavaScript. This is my personal blog where I write about things that I learn and feel interesting to share.

8 years ago 4 Comments WordPress
Share this
0
GooglePlus
0
Facebook
0
Twitter
0
Linkedin
Related Articles
  • Adding a Video using WordPress Media Uploader
  • Adding Multiple Images using WordPress Media Uploader
  • Adding a Audio Playlist using WordPress Media Uploader
  • Adding a Single Image using WordPress Media Uploader
  • Adding Image Gallery using WordPress Media Uploader
Our Sponsor
My Books

2014 - 2015 © QNimate
All tutorials MIT license