The media_upload_library() WordPress PHP function retrieves the legacy media library form in an iframe.
Usage
To use the media_upload_library() function, simply call it like this:
media_upload_library();
Parameters
This function does not have any parameters.
More information
See WordPress Developer Resources: media_upload_library
Examples
Display the media library form in an iframe
This example demonstrates how to use the media_upload_library() function to display the legacy media library form in an iframe.
function display_media_library() {
media_upload_library();
}
add_action('admin_menu', 'display_media_library');
Add a custom admin page with the media library form
This example creates a custom admin page and displays the legacy media library form in an iframe on that page.
function custom_admin_menu() {
add_menu_page('Media Library', 'Media Library', 'manage_options', 'custom-media-library', 'media_library_page');
}
function media_library_page() {
echo '<iframe src="media-upload.php?type=image&TB_iframe=1"></iframe>';
}
add_action('admin_menu', 'custom_admin_menu');
Display the media library form in a custom metabox
This example shows how to display the legacy media library form in an iframe within a custom metabox on a post edit screen.
function custom_metabox() {
add_meta_box('media_library_metabox', 'Media Library', 'media_library_callback', 'post');
}
function media_library_callback() {
media_upload_library();
}
add_action('add_meta_boxes', 'custom_metabox');
Create a shortcode to display the media library form
This example demonstrates how to create a shortcode that displays the legacy media library form in an iframe.
function media_library_shortcode() {
ob_start();
media_upload_library();
return ob_get_clean();
}
add_shortcode('media_library', 'media_library_shortcode');
Usage: In your post or page editor, add the [media_library] shortcode where you want the media library form to appear.
Add the media library form to a custom widget
This example shows how to create a custom widget that displays the legacy media library form in an iframe.
class Media_Library_Widget extends WP_Widget {
public function __construct() {
parent::__construct('media_library_widget', 'Media Library', array('description' => 'Displays the legacy media library form.'));
}
public function widget($args, $instance) {
echo $args['before_widget'];
media_upload_library();
echo $args['after_widget'];
}
}
function register_media_library_widget() {
register_widget('Media_Library_Widget');
}
add_action('widgets_init', 'register_media_library_widget');