wp/wp-admin/includes/media.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
     5  * @package WordPress
     5  * @package WordPress
     6  * @subpackage Administration
     6  * @subpackage Administration
     7  */
     7  */
     8 
     8 
     9 /**
     9 /**
    10  * Defines the default media upload tabs
    10  * Defines the default media upload tabs.
    11  *
    11  *
    12  * @since 2.5.0
    12  * @since 2.5.0
    13  *
    13  *
    14  * @return string[] Default tabs.
    14  * @return string[] Default tabs.
    15  */
    15  */
    30 	 */
    30 	 */
    31 	return apply_filters( 'media_upload_tabs', $_default_tabs );
    31 	return apply_filters( 'media_upload_tabs', $_default_tabs );
    32 }
    32 }
    33 
    33 
    34 /**
    34 /**
    35  * Adds the gallery tab back to the tabs array if post has image attachments
    35  * Adds the gallery tab back to the tabs array if post has image attachments.
    36  *
    36  *
    37  * @since 2.5.0
    37  * @since 2.5.0
    38  *
    38  *
    39  * @global wpdb $wpdb WordPress database abstraction object.
    39  * @global wpdb $wpdb WordPress database abstraction object.
    40  *
    40  *
   280 /**
   280 /**
   281  * Saves a file submitted from a POST request and create an attachment post for it.
   281  * Saves a file submitted from a POST request and create an attachment post for it.
   282  *
   282  *
   283  * @since 2.5.0
   283  * @since 2.5.0
   284  *
   284  *
   285  * @param string $file_id   Index of the `$_FILES` array that the file was sent. Required.
   285  * @param string $file_id   Index of the `$_FILES` array that the file was sent.
   286  * @param int    $post_id   The post ID of a post to attach the media item to. Required, but can
   286  * @param int    $post_id   The post ID of a post to attach the media item to. Required, but can
   287  *                          be set to 0, creating a media item that has no relationship to a post.
   287  *                          be set to 0, creating a media item that has no relationship to a post.
   288  * @param array  $post_data Optional. Overwrite some of the attachment.
   288  * @param array  $post_data Optional. Overwrite some of the attachment.
   289  * @param array  $overrides Optional. Override the wp_handle_upload() behavior.
   289  * @param array  $overrides Optional. Override the wp_handle_upload() behavior.
   290  * @return int|WP_Error ID of the attachment or a WP_Error object on failure.
   290  * @return int|WP_Error ID of the attachment or a WP_Error object on failure.
   359 		}
   359 		}
   360 
   360 
   361 		if ( ! empty( $meta['track_number'] ) ) {
   361 		if ( ! empty( $meta['track_number'] ) ) {
   362 			$track_number = explode( '/', $meta['track_number'] );
   362 			$track_number = explode( '/', $meta['track_number'] );
   363 
   363 
   364 			if ( isset( $track_number[1] ) ) {
   364 			if ( is_numeric( $track_number[0] ) ) {
   365 				/* translators: Audio file track information. 1: Audio track number, 2: Total audio tracks. */
   365 				if ( isset( $track_number[1] ) && is_numeric( $track_number[1] ) ) {
   366 				$content .= ' ' . sprintf( __( 'Track %1$s of %2$s.' ), number_format_i18n( $track_number[0] ), number_format_i18n( $track_number[1] ) );
   366 					$content .= ' ' . sprintf(
   367 			} else {
   367 						/* translators: Audio file track information. 1: Audio track number, 2: Total audio tracks. */
   368 				/* translators: Audio file track information. %s: Audio track number. */
   368 						__( 'Track %1$s of %2$s.' ),
   369 				$content .= ' ' . sprintf( __( 'Track %s.' ), number_format_i18n( $track_number[0] ) );
   369 						number_format_i18n( $track_number[0] ),
       
   370 						number_format_i18n( $track_number[1] )
       
   371 					);
       
   372 				} else {
       
   373 					$content .= ' ' . sprintf(
       
   374 						/* translators: Audio file track information. %s: Audio track number. */
       
   375 						__( 'Track %s.' ),
       
   376 						number_format_i18n( $track_number[0] )
       
   377 					);
       
   378 				}
   370 			}
   379 			}
   371 		}
   380 		}
   372 
   381 
   373 		if ( ! empty( $meta['genre'] ) ) {
   382 		if ( ! empty( $meta['genre'] ) ) {
   374 			/* translators: Audio file genre information. %s: Audio genre name. */
   383 			/* translators: Audio file genre information. %s: Audio genre name. */
   531 		wp_enqueue_style( 'deprecated-media' );
   540 		wp_enqueue_style( 'deprecated-media' );
   532 	}
   541 	}
   533 
   542 
   534 	?>
   543 	?>
   535 	<script type="text/javascript">
   544 	<script type="text/javascript">
   536 	addLoadEvent = function(func){if(typeof jQuery!=='undefined')jQuery(document).ready(func);else if(typeof wpOnload!=='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
   545 	addLoadEvent = function(func){if(typeof jQuery!=='undefined')jQuery(function(){func();});else if(typeof wpOnload!=='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
   537 	var ajaxurl = '<?php echo esc_js( admin_url( 'admin-ajax.php', 'relative' ) ); ?>', pagenow = 'media-upload-popup', adminpage = 'media-upload-popup',
   546 	var ajaxurl = '<?php echo esc_js( admin_url( 'admin-ajax.php', 'relative' ) ); ?>', pagenow = 'media-upload-popup', adminpage = 'media-upload-popup',
   538 	isRtl = <?php echo (int) is_rtl(); ?>;
   547 	isRtl = <?php echo (int) is_rtl(); ?>;
   539 	</script>
   548 	</script>
   540 	<?php
   549 	<?php
   541 	/** This action is documented in wp-admin/admin-header.php */
   550 	/** This action is documented in wp-admin/admin-header.php */
   575 	if ( is_string( $content_func ) ) {
   584 	if ( is_string( $content_func ) ) {
   576 		/**
   585 		/**
   577 		 * Fires in the admin header for each specific form tab in the legacy
   586 		 * Fires in the admin header for each specific form tab in the legacy
   578 		 * (pre-3.5.0) media upload popup.
   587 		 * (pre-3.5.0) media upload popup.
   579 		 *
   588 		 *
   580 		 * The dynamic portion of the hook, `$content_func`, refers to the form
   589 		 * The dynamic portion of the hook name, `$content_func`, refers to the form
   581 		 * callback for the media upload type. Possible values include
   590 		 * callback for the media upload type.
   582 		 * 'media_upload_type_form', 'media_upload_type_url_form', and
       
   583 		 * 'media_upload_library_form'.
       
   584 		 *
   591 		 *
   585 		 * @since 2.5.0
   592 		 * @since 2.5.0
   586 		 */
   593 		 */
   587 		do_action( "admin_head_{$content_func}" );
   594 		do_action( "admin_head_{$content_func}" );
   588 	}
   595 	}
   612 	</html>
   619 	</html>
   613 	<?php
   620 	<?php
   614 }
   621 }
   615 
   622 
   616 /**
   623 /**
   617  * Adds the media button to the editor
   624  * Adds the media button to the editor.
   618  *
   625  *
   619  * @since 2.5.0
   626  * @since 2.5.0
   620  *
   627  *
   621  * @global int $post_ID
   628  * @global int $post_ID
   622  *
   629  *
   713 /**
   720 /**
   714  * Handles form submissions for the legacy media uploader.
   721  * Handles form submissions for the legacy media uploader.
   715  *
   722  *
   716  * @since 2.5.0
   723  * @since 2.5.0
   717  *
   724  *
   718  * @return mixed void|object WP_Error on failure
   725  * @return null|array|void Array of error messages keyed by attachment ID, null or void on success.
   719  */
   726  */
   720 function media_upload_form_handler() {
   727 function media_upload_form_handler() {
   721 	check_admin_referer( 'media-form' );
   728 	check_admin_referer( 'media-form' );
   722 
   729 
   723 	$errors = null;
   730 	$errors = null;
   974 
   981 
   975 /**
   982 /**
   976  * Downloads an image from the specified URL, saves it as an attachment, and optionally attaches it to a post.
   983  * Downloads an image from the specified URL, saves it as an attachment, and optionally attaches it to a post.
   977  *
   984  *
   978  * @since 2.6.0
   985  * @since 2.6.0
   979  * @since 4.2.0 Introduced the `$return` parameter.
   986  * @since 4.2.0 Introduced the `$return_type` parameter.
   980  * @since 4.8.0 Introduced the 'id' option for the `$return` parameter.
   987  * @since 4.8.0 Introduced the 'id' option for the `$return_type` parameter.
   981  * @since 5.3.0 The `$post_id` parameter was made optional.
   988  * @since 5.3.0 The `$post_id` parameter was made optional.
   982  * @since 5.4.0 The original URL of the attachment is stored in the `_source_url`
   989  * @since 5.4.0 The original URL of the attachment is stored in the `_source_url`
   983  *              post meta value.
   990  *              post meta value.
   984  *
   991  *
   985  * @param string $file    The URL of the image to download.
   992  * @param string $file        The URL of the image to download.
   986  * @param int    $post_id Optional. The post ID the media is to be associated with.
   993  * @param int    $post_id     Optional. The post ID the media is to be associated with.
   987  * @param string $desc    Optional. Description of the image.
   994  * @param string $desc        Optional. Description of the image.
   988  * @param string $return  Optional. Accepts 'html' (image tag html) or 'src' (URL),
   995  * @param string $return_type Optional. Accepts 'html' (image tag html) or 'src' (URL),
   989  *                        or 'id' (attachment ID). Default 'html'.
   996  *                            or 'id' (attachment ID). Default 'html'.
   990  * @return string|int|WP_Error Populated HTML img tag, attachment ID, or attachment source
   997  * @return string|int|WP_Error Populated HTML img tag, attachment ID, or attachment source
   991  *                             on success, WP_Error object otherwise.
   998  *                             on success, WP_Error object otherwise.
   992  */
   999  */
   993 function media_sideload_image( $file, $post_id = 0, $desc = null, $return = 'html' ) {
  1000 function media_sideload_image( $file, $post_id = 0, $desc = null, $return_type = 'html' ) {
   994 	if ( ! empty( $file ) ) {
  1001 	if ( ! empty( $file ) ) {
   995 
  1002 
   996 		$allowed_extensions = array( 'jpg', 'jpeg', 'jpe', 'png', 'gif', 'webp' );
  1003 		$allowed_extensions = array( 'jpg', 'jpeg', 'jpe', 'png', 'gif', 'webp' );
   997 
  1004 
   998 		/**
  1005 		/**
  1043 
  1050 
  1044 		// Store the original attachment source in meta.
  1051 		// Store the original attachment source in meta.
  1045 		add_post_meta( $id, '_source_url', $file );
  1052 		add_post_meta( $id, '_source_url', $file );
  1046 
  1053 
  1047 		// If attachment ID was requested, return it.
  1054 		// If attachment ID was requested, return it.
  1048 		if ( 'id' === $return ) {
  1055 		if ( 'id' === $return_type ) {
  1049 			return $id;
  1056 			return $id;
  1050 		}
  1057 		}
  1051 
  1058 
  1052 		$src = wp_get_attachment_url( $id );
  1059 		$src = wp_get_attachment_url( $id );
  1053 	}
  1060 	}
  1054 
  1061 
  1055 	// Finally, check to make sure the file has been saved, then return the HTML.
  1062 	// Finally, check to make sure the file has been saved, then return the HTML.
  1056 	if ( ! empty( $src ) ) {
  1063 	if ( ! empty( $src ) ) {
  1057 		if ( 'src' === $return ) {
  1064 		if ( 'src' === $return_type ) {
  1058 			return $src;
  1065 			return $src;
  1059 		}
  1066 		}
  1060 
  1067 
  1061 		$alt  = isset( $desc ) ? esc_attr( $desc ) : '';
  1068 		$alt  = isset( $desc ) ? esc_attr( $desc ) : '';
  1062 		$html = "<img src='$src' alt='$alt' />";
  1069 		$html = "<img src='$src' alt='$alt' />";
  1116 
  1123 
  1117 	return wp_iframe( 'media_upload_library_form', $errors );
  1124 	return wp_iframe( 'media_upload_library_form', $errors );
  1118 }
  1125 }
  1119 
  1126 
  1120 /**
  1127 /**
  1121  * Retrieve HTML for the image alignment radio buttons with the specified one checked.
  1128  * Retrieves HTML for the image alignment radio buttons with the specified one checked.
  1122  *
  1129  *
  1123  * @since 2.7.0
  1130  * @since 2.7.0
  1124  *
  1131  *
  1125  * @param WP_Post $post
  1132  * @param WP_Post $post
  1126  * @param string  $checked
  1133  * @param string  $checked
  1154 
  1161 
  1155 	return implode( "\n", $out );
  1162 	return implode( "\n", $out );
  1156 }
  1163 }
  1157 
  1164 
  1158 /**
  1165 /**
  1159  * Retrieve HTML for the size radio buttons with the specified one checked.
  1166  * Retrieves HTML for the size radio buttons with the specified one checked.
  1160  *
  1167  *
  1161  * @since 2.7.0
  1168  * @since 2.7.0
  1162  *
  1169  *
  1163  * @param WP_Post     $post
  1170  * @param WP_Post     $post
  1164  * @param bool|string $check
  1171  * @param bool|string $check
  1232 		'html'  => implode( "\n", $out ),
  1239 		'html'  => implode( "\n", $out ),
  1233 	);
  1240 	);
  1234 }
  1241 }
  1235 
  1242 
  1236 /**
  1243 /**
  1237  * Retrieve HTML for the Link URL buttons with the default link type as specified.
  1244  * Retrieves HTML for the Link URL buttons with the default link type as specified.
  1238  *
  1245  *
  1239  * @since 2.7.0
  1246  * @since 2.7.0
  1240  *
  1247  *
  1241  * @param WP_Post $post
  1248  * @param WP_Post $post
  1242  * @param string  $url_type
  1249  * @param string  $url_type
  1266 	<button type='button' class='button urlpost' data-link-url='" . esc_attr( $link ) . "'>" . __( 'Attachment Post URL' ) . '</button>
  1273 	<button type='button' class='button urlpost' data-link-url='" . esc_attr( $link ) . "'>" . __( 'Attachment Post URL' ) . '</button>
  1267 ';
  1274 ';
  1268 }
  1275 }
  1269 
  1276 
  1270 /**
  1277 /**
  1271  * Output a textarea element for inputting an attachment caption.
  1278  * Outputs a textarea element for inputting an attachment caption.
  1272  *
  1279  *
  1273  * @since 3.4.0
  1280  * @since 3.4.0
  1274  *
  1281  *
  1275  * @param WP_Post $edit_post Attachment WP_Post object.
  1282  * @param WP_Post $edit_post Attachment WP_Post object.
  1276  * @return string HTML markup for the textarea element.
  1283  * @return string HTML markup for the textarea element.
  1319  * @return array Filtered attachment form fields.
  1326  * @return array Filtered attachment form fields.
  1320  */
  1327  */
  1321 function media_post_single_attachment_fields_to_edit( $form_fields, $post ) {
  1328 function media_post_single_attachment_fields_to_edit( $form_fields, $post ) {
  1322 	unset( $form_fields['image_url'] );
  1329 	unset( $form_fields['image_url'] );
  1323 	return $form_fields;
  1330 	return $form_fields;
  1324 }
       
  1325 
       
  1326 /**
       
  1327  * Filters input from media_upload_form_handler() and assigns a default
       
  1328  * post_title from the file name if none supplied.
       
  1329  *
       
  1330  * Illustrates the use of the {@see 'attachment_fields_to_save'} filter
       
  1331  * which can be used to add default values to any field before saving to DB.
       
  1332  *
       
  1333  * @since 2.5.0
       
  1334  *
       
  1335  * @param array $post       The WP_Post attachment object converted to an array.
       
  1336  * @param array $attachment An array of attachment metadata.
       
  1337  * @return array Filtered attachment post object.
       
  1338  */
       
  1339 function image_attachment_fields_to_save( $post, $attachment ) {
       
  1340 	if ( 'image' === substr( $post['post_mime_type'], 0, 5 ) ) {
       
  1341 		if ( strlen( trim( $post['post_title'] ) ) == 0 ) {
       
  1342 			$attachment_url                           = ( isset( $post['attachment_url'] ) ) ? $post['attachment_url'] : $post['guid'];
       
  1343 			$post['post_title']                       = preg_replace( '/\.\w+$/', '', wp_basename( $attachment_url ) );
       
  1344 			$post['errors']['post_title']['errors'][] = __( 'Empty Title filled from filename.' );
       
  1345 		}
       
  1346 	}
       
  1347 
       
  1348 	return $post;
       
  1349 }
  1331 }
  1350 
  1332 
  1351 /**
  1333 /**
  1352  * Retrieves the media element HTML to send to the editor.
  1334  * Retrieves the media element HTML to send to the editor.
  1353  *
  1335  *
  1511 
  1493 
  1512 	return $form_fields;
  1494 	return $form_fields;
  1513 }
  1495 }
  1514 
  1496 
  1515 /**
  1497 /**
  1516  * Retrieve HTML for media items of post gallery.
  1498  * Retrieves HTML for media items of post gallery.
  1517  *
  1499  *
  1518  * The HTML markup retrieved will be created for the progress of SWF Upload
  1500  * The HTML markup retrieved will be created for the progress of SWF Upload
  1519  * component. Will also create link for showing and hiding the form to modify
  1501  * component. Will also create link for showing and hiding the form to modify
  1520  * the image attachment.
  1502  * the image attachment.
  1521  *
  1503  *
  1522  * @since 2.5.0
  1504  * @since 2.5.0
  1523  *
  1505  *
  1524  * @global WP_Query $wp_the_query WordPress Query object.
  1506  * @global WP_Query $wp_the_query WordPress Query object.
  1525  *
  1507  *
  1526  * @param int   $post_id Optional. Post ID.
  1508  * @param int   $post_id Post ID.
  1527  * @param array $errors  Errors for attachment, if any.
  1509  * @param array $errors  Errors for attachment, if any.
  1528  * @return string
  1510  * @return string HTML content for media items of post gallery.
  1529  */
  1511  */
  1530 function get_media_items( $post_id, $errors ) {
  1512 function get_media_items( $post_id, $errors ) {
  1531 	$attachments = array();
  1513 	$attachments = array();
  1532 
  1514 
  1533 	if ( $post_id ) {
  1515 	if ( $post_id ) {
  1568 
  1550 
  1569 	return $output;
  1551 	return $output;
  1570 }
  1552 }
  1571 
  1553 
  1572 /**
  1554 /**
  1573  * Retrieve HTML form for modifying the image attachment.
  1555  * Retrieves HTML form for modifying the image attachment.
  1574  *
  1556  *
  1575  * @since 2.5.0
  1557  * @since 2.5.0
  1576  *
  1558  *
  1577  * @global string $redir_tab
  1559  * @global string $redir_tab
  1578  *
  1560  *
  2501 		t.preloadImg.onerror = t.resetImageData;
  2483 		t.preloadImg.onerror = t.resetImageData;
  2502 		t.preloadImg.src = src;
  2484 		t.preloadImg.src = src;
  2503 	}
  2485 	}
  2504 	};
  2486 	};
  2505 
  2487 
  2506 	jQuery(document).ready( function($) {
  2488 	jQuery( function($) {
  2507 		$('.media-types input').click( function() {
  2489 		$('.media-types input').click( function() {
  2508 			$('table.describe').toggleClass('not-image', $('#not-image').prop('checked') );
  2490 			$('table.describe').toggleClass('not-image', $('#not-image').prop('checked') );
  2509 		});
  2491 		});
  2510 	});
  2492 	} );
  2511 	</script>
  2493 	</script>
  2512 
  2494 
  2513 	<div id="media-items">
  2495 	<div id="media-items">
  2514 	<div class="media-item media-blank">
  2496 	<div class="media-item media-blank">
  2515 	<?php
  2497 	<?php
  2528 	</form>
  2510 	</form>
  2529 	<?php
  2511 	<?php
  2530 }
  2512 }
  2531 
  2513 
  2532 /**
  2514 /**
  2533  * Adds gallery form to upload iframe
  2515  * Adds gallery form to upload iframe.
  2534  *
  2516  *
  2535  * @since 2.5.0
  2517  * @since 2.5.0
  2536  *
  2518  *
  2537  * @global string $redir_tab
  2519  * @global string $redir_tab
  2538  * @global string $type
  2520  * @global string $type
  2577 	<a href="#" id="desc"><?php _e( 'Descending' ); ?></a> |
  2559 	<a href="#" id="desc"><?php _e( 'Descending' ); ?></a> |
  2578 	<a href="#" id="clear"><?php _ex( 'Clear', 'verb' ); ?></a>
  2560 	<a href="#" id="clear"><?php _ex( 'Clear', 'verb' ); ?></a>
  2579 	</div>
  2561 	</div>
  2580 	<form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="gallery-form">
  2562 	<form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="gallery-form">
  2581 		<?php wp_nonce_field( 'media-form' ); ?>
  2563 		<?php wp_nonce_field( 'media-form' ); ?>
  2582 		<?php // media_upload_form( $errors ); ?>
       
  2583 	<table class="widefat">
  2564 	<table class="widefat">
  2584 	<thead><tr>
  2565 	<thead><tr>
  2585 	<th><?php _e( 'Media' ); ?></th>
  2566 	<th><?php _e( 'Media' ); ?></th>
  2586 	<th class="order-head"><?php _e( 'Order' ); ?></th>
  2567 	<th class="order-head"><?php _e( 'Order' ); ?></th>
  2587 	<th class="actions-head"><?php _e( 'Actions' ); ?></th>
  2568 	<th class="actions-head"><?php _e( 'Actions' ); ?></th>
  2879 	</div>
  2860 	</div>
  2880 	</form>
  2861 	</form>
  2881 
  2862 
  2882 	<form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="library-form">
  2863 	<form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="library-form">
  2883 	<?php wp_nonce_field( 'media-form' ); ?>
  2864 	<?php wp_nonce_field( 'media-form' ); ?>
  2884 	<?php // media_upload_form( $errors ); ?>
       
  2885 
  2865 
  2886 	<script type="text/javascript">
  2866 	<script type="text/javascript">
  2887 	jQuery(function($){
  2867 	jQuery(function($){
  2888 		var preloaded = $(".media-item.preloaded");
  2868 		var preloaded = $(".media-item.preloaded");
  2889 		if ( preloaded.length > 0 ) {
  2869 		if ( preloaded.length > 0 ) {
  2904 	</form>
  2884 	</form>
  2905 	<?php
  2885 	<?php
  2906 }
  2886 }
  2907 
  2887 
  2908 /**
  2888 /**
  2909  * Creates the form for external url
  2889  * Creates the form for external url.
  2910  *
  2890  *
  2911  * @since 2.7.0
  2891  * @since 2.7.0
  2912  *
  2892  *
  2913  * @param string $default_view
  2893  * @param string $default_view
  2914  * @return string the form html
  2894  * @return string HTML content of the form.
  2915  */
  2895  */
  2916 function wp_media_insert_url_form( $default_view = 'image' ) {
  2896 function wp_media_insert_url_form( $default_view = 'image' ) {
  2917 	/** This filter is documented in wp-admin/includes/media.php */
  2897 	/** This filter is documented in wp-admin/includes/media.php */
  2918 	if ( ! apply_filters( 'disable_captions', '' ) ) {
  2898 	if ( ! apply_filters( 'disable_captions', '' ) ) {
  2919 		$caption = '
  2899 		$caption = '
  3230 		<p class="attachment-alt-text-description" id="alt-text-description">
  3210 		<p class="attachment-alt-text-description" id="alt-text-description">
  3231 		<?php
  3211 		<?php
  3232 
  3212 
  3233 		printf(
  3213 		printf(
  3234 			/* translators: 1: Link to tutorial, 2: Additional link attributes, 3: Accessibility text. */
  3214 			/* translators: 1: Link to tutorial, 2: Additional link attributes, 3: Accessibility text. */
  3235 			__( '<a href="%1$s" %2$s>Describe the purpose of the image%3$s</a>. Leave empty if the image is purely decorative.' ),
  3215 			__( '<a href="%1$s" %2$s>Learn how to describe the purpose of the image%3$s</a>. Leave empty if the image is purely decorative.' ),
  3236 			esc_url( 'https://www.w3.org/WAI/tutorials/images/decision-tree' ),
  3216 			esc_url( 'https://www.w3.org/WAI/tutorials/images/decision-tree' ),
  3237 			'target="_blank" rel="noopener"',
  3217 			'target="_blank" rel="noopener"',
  3238 			sprintf(
  3218 			sprintf(
  3239 				'<span class="screen-reader-text"> %s</span>',
  3219 				'<span class="screen-reader-text"> %s</span>',
  3240 				/* translators: Accessibility text. */
  3220 				/* translators: Accessibility text. */
  3380 	$file_size = false;
  3360 	$file_size = false;
  3381 
  3361 
  3382 	if ( isset( $meta['filesize'] ) ) {
  3362 	if ( isset( $meta['filesize'] ) ) {
  3383 		$file_size = $meta['filesize'];
  3363 		$file_size = $meta['filesize'];
  3384 	} elseif ( file_exists( $file ) ) {
  3364 	} elseif ( file_exists( $file ) ) {
  3385 		$file_size = filesize( $file );
  3365 		$file_size = wp_filesize( $file );
  3386 	}
  3366 	}
  3387 
  3367 
  3388 	if ( ! empty( $file_size ) ) {
  3368 	if ( ! empty( $file_size ) ) {
  3389 		?>
  3369 		?>
  3390 		<div class="misc-pub-section misc-pub-filesize">
  3370 		<div class="misc-pub-section misc-pub-filesize">
  3493 		<?php
  3473 		<?php
  3494 	}
  3474 	}
  3495 }
  3475 }
  3496 
  3476 
  3497 /**
  3477 /**
  3498  * Parse ID3v2, ID3v1, and getID3 comments to extract usable data
  3478  * Parses ID3v2, ID3v1, and getID3 comments to extract usable data.
  3499  *
  3479  *
  3500  * @since 3.6.0
  3480  * @since 3.6.0
  3501  *
  3481  *
  3502  * @param array $metadata An existing array with data
  3482  * @param array $metadata An existing array with data.
  3503  * @param array $data Data supplied by ID3 tags
  3483  * @param array $data Data supplied by ID3 tags.
  3504  */
  3484  */
  3505 function wp_add_id3_tag_data( &$metadata, $data ) {
  3485 function wp_add_id3_tag_data( &$metadata, $data ) {
  3506 	foreach ( array( 'id3v2', 'id3v1' ) as $version ) {
  3486 	foreach ( array( 'id3v2', 'id3v1' ) as $version ) {
  3507 		if ( ! empty( $data[ $version ]['comments'] ) ) {
  3487 		if ( ! empty( $data[ $version ]['comments'] ) ) {
  3508 			foreach ( $data[ $version ]['comments'] as $key => $list ) {
  3488 			foreach ( $data[ $version ]['comments'] as $key => $list ) {
  3538 		}
  3518 		}
  3539 	}
  3519 	}
  3540 }
  3520 }
  3541 
  3521 
  3542 /**
  3522 /**
  3543  * Retrieve metadata from a video file's ID3 tags
  3523  * Retrieves metadata from a video file's ID3 tags.
  3544  *
  3524  *
  3545  * @since 3.6.0
  3525  * @since 3.6.0
  3546  *
  3526  *
  3547  * @param string $file Path to file.
  3527  * @param string $file Path to file.
  3548  * @return array|false Returns array of metadata, if found.
  3528  * @return array|false Returns array of metadata, if found.
  3560 
  3540 
  3561 	if ( ! class_exists( 'getID3', false ) ) {
  3541 	if ( ! class_exists( 'getID3', false ) ) {
  3562 		require ABSPATH . WPINC . '/ID3/getid3.php';
  3542 		require ABSPATH . WPINC . '/ID3/getid3.php';
  3563 	}
  3543 	}
  3564 
  3544 
  3565 	$id3  = new getID3();
  3545 	$id3 = new getID3();
       
  3546 	// Required to get the `created_timestamp` value.
       
  3547 	$id3->options_audiovideo_quicktime_ReturnAtomData = true; // phpcs:ignore WordPress.NamingConventions.ValidVariableName
       
  3548 
  3566 	$data = $id3->analyze( $file );
  3549 	$data = $id3->analyze( $file );
  3567 
  3550 
  3568 	if ( isset( $data['video']['lossless'] ) ) {
  3551 	if ( isset( $data['video']['lossless'] ) ) {
  3569 		$metadata['lossless'] = $data['video']['lossless'];
  3552 		$metadata['lossless'] = $data['video']['lossless'];
  3570 	}
  3553 	}
  3643 	 * @since 4.9.0
  3626 	 * @since 4.9.0
  3644 	 *
  3627 	 *
  3645 	 * @param array  $metadata       Filtered Video metadata.
  3628 	 * @param array  $metadata       Filtered Video metadata.
  3646 	 * @param string $file           Path to video file.
  3629 	 * @param string $file           Path to video file.
  3647 	 * @param string $file_format    File format of video, as analyzed by getID3.
  3630 	 * @param string $file_format    File format of video, as analyzed by getID3.
  3648 	 * @param string $data           Raw metadata from getID3.
  3631 	 * @param array  $data           Raw metadata from getID3.
  3649 	 */
  3632 	 */
  3650 	return apply_filters( 'wp_read_video_metadata', $metadata, $file, $file_format, $data );
  3633 	return apply_filters( 'wp_read_video_metadata', $metadata, $file, $file_format, $data );
  3651 }
  3634 }
  3652 
  3635 
  3653 /**
  3636 /**
  3654  * Retrieve metadata from an audio file's ID3 tags.
  3637  * Retrieves metadata from an audio file's ID3 tags.
  3655  *
  3638  *
  3656  * @since 3.6.0
  3639  * @since 3.6.0
  3657  *
  3640  *
  3658  * @param string $file Path to file.
  3641  * @param string $file Path to file.
  3659  * @return array|false Returns array of metadata, if found.
  3642  * @return array|false Returns array of metadata, if found.
  3671 
  3654 
  3672 	if ( ! class_exists( 'getID3', false ) ) {
  3655 	if ( ! class_exists( 'getID3', false ) ) {
  3673 		require ABSPATH . WPINC . '/ID3/getid3.php';
  3656 		require ABSPATH . WPINC . '/ID3/getid3.php';
  3674 	}
  3657 	}
  3675 
  3658 
  3676 	$id3  = new getID3();
  3659 	$id3 = new getID3();
       
  3660 	// Required to get the `created_timestamp` value.
       
  3661 	$id3->options_audiovideo_quicktime_ReturnAtomData = true; // phpcs:ignore WordPress.NamingConventions.ValidVariableName
       
  3662 
  3677 	$data = $id3->analyze( $file );
  3663 	$data = $id3->analyze( $file );
  3678 
  3664 
  3679 	if ( ! empty( $data['audio'] ) ) {
  3665 	if ( ! empty( $data['audio'] ) ) {
  3680 		unset( $data['audio']['streams'] );
  3666 		unset( $data['audio']['streams'] );
  3681 		$metadata = $data['audio'];
  3667 		$metadata = $data['audio'];
  3713 
  3699 
  3714 	return $metadata;
  3700 	return $metadata;
  3715 }
  3701 }
  3716 
  3702 
  3717 /**
  3703 /**
  3718  * Parse creation date from media metadata.
  3704  * Parses creation date from media metadata.
  3719  *
  3705  *
  3720  * The getID3 library doesn't have a standard method for getting creation dates,
  3706  * The getID3 library doesn't have a standard method for getting creation dates,
  3721  * so the location of this data can vary based on the MIME type.
  3707  * so the location of this data can vary based on the MIME type.
  3722  *
  3708  *
  3723  * @since 4.9.0
  3709  * @since 4.9.0
  3742 			}
  3728 			}
  3743 			break;
  3729 			break;
  3744 
  3730 
  3745 		case 'matroska':
  3731 		case 'matroska':
  3746 		case 'webm':
  3732 		case 'webm':
  3747 			if ( isset( $metadata['matroska']['comments']['creation_time']['0'] ) ) {
  3733 			if ( isset( $metadata['matroska']['comments']['creation_time'][0] ) ) {
  3748 				$creation_date = strtotime( $metadata['matroska']['comments']['creation_time']['0'] );
  3734 				$creation_date = strtotime( $metadata['matroska']['comments']['creation_time'][0] );
  3749 			} elseif ( isset( $metadata['matroska']['info']['0']['DateUTC_unix'] ) ) {
  3735 			} elseif ( isset( $metadata['matroska']['info'][0]['DateUTC_unix'] ) ) {
  3750 				$creation_date = (int) $metadata['matroska']['info']['0']['DateUTC_unix'];
  3736 				$creation_date = (int) $metadata['matroska']['info'][0]['DateUTC_unix'];
  3751 			}
  3737 			}
  3752 			break;
  3738 			break;
  3753 
  3739 
  3754 		case 'quicktime':
  3740 		case 'quicktime':
  3755 		case 'mp4':
  3741 		case 'mp4':
  3756 			if ( isset( $metadata['quicktime']['moov']['subatoms']['0']['creation_time_unix'] ) ) {
  3742 			if ( isset( $metadata['quicktime']['moov']['subatoms'][0]['creation_time_unix'] ) ) {
  3757 				$creation_date = (int) $metadata['quicktime']['moov']['subatoms']['0']['creation_time_unix'];
  3743 				$creation_date = (int) $metadata['quicktime']['moov']['subatoms'][0]['creation_time_unix'];
  3758 			}
  3744 			}
  3759 			break;
  3745 			break;
  3760 	}
  3746 	}
  3761 
  3747 
  3762 	return $creation_date;
  3748 	return $creation_date;