How to extend Media Library (WP 4.4)

It’s not a tab but you might be able to get started with an upload button. Check out pre-upload-ui and some actions that follow. Namely pre-plupload-upload-ui and post-upload-ui.

This will add a couple buttons to the ‘Upload Files‘ tab and to ‘Media > Add New‘.

BUTTONS

add_action( 'pre-plupload-upload-ui', 'wpse_20160202_pre_plupload_upload_ui' );
add_action( 'post-upload-ui', 'wpse_20160202_post_upload_ui' );

function wpse_20160202_pre_plupload_upload_ui()
{
    # see https://core.trac.wordpress.org/browser/tags/4.4.1/src/wp-admin/includes/media.php#L1902

    print '<button onclick="javascript:alert(\'Upload From Dropbox\');" id="db-upload-btn" class="button media-button button-primary button-large" style="margin-bottom:10px;">Upload From Dropbox</button>';
}


function wpse_20160202_post_upload_ui()
{
    # see wp-includes/media-template.php

    print '<button onclick="javascript:alert(\'Another Upload From Dropbox\');" id="db-upload-btn" class="button media-button button-primary button-large" style="margin-bottom:10px;">Another Upload From Dropbox</button>';
}

TABS

Adding this here just to show the alternate. media_upload_tabs will help you control which tabs are included in the side and media_upload_{tab} to render the contents using wp_iframe().

add_filter( 'media_upload_tabs', 'media_upload_tabs__tab_slug' );

function media_upload_tabs__tab_slug( $tabs ) {
    $newtab = array ( 'tab_slug' => 'Your Tab Name' );
    return array_merge( $tabs, $newtab );
}

add_action( 'media_upload_tab_slug', 'media_upload_tab_slug__content' );

function media_upload_tab_slug__content() {
    wp_iframe( 'media_upload_tab_slug_content__iframe' );
}

function media_upload_tab_slug_content__iframe() {
    ?>
    <div>tab_slug: Add your content here.</div><?php
}

Leave a Comment