diff -r be944660c56a -r 3d72ae0968f4 wp/wp-admin/includes/media.php --- a/wp/wp-admin/includes/media.php Wed Sep 21 18:19:35 2022 +0200 +++ b/wp/wp-admin/includes/media.php Tue Sep 27 16:37:53 2022 +0200 @@ -7,7 +7,7 @@ */ /** - * Defines the default media upload tabs + * Defines the default media upload tabs. * * @since 2.5.0 * @@ -32,7 +32,7 @@ } /** - * Adds the gallery tab back to the tabs array if post has image attachments + * Adds the gallery tab back to the tabs array if post has image attachments. * * @since 2.5.0 * @@ -282,7 +282,7 @@ * * @since 2.5.0 * - * @param string $file_id Index of the `$_FILES` array that the file was sent. Required. + * @param string $file_id Index of the `$_FILES` array that the file was sent. * @param int $post_id The post ID of a post to attach the media item to. Required, but can * be set to 0, creating a media item that has no relationship to a post. * @param array $post_data Optional. Overwrite some of the attachment. @@ -361,12 +361,21 @@ if ( ! empty( $meta['track_number'] ) ) { $track_number = explode( '/', $meta['track_number'] ); - if ( isset( $track_number[1] ) ) { - /* translators: Audio file track information. 1: Audio track number, 2: Total audio tracks. */ - $content .= ' ' . sprintf( __( 'Track %1$s of %2$s.' ), number_format_i18n( $track_number[0] ), number_format_i18n( $track_number[1] ) ); - } else { - /* translators: Audio file track information. %s: Audio track number. */ - $content .= ' ' . sprintf( __( 'Track %s.' ), number_format_i18n( $track_number[0] ) ); + if ( is_numeric( $track_number[0] ) ) { + if ( isset( $track_number[1] ) && is_numeric( $track_number[1] ) ) { + $content .= ' ' . sprintf( + /* translators: Audio file track information. 1: Audio track number, 2: Total audio tracks. */ + __( 'Track %1$s of %2$s.' ), + number_format_i18n( $track_number[0] ), + number_format_i18n( $track_number[1] ) + ); + } else { + $content .= ' ' . sprintf( + /* translators: Audio file track information. %s: Audio track number. */ + __( 'Track %s.' ), + number_format_i18n( $track_number[0] ) + ); + } } } @@ -533,7 +542,7 @@ ?> @@ -577,10 +586,8 @@ * Fires in the admin header for each specific form tab in the legacy * (pre-3.5.0) media upload popup. * - * The dynamic portion of the hook, `$content_func`, refers to the form - * callback for the media upload type. Possible values include - * 'media_upload_type_form', 'media_upload_type_url_form', and - * 'media_upload_library_form'. + * The dynamic portion of the hook name, `$content_func`, refers to the form + * callback for the media upload type. * * @since 2.5.0 */ @@ -614,7 +621,7 @@ } /** - * Adds the media button to the editor + * Adds the media button to the editor. * * @since 2.5.0 * @@ -715,7 +722,7 @@ * * @since 2.5.0 * - * @return mixed void|object WP_Error on failure + * @return null|array|void Array of error messages keyed by attachment ID, null or void on success. */ function media_upload_form_handler() { check_admin_referer( 'media-form' ); @@ -976,21 +983,21 @@ * Downloads an image from the specified URL, saves it as an attachment, and optionally attaches it to a post. * * @since 2.6.0 - * @since 4.2.0 Introduced the `$return` parameter. - * @since 4.8.0 Introduced the 'id' option for the `$return` parameter. + * @since 4.2.0 Introduced the `$return_type` parameter. + * @since 4.8.0 Introduced the 'id' option for the `$return_type` parameter. * @since 5.3.0 The `$post_id` parameter was made optional. * @since 5.4.0 The original URL of the attachment is stored in the `_source_url` * post meta value. * - * @param string $file The URL of the image to download. - * @param int $post_id Optional. The post ID the media is to be associated with. - * @param string $desc Optional. Description of the image. - * @param string $return Optional. Accepts 'html' (image tag html) or 'src' (URL), - * or 'id' (attachment ID). Default 'html'. + * @param string $file The URL of the image to download. + * @param int $post_id Optional. The post ID the media is to be associated with. + * @param string $desc Optional. Description of the image. + * @param string $return_type Optional. Accepts 'html' (image tag html) or 'src' (URL), + * or 'id' (attachment ID). Default 'html'. * @return string|int|WP_Error Populated HTML img tag, attachment ID, or attachment source * on success, WP_Error object otherwise. */ -function media_sideload_image( $file, $post_id = 0, $desc = null, $return = 'html' ) { +function media_sideload_image( $file, $post_id = 0, $desc = null, $return_type = 'html' ) { if ( ! empty( $file ) ) { $allowed_extensions = array( 'jpg', 'jpeg', 'jpe', 'png', 'gif', 'webp' ); @@ -1045,7 +1052,7 @@ add_post_meta( $id, '_source_url', $file ); // If attachment ID was requested, return it. - if ( 'id' === $return ) { + if ( 'id' === $return_type ) { return $id; } @@ -1054,7 +1061,7 @@ // Finally, check to make sure the file has been saved, then return the HTML. if ( ! empty( $src ) ) { - if ( 'src' === $return ) { + if ( 'src' === $return_type ) { return $src; } @@ -1118,7 +1125,7 @@ } /** - * Retrieve HTML for the image alignment radio buttons with the specified one checked. + * Retrieves HTML for the image alignment radio buttons with the specified one checked. * * @since 2.7.0 * @@ -1156,7 +1163,7 @@ } /** - * Retrieve HTML for the size radio buttons with the specified one checked. + * Retrieves HTML for the size radio buttons with the specified one checked. * * @since 2.7.0 * @@ -1234,7 +1241,7 @@ } /** - * Retrieve HTML for the Link URL buttons with the default link type as specified. + * Retrieves HTML for the Link URL buttons with the default link type as specified. * * @since 2.7.0 * @@ -1268,7 +1275,7 @@ } /** - * Output a textarea element for inputting an attachment caption. + * Outputs a textarea element for inputting an attachment caption. * * @since 3.4.0 * @@ -1324,31 +1331,6 @@ } /** - * Filters input from media_upload_form_handler() and assigns a default - * post_title from the file name if none supplied. - * - * Illustrates the use of the {@see 'attachment_fields_to_save'} filter - * which can be used to add default values to any field before saving to DB. - * - * @since 2.5.0 - * - * @param array $post The WP_Post attachment object converted to an array. - * @param array $attachment An array of attachment metadata. - * @return array Filtered attachment post object. - */ -function image_attachment_fields_to_save( $post, $attachment ) { - if ( 'image' === substr( $post['post_mime_type'], 0, 5 ) ) { - if ( strlen( trim( $post['post_title'] ) ) == 0 ) { - $attachment_url = ( isset( $post['attachment_url'] ) ) ? $post['attachment_url'] : $post['guid']; - $post['post_title'] = preg_replace( '/\.\w+$/', '', wp_basename( $attachment_url ) ); - $post['errors']['post_title']['errors'][] = __( 'Empty Title filled from filename.' ); - } - } - - return $post; -} - -/** * Retrieves the media element HTML to send to the editor. * * @since 2.5.0 @@ -1513,7 +1495,7 @@ } /** - * Retrieve HTML for media items of post gallery. + * Retrieves HTML for media items of post gallery. * * The HTML markup retrieved will be created for the progress of SWF Upload * component. Will also create link for showing and hiding the form to modify @@ -1523,9 +1505,9 @@ * * @global WP_Query $wp_the_query WordPress Query object. * - * @param int $post_id Optional. Post ID. + * @param int $post_id Post ID. * @param array $errors Errors for attachment, if any. - * @return string + * @return string HTML content for media items of post gallery. */ function get_media_items( $post_id, $errors ) { $attachments = array(); @@ -1570,7 +1552,7 @@ } /** - * Retrieve HTML form for modifying the image attachment. + * Retrieves HTML form for modifying the image attachment. * * @since 2.5.0 * @@ -2503,11 +2485,11 @@ } }; - jQuery(document).ready( function($) { + jQuery( function($) { $('.media-types input').click( function() { $('table.describe').toggleClass('not-image', $('#not-image').prop('checked') ); }); - }); + } );
@@ -2530,7 +2512,7 @@ } /** - * Adds gallery form to upload iframe + * Adds gallery form to upload iframe. * * @since 2.5.0 * @@ -2579,7 +2561,6 @@