wp_get_media_creation_timestamp() WordPress Function

The wp_get_media_creation_timestamp() function is used to get the timestamp for when a piece of media was created. This timestamp can be used to display when an image or video was created, or to order media by when it was created.

wp_get_media_creation_timestamp( array $metadata ) #

Parses creation date from media metadata.


Description

The getID3 library doesn’t have a standard method for getting creation dates, so the location of this data can vary based on the MIME type.


Top ↑

Parameters

$metadata

(array)(Required)The metadata returned by getID3::analyze().


Top ↑

Return

(int|false) A UNIX timestamp for the media's creation date if available or a boolean FALSE if a timestamp could not be determined.


Top ↑

Source

File: wp-admin/includes/media.php

function wp_get_media_creation_timestamp( $metadata ) {
	$creation_date = false;

	if ( empty( $metadata['fileformat'] ) ) {
		return $creation_date;
	}

	switch ( $metadata['fileformat'] ) {
		case 'asf':
			if ( isset( $metadata['asf']['file_properties_object']['creation_date_unix'] ) ) {
				$creation_date = (int) $metadata['asf']['file_properties_object']['creation_date_unix'];
			}
			break;

		case 'matroska':
		case 'webm':
			if ( isset( $metadata['matroska']['comments']['creation_time'][0] ) ) {
				$creation_date = strtotime( $metadata['matroska']['comments']['creation_time'][0] );
			} elseif ( isset( $metadata['matroska']['info'][0]['DateUTC_unix'] ) ) {
				$creation_date = (int) $metadata['matroska']['info'][0]['DateUTC_unix'];
			}
			break;

		case 'quicktime':
		case 'mp4':
			if ( isset( $metadata['quicktime']['moov']['subatoms'][0]['creation_time_unix'] ) ) {
				$creation_date = (int) $metadata['quicktime']['moov']['subatoms'][0]['creation_time_unix'];
			}
			break;
	}

	return $creation_date;
}


Top ↑

Changelog

Changelog
VersionDescription
4.9.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More