wp_get_media_creation_timestamp

函数
wp_get_media_creation_timestamp ( $metadata )
参数
  • (array) $metadata The metadata returned by getID3::analyze().
    Required:
返回值
  • (int|false) A UNIX timestamp for the media's creation date if available or a boolean FALSE if a timestamp could not be determined.
定义位置
相关方法
get_media_itemget_media_itemsget_post_timestampwp_ajax_media_create_image_subsizeswp_kses_named_entities
引入
4.9.0
弃用
-

wp_get_media_creation_timestamp: 这个函数检索媒体创建时的时间戳。它需要一个参数,即媒体ID,并返回创建时间戳。

从媒体元数据中解析创建日期。

getID3库没有获取创建日期的标准方法,所以这个数据的位置可能根据MIME类型而变化。

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;
}

常见问题

FAQs
查看更多 >