将媒体按钮添加到编辑器

原型

media_buttons( string $editor_id = 'content' )

参数

$editor_id (string) (Optional)

源文件

路径:wp-admin/includes/media.php

<?php
...
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;
	}
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/media_buttons/