• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WordPress core a2z

WordPress core a2z

WordPress core only

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / wp_enqueue_media() – Enqueues all scripts, styles, settings, and templates necessary to use all media JS APIs.

You appear to be a bot. Output may be restricted

Description

Enqueues all scripts, styles, settings, and templates necessary to use all media JS APIs.

Usage

wp_enqueue_media( $args );

Parameters

$args
( array ) optional – { Arguments for enqueuing media scripts.
A
( int|WP_Post ) optional – post object or ID. }

Returns

void

Source

File name: wordpress/wp-includes/media.php


Lines:

1 to 100 of 391
function wp_enqueue_media( $args = array() ) {
  // Enqueue me just once per page, please.
  if ( did_action( 'wp_enqueue_media' ) ) {
    return;
  }

  global $content_width, $wpdb, $wp_locale;

  $defaults = array(
    'post' => null,
  );
  $args     = wp_parse_args( $args, $defaults );

  // We're going to pass the old thickbox media tabs to `media_upload_tabs`
  // to ensure plugins will work. We will then unset those tabs.
  $tabs = array(
    // handler action suffix => tab label
    'type'     => '',
    'type_url' => '',
    'gallery'  => '',
    'library'  => '',
  );

  
/** This filter is documented in wp-admin/includes/media.php */
  $tabs = apply_filters( 'media_upload_tabs', $tabs );
  unset( $tabs['type'], $tabs['type_url'], $tabs['gallery'], $tabs['library'] );

  $props = array(
    'link'  => get_option( 'image_default_link_type' ), // DB default is 'file'.
    'align' => get_option( 'image_default_align' ),     // Empty default.
    'size'  => get_option( 'image_default_size' ),      // Empty default.
  );

  $exts      = array_merge( wp_get_audio_extensions(), wp_get_video_extensions() );
  $mimes     = get_allowed_mime_types();
  $ext_mimes = array();
  foreach ( $exts as $ext ) {
    foreach ( $mimes as $ext_preg => $mime_match ) {
      if ( preg_match( '#' . $ext . '#i', $ext_preg ) ) {
        $ext_mimes[ $ext ] = $mime_match;
        break;
      }
    }
  }

  
/**
 * Allows showing or hiding the "Create Audio Playlist" button in the media library.
 *
 * By default, the "Create Audio Playlist" button will always be shown in
 * the media library.  If this filter returns `null`, a query will be run
 * to determine whether the media library contains any audio items.  This
 * was the default behavior prior to version 4.8.0, but this query is
 * expensive for large media libraries.
 *
 * @since 4.7.4
 * @since 4.8.0 The filter's default value is `true` rather than `null`.
 *
 * @link https://core.trac.wordpress.org/ticket/31071
 *
 * @param bool|null $show Whether to show the button, or `null` to decide based
 *                        on whether any audio files exist in the media library.
 */
  $show_audio_playlist = apply_filters( 'media_library_show_audio_playlist', true );
  if ( null === $show_audio_playlist ) {
    $show_audio_playlist = $wpdb->get_var(
      "
			SELECT ID
			FROM $wpdb->posts
			WHERE post_type = 'attachment'
			AND post_mime_type LIKE 'audio%'
			LIMIT 1
		"
    );
  }

  
/**
 * Allows showing or hiding the "Create Video Playlist" button in the media library.
 *
 * By default, the "Create Video Playlist" button will always be shown in
 * the media library.  If this filter returns `null`, a query will be run
 * to determine whether the media library contains any video items.  This
 * was the default behavior prior to version 4.8.0, but this query is
 * expensive for large media libraries.
 *
 * @since 4.7.4
 * @since 4.8.0 The filter's default value is `true` rather than `null`.
 *
 * @link https://core.trac.wordpress.org/ticket/31071
 *
 * @param bool|null $show Whether to show the button, or `null` to decide based
 *                        on whether any video files exist in the media library.
 */
  $show_video_playlist = apply_filters( 'media_library_show_video_playlist', true );
  if ( null === $show_video_playlist ) {
    $show_video_playlist = $wpdb->get_var(
      "
[1] [2] [3] [4] Next »

 View on GitHub View on Trac

Published: 25th November 2019 | Last updated: 9th December 2020

Primary Sidebar

Information

Function name: wp_enqueue_media
Plugin ref: WordPress
Version: 5.6
Sourcefile: wp-includes/media.php
File ref: wp-includes/media.php
Deprecated?: No
API Letters: E,M,W

Footer

WP-a2z
WordPress core a2z
WordPress core only
WordPress 5.6
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  core.wp-a2z.org
© Copyright WP-a2z 2014-2021. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites