media_buttons

Adds the media button to the editor.

Description

media_buttons( (string) $editor_id = 'content' ); 

Parameters (1)

0. $editor_id — Optional. (string) => 'content'
The editor id.

Usage

  1. if ( !function_exists( 'media_buttons' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/media.php'; 
  3.  
  4. // The editor id. 
  5. $editor_id = 'content'; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = media_buttons($editor_id); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/media.php  
  1. function media_buttons($editor_id = 'content') { 
  2. static $instance = 0; 
  3. $instance++; 
  4.  
  5. $post = get_post(); 
  6. if ( ! $post && ! empty( $GLOBALS['post_ID'] ) ) 
  7. $post = $GLOBALS['post_ID']; 
  8.  
  9. wp_enqueue_media( array( 
  10. 'post' => $post 
  11. ) ); 
  12.  
  13. $img = '<span class="wp-media-buttons-icon"></span> '; 
  14.  
  15. $id_attribute = $instance === 1 ? ' id="insert-media-button"' : ''; 
  16. printf( '<button type="button"%s class="button insert-media add_media" data-editor="%s">%s</button>',  
  17. $id_attribute,  
  18. esc_attr( $editor_id ),  
  19. $img . __( 'Add Media' ) 
  20. ); 
  21. /** 
  22. * Filters the legacy (pre-3.5.0) media buttons. 
  23. * Use {@see 'media_buttons'} action instead. 
  24. * @since 2.5.0 
  25. * @deprecated 3.5.0 Use {@see 'media_buttons'} action instead. 
  26. * @param string $string Media buttons context. Default empty. 
  27. */ 
  28. $legacy_filter = apply_filters( 'media_buttons_context', '' ); 
  29.  
  30. if ( $legacy_filter ) { 
  31. // #WP22559. Close <a> if a plugin started by closing <a> to open their own <a> tag. 
  32. if ( 0 === stripos( trim( $legacy_filter ), '</a>' ) ) 
  33. $legacy_filter .= '</a>'; 
  34. echo $legacy_filter;