media_buttons

The timeline below displays how wordpress function media_buttons has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.4

/**
 * Adds the media button to the editor.
 *
 * @since 2.5.0
 *
 * @global int $post_ID
 *
 * @param string $editor_id
 */
function media_buttons($editor_id = 'content')
{
    static $instance = 0;
    ++$instance;
    $post = get_post();
    if (!$post && !empty($GLOBALS['post_ID'])) {
        $post = $GLOBALS['post_ID'];
    }
    wp_enqueue_media(array('post' => $post));
    $img = '<span class="wp-media-buttons-icon"></span> ';
    $id_attribute = (1 === $instance) ? ' id="insert-media-button"' : '';
    printf('<button type="button"%s class="button insert-media add_media" data-editor="%s">%s</button>', $id_attribute, esc_attr($editor_id), $img . __('Add Media'));
    /**
     * Filters the legacy (pre-3.5.0) media buttons.
     *
     * Use {@see 'media_buttons'} action instead.
     *
     * @since 2.5.0
     * @deprecated 3.5.0 Use {@see 'media_buttons'} action instead.
     *
     * @param string $string Media buttons context. Default empty.
     */
    $legacy_filter = apply_filters_deprecated('media_buttons_context', array(''), '3.5.0', 'media_buttons');
    if ($legacy_filter) {
        // #WP22559. Close <a> if a plugin started by closing <a> to open their own <a> tag.
        if (0 === stripos(trim($legacy_filter), '</a>')) {
            $legacy_filter .= '</a>';
        }
        echo $legacy_filter;
    }
}

WordPress Version: 6.1

/**
 * Adds the media button to the editor.
 *
 * @since 2.5.0
 *
 * @global int $post_ID
 *
 * @param string $editor_id
 */
function media_buttons($editor_id = 'content')
{
    static $instance = 0;
    $instance++;
    $post = get_post();
    if (!$post && !empty($GLOBALS['post_ID'])) {
        $post = $GLOBALS['post_ID'];
    }
    wp_enqueue_media(array('post' => $post));
    $img = '<span class="wp-media-buttons-icon"></span> ';
    $id_attribute = (1 === $instance) ? ' id="insert-media-button"' : '';
    printf('<button type="button"%s class="button insert-media add_media" data-editor="%s">%s</button>', $id_attribute, esc_attr($editor_id), $img . __('Add Media'));
    /**
     * Filters the legacy (pre-3.5.0) media buttons.
     *
     * Use {@see 'media_buttons'} action instead.
     *
     * @since 2.5.0
     * @deprecated 3.5.0 Use {@see 'media_buttons'} action instead.
     *
     * @param string $string Media buttons context. Default empty.
     */
    $legacy_filter = apply_filters_deprecated('media_buttons_context', array(''), '3.5.0', 'media_buttons');
    if ($legacy_filter) {
        // #WP22559. Close <a> if a plugin started by closing <a> to open their own <a> tag.
        if (0 === stripos(trim($legacy_filter), '</a>')) {
            $legacy_filter .= '</a>';
        }
        echo $legacy_filter;
    }
}

WordPress Version: 5.5

/**
 * Adds the media button to the editor
 *
 * @since 2.5.0
 *
 * @global int $post_ID
 *
 * @param string $editor_id
 */
function media_buttons($editor_id = 'content')
{
    static $instance = 0;
    $instance++;
    $post = get_post();
    if (!$post && !empty($GLOBALS['post_ID'])) {
        $post = $GLOBALS['post_ID'];
    }
    wp_enqueue_media(array('post' => $post));
    $img = '<span class="wp-media-buttons-icon"></span> ';
    $id_attribute = (1 === $instance) ? ' id="insert-media-button"' : '';
    printf('<button type="button"%s class="button insert-media add_media" data-editor="%s">%s</button>', $id_attribute, esc_attr($editor_id), $img . __('Add Media'));
    /**
     * Filters the legacy (pre-3.5.0) media buttons.
     *
     * Use {@see 'media_buttons'} action instead.
     *
     * @since 2.5.0
     * @deprecated 3.5.0 Use {@see 'media_buttons'} action instead.
     *
     * @param string $string Media buttons context. Default empty.
     */
    $legacy_filter = apply_filters_deprecated('media_buttons_context', array(''), '3.5.0', 'media_buttons');
    if ($legacy_filter) {
        // #WP22559. Close <a> if a plugin started by closing <a> to open their own <a> tag.
        if (0 === stripos(trim($legacy_filter), '</a>')) {
            $legacy_filter .= '</a>';
        }
        echo $legacy_filter;
    }
}

WordPress Version: 5.4

/**
 * Adds the media button to the editor
 *
 * @since 2.5.0
 *
 * @global int $post_ID
 *
 * @staticvar int $instance
 *
 * @param string $editor_id
 */
function media_buttons($editor_id = 'content')
{
    static $instance = 0;
    $instance++;
    $post = get_post();
    if (!$post && !empty($GLOBALS['post_ID'])) {
        $post = $GLOBALS['post_ID'];
    }
    wp_enqueue_media(array('post' => $post));
    $img = '<span class="wp-media-buttons-icon"></span> ';
    $id_attribute = (1 === $instance) ? ' id="insert-media-button"' : '';
    printf('<button type="button"%s class="button insert-media add_media" data-editor="%s">%s</button>', $id_attribute, esc_attr($editor_id), $img . __('Add Media'));
    /**
     * Filters the legacy (pre-3.5.0) media buttons.
     *
     * Use {@see 'media_buttons'} action instead.
     *
     * @since 2.5.0
     * @deprecated 3.5.0 Use {@see 'media_buttons'} action instead.
     *
     * @param string $string Media buttons context. Default empty.
     */
    $legacy_filter = apply_filters_deprecated('media_buttons_context', array(''), '3.5.0', 'media_buttons');
    if ($legacy_filter) {
        // #WP22559. Close <a> if a plugin started by closing <a> to open their own <a> tag.
        if (0 === stripos(trim($legacy_filter), '</a>')) {
            $legacy_filter .= '</a>';
        }
        echo $legacy_filter;
    }
}

WordPress Version: 4.6

/**
 * Adds the media button to the editor
 *
 * @since 2.5.0
 *
 * @global int $post_ID
 *
 * @staticvar int $instance
 *
 * @param string $editor_id
 */
function media_buttons($editor_id = 'content')
{
    static $instance = 0;
    $instance++;
    $post = get_post();
    if (!$post && !empty($GLOBALS['post_ID'])) {
        $post = $GLOBALS['post_ID'];
    }
    wp_enqueue_media(array('post' => $post));
    $img = '<span class="wp-media-buttons-icon"></span> ';
    $id_attribute = ($instance === 1) ? ' id="insert-media-button"' : '';
    printf('<button type="button"%s class="button insert-media add_media" data-editor="%s">%s</button>', $id_attribute, esc_attr($editor_id), $img . __('Add Media'));
    /**
     * Filters the legacy (pre-3.5.0) media buttons.
     *
     * Use {@see 'media_buttons'} action instead.
     *
     * @since 2.5.0
     * @deprecated 3.5.0 Use {@see 'media_buttons'} action instead.
     *
     * @param string $string Media buttons context. Default empty.
     */
    $legacy_filter = apply_filters('media_buttons_context', '');
    if ($legacy_filter) {
        // #WP22559. Close <a> if a plugin started by closing <a> to open their own <a> tag.
        if (0 === stripos(trim($legacy_filter), '</a>')) {
            $legacy_filter .= '</a>';
        }
        echo $legacy_filter;
    }
}

WordPress Version: 4.3

/**
 * Adds the media button to the editor
 *
 * @since 2.5.0
 *
 * @global int $post_ID
 *
 * @staticvar int $instance
 *
 * @param string $editor_id
 */
function media_buttons($editor_id = 'content')
{
    static $instance = 0;
    $instance++;
    $post = get_post();
    if (!$post && !empty($GLOBALS['post_ID'])) {
        $post = $GLOBALS['post_ID'];
    }
    wp_enqueue_media(array('post' => $post));
    $img = '<span class="wp-media-buttons-icon"></span> ';
    $id_attribute = ($instance === 1) ? ' id="insert-media-button"' : '';
    printf('<button type="button"%s class="button insert-media add_media" data-editor="%s">%s</button>', $id_attribute, esc_attr($editor_id), $img . __('Add Media'));
    /**
     * Filter the legacy (pre-3.5.0) media buttons.
     *
     * @since 2.5.0
     * @deprecated 3.5.0 Use 'media_buttons' action instead.
     *
     * @param string $string Media buttons context. Default empty.
     */
    $legacy_filter = apply_filters('media_buttons_context', '');
    if ($legacy_filter) {
        // #WP22559. Close <a> if a plugin started by closing <a> to open their own <a> tag.
        if (0 === stripos(trim($legacy_filter), '</a>')) {
            $legacy_filter .= '</a>';
        }
        echo $legacy_filter;
    }
}

WordPress Version: 4.0

/**
 * Adds the media button to the editor
 *
 * @since 2.5.0
 *
 * @param string $editor_id
 */
function media_buttons($editor_id = 'content')
{
    static $instance = 0;
    $instance++;
    $post = get_post();
    if (!$post && !empty($GLOBALS['post_ID'])) {
        $post = $GLOBALS['post_ID'];
    }
    wp_enqueue_media(array('post' => $post));
    $img = '<span class="wp-media-buttons-icon"></span> ';
    $id_attribute = ($instance === 1) ? ' id="insert-media-button"' : '';
    printf('<a href="#"%s class="button insert-media add_media" data-editor="%s" title="%s">%s</a>', $id_attribute, esc_attr($editor_id), esc_attr__('Add Media'), $img . __('Add Media'));
    /**
     * Filter the legacy (pre-3.5.0) media buttons.
     *
     * @since 2.5.0
     * @deprecated 3.5.0 Use 'media_buttons' action instead.
     *
     * @param string $string Media buttons context. Default empty.
     */
    $legacy_filter = apply_filters('media_buttons_context', '');
    if ($legacy_filter) {
        // #WP22559. Close <a> if a plugin started by closing <a> to open their own <a> tag.
        if (0 === stripos(trim($legacy_filter), '</a>')) {
            $legacy_filter .= '</a>';
        }
        echo $legacy_filter;
    }
}

WordPress Version: 3.9

/**
 * Adds the media button to the editor
 *
 * @since 2.5.0
 *
 * @param string $editor_id
 */
function media_buttons($editor_id = 'content')
{
    $post = get_post();
    if (!$post && !empty($GLOBALS['post_ID'])) {
        $post = $GLOBALS['post_ID'];
    }
    wp_enqueue_media(array('post' => $post));
    $img = '<span class="wp-media-buttons-icon"></span> ';
    echo '<a href="#" id="insert-media-button" class="button insert-media add_media" data-editor="' . esc_attr($editor_id) . '" title="' . esc_attr__('Add Media') . '">' . $img . __('Add Media') . '</a>';
    /**
     * Filter the legacy (pre-3.5.0) media buttons.
     *
     * @since 2.5.0
     * @deprecated 3.5.0 Use 'media_buttons' action instead.
     *
     * @param string $string Media buttons context. Default empty.
     */
    $legacy_filter = apply_filters('media_buttons_context', '');
    if ($legacy_filter) {
        // #WP22559. Close <a> if a plugin started by closing <a> to open their own <a> tag.
        if (0 === stripos(trim($legacy_filter), '</a>')) {
            $legacy_filter .= '</a>';
        }
        echo $legacy_filter;
    }
}

WordPress Version: 3.7

/**
 * Adds the media button to the editor
 *
 * @since 2.5.0
 *
 * @param string $editor_id
 */
function media_buttons($editor_id = 'content')
{
    $post = get_post();
    if (!$post && !empty($GLOBALS['post_ID'])) {
        $post = $GLOBALS['post_ID'];
    }
    wp_enqueue_media(array('post' => $post));
    $img = '<span class="wp-media-buttons-icon"></span> ';
    echo '<a href="#" id="insert-media-button" class="button insert-media add_media" data-editor="' . esc_attr($editor_id) . '" title="' . esc_attr__('Add Media') . '">' . $img . __('Add Media') . '</a>';
    // Don't use this filter. Want to add a button? Use the media_buttons action.
    $legacy_filter = apply_filters('media_buttons_context', '');
    // deprecated
    if ($legacy_filter) {
        // #WP22559. Close <a> if a plugin started by closing <a> to open their own <a> tag.
        if (0 === stripos(trim($legacy_filter), '</a>')) {
            $legacy_filter .= '</a>';
        }
        echo $legacy_filter;
    }
}