media_id = self::$media_seq_id++;
$this->item_hide_icon = true;
$this->media_frame_title = __( 'Upload or select media from your WordPress media library', 'wp-data-access' );
$this->media_frame_remove = __( 'Remove media', 'wp-data-access' );
$this->media_types = '';
$this->media_frame_button = __( 'Select', 'wp-data-access' );
}
/**
* Overwrite method show_item: create media item to interact with the WordPress media library
*
* When adding a new media item type, modify the following methods:
* show_item_media()
*
* If you change this method all media items will be affected!
*/
public function show_item() {
?>
show_item_media(); ?>
show_context_action ) {
$this->add_media_library_interaction();
}
}
/**
* Uses the media id to the media
*
* Overwrite this method for every new media item.
*/
protected function show_item_media() {
if ( 'number' === $this->data_type ) {
// Column supports only one media file
$url = wp_get_attachment_url( $this->item_value );
if ( false !== $url ) {
$icon = wp_mime_type_icon( $this->item_value );
$title = get_the_title( $this->item_value );
$this->create_item_media( $url, $icon, $title );
}
} else {
// Column supports multiple media files
if ( null !== $this->item_value && '' !== $this->item_value ) {
$media_ids = explode( ',', $this->item_value );//phpcs:ignore - 8.1 proof
foreach ( $media_ids as $media_id ) {
$url = wp_get_attachment_url( $media_id );
if ( false !== $url ) {
$icon = wp_mime_type_icon( $media_id );
$title = get_the_title( $media_id );
$this->create_item_media( $url, $icon, $title );
}
}
}
}
}
private function create_item_media( $url, $icon, $title ) {
?>