Add Media Library Column

require_once(dirname(__FILE__) . "/AddMediaLibraryColumn.php");
<?php

// Add Media Library Column: File Size
// Need help: https://bloggerpilot.com/snippet-media-filesize/


// Create the column
add_filter('manage_upload_columns', function ($columns) {

	$columns['bpFilesize']  = 'Dateigröße';
	$columns['bpDimension'] = 'Dimension';

	return $columns;
});

// Display the file size and dimension
add_action('manage_media_custom_column', function ($column_name, $media_item) {

	if (!wp_attachment_is_image($media_item))
	{
		return;
	}

	switch ($column_name)
	{
		case 'bpFilesize':
			$dateigroesse = filesize(get_attached_file($media_item));
			$bpFilesize   = size_format($dateigroesse, 2);
			if ($dateigroesse > MB_IN_BYTES)
			{
				$bpFilesize = "<span style='font-weight: 700; font-size: 1.2em;  background-color: yellow'>$bpFilesize</span>";
			}
			//			$bpFilesize = number_format_i18n($bpFilesize / KB_IN_BYTES, 2) . ' ' . "KB";
			echo $bpFilesize;
			break;
		case 'bpDimension':
			list($url, $width, $height) = wp_get_attachment_image_src($media_item, 'full');
			$bpDimension = number_format_i18n($width, 0) . "x" . number_format_i18n($height, 0);
			//	maximale Größe 1920 x 1080
			if ($width > 1920 || $height > 1080)
			{
				echo "<span style='font-size: 1.2em; background-color: yellow'>" . $bpDimension . "</span>";
			}
			else
			{
				echo $bpDimension;
			}
			//			echo get_post_meta($media_item, '_width', true);
			break;
		default:
			return;
	}

},         10, 2);

// Format the column width with CSS
add_action('admin_head', function () {

	echo '<style>.column-bpFilesize, .column-bpDimension {width: 100px;}</style>';
});

// Make the column sortable
add_filter('manage_upload_sortable_columns', function ($sortable_columns) {

	//	$sortable_columns['bpFilesize']  = 'bpFilesize';
	//	$sortable_columns['bpDimension'] = 'bpDimension';

	return $sortable_columns;
});