diff -r 7b1b88e27a20 -r 48c4eec2b7e6 wp/wp-admin/includes/media.php
--- a/wp/wp-admin/includes/media.php Thu Sep 29 08:06:27 2022 +0200
+++ b/wp/wp-admin/includes/media.php Fri Sep 05 18:40:08 2025 +0200
@@ -145,7 +145,7 @@
}
if ( $url ) {
- $html = '' . $html . ' ';
+ $html = '' . $html . ' ';
}
/**
@@ -254,6 +254,9 @@
*
* @access private
* @since 3.4.0
+ *
+ * @param array $matches Single regex match.
+ * @return string Cleaned up HTML for caption.
*/
function _cleanup_image_add_caption( $matches ) {
// Remove any line breaks from inside the tags.
@@ -385,7 +388,7 @@
}
// Use image exif/iptc data for title and caption defaults if possible.
- } elseif ( 0 === strpos( $type, 'image/' ) ) {
+ } elseif ( str_starts_with( $type, 'image/' ) ) {
$image_meta = wp_read_image_metadata( $file );
if ( $image_meta ) {
@@ -419,14 +422,18 @@
$attachment_id = wp_insert_attachment( $attachment, $file, $post_id, true );
if ( ! is_wp_error( $attachment_id ) ) {
- // Set a custom header with the attachment_id.
- // Used by the browser/client to resume creating image sub-sizes after a PHP fatal error.
+ /*
+ * Set a custom header with the attachment_id.
+ * Used by the browser/client to resume creating image sub-sizes after a PHP fatal error.
+ */
if ( ! headers_sent() ) {
header( 'X-WP-Upload-Attachment-ID: ' . $attachment_id );
}
- // The image sub-sizes are created during wp_generate_attachment_metadata().
- // This is generally slow and may cause timeouts or out of memory errors.
+ /*
+ * The image sub-sizes are created during wp_generate_attachment_metadata().
+ * This is generally slow and may cause timeouts or out of memory errors.
+ */
wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file ) );
}
@@ -520,12 +527,14 @@
* @since 5.3.0 Formalized the existing and already documented `...$args` parameter
* by adding it to the function signature.
*
- * @global int $body_id
+ * @global string $body_id
*
* @param callable $content_func Function that outputs the content.
* @param mixed ...$args Optional additional parameters to pass to the callback function when it's called.
*/
function wp_iframe( $content_func, ...$args ) {
+ global $body_id;
+
_wp_admin_html_begin();
?>
› —
@@ -534,8 +543,8 @@
wp_enqueue_style( 'colors' );
// Check callback name for 'media'.
if (
- ( is_array( $content_func ) && ! empty( $content_func[1] ) && 0 === strpos( (string) $content_func[1], 'media' ) ) ||
- ( ! is_array( $content_func ) && 0 === strpos( $content_func, 'media' ) )
+ ( is_array( $content_func ) && ! empty( $content_func[1] ) && str_starts_with( (string) $content_func[1], 'media' ) ) ||
+ ( ! is_array( $content_func ) && str_starts_with( $content_func, 'media' ) )
) {
wp_enqueue_style( 'deprecated-media' );
}
@@ -596,8 +605,8 @@
$body_id_attr = '';
- if ( isset( $GLOBALS['body_id'] ) ) {
- $body_id_attr = ' id="' . $GLOBALS['body_id'] . '"';
+ if ( isset( $body_id ) ) {
+ $body_id_attr = ' id="' . $body_id . '"';
}
?>
@@ -631,7 +640,7 @@
*/
function media_buttons( $editor_id = 'content' ) {
static $instance = 0;
- $instance++;
+ ++$instance;
$post = get_post();
@@ -674,11 +683,16 @@
}
/**
+ * Retrieves the upload iframe source URL.
+ *
+ * @since 3.0.0
+ *
* @global int $post_ID
- * @param string $type
- * @param int $post_id
- * @param string $tab
- * @return string
+ *
+ * @param string $type Media type.
+ * @param int $post_id Post ID.
+ * @param string $tab Media upload tab.
+ * @return string Upload iframe source URL.
*/
function get_upload_iframe_src( $type = null, $post_id = null, $tab = null ) {
global $post_ID;
@@ -823,7 +837,7 @@
if ( ! empty( $attachment['url'] ) ) {
$rel = '';
- if ( strpos( $attachment['url'], 'attachment_id' ) || get_attachment_link( $send_id ) == $attachment['url'] ) {
+ if ( str_contains( $attachment['url'], 'attachment_id' ) || get_attachment_link( $send_id ) === $attachment['url'] ) {
$rel = " rel='attachment wp-att-" . esc_attr( $send_id ) . "'";
}
@@ -917,7 +931,7 @@
* @param string $src Media source URL.
* @param string $title Media title.
*/
- $html = apply_filters( "{$type}_send_to_editor_url", $html, esc_url_raw( $src ), $title );
+ $html = apply_filters( "{$type}_send_to_editor_url", $html, sanitize_url( $src ), $title );
} else {
$align = '';
$alt = esc_attr( wp_unslash( $_POST['alt'] ) );
@@ -942,7 +956,7 @@
* @param string $align The image alignment. Default 'alignnone'. Possible values include
* 'alignleft', 'aligncenter', 'alignright', 'alignnone'.
*/
- $html = apply_filters( 'image_send_to_editor_url', $html, esc_url_raw( $src ), $alt, $align );
+ $html = apply_filters( 'image_send_to_editor_url', $html, sanitize_url( $src ), $alt, $align );
}
return media_send_to_editor( $html );
@@ -988,6 +1002,7 @@
* @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.
+ * @since 5.8.0 Added 'webp' to the default list of allowed file extensions.
*
* @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.
@@ -1012,8 +1027,10 @@
* - `jpe`
* - `png`
* - `gif`
+ * - `webp`
*
* @since 5.6.0
+ * @since 5.8.0 Added 'webp' to the default list of allowed file extensions.
*
* @param string[] $allowed_extensions Array of allowed file extensions.
* @param string $file The URL of the image to download.
@@ -1150,16 +1167,16 @@
$checked = 'none';
}
- $out = array();
+ $output = array();
foreach ( $alignments as $name => $label ) {
- $name = esc_attr( $name );
- $out[] = "$label ";
}
- return implode( "\n", $out );
+ return implode( "\n", $output );
}
/**
@@ -1194,7 +1211,7 @@
$check = get_user_setting( 'imgsize', 'medium' );
}
- $out = array();
+ $output = array();
foreach ( $size_names as $size => $label ) {
$downsize = image_downsize( $post->ID, $size );
@@ -1230,13 +1247,13 @@
}
$html .= '';
- $out[] = $html;
+ $output[] = $html;
}
return array(
'label' => __( 'Size' ),
'input' => 'html',
- 'html' => implode( "\n", $out ),
+ 'html' => implode( "\n", $output ),
);
}
@@ -1269,8 +1286,8 @@
return "
" . __( 'None' ) . "
- " . __( 'File URL' ) . "
- " . __( 'Attachment Post URL' ) . '
+ " . __( 'File URL' ) . "
+ " . __( 'Attachment Post URL' ) . '
';
}
@@ -1343,12 +1360,12 @@
function image_media_send_to_editor( $html, $attachment_id, $attachment ) {
$post = get_post( $attachment_id );
- if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) {
+ if ( str_starts_with( $post->post_mime_type, 'image' ) ) {
$url = $attachment['url'];
$align = ! empty( $attachment['align'] ) ? $attachment['align'] : 'none';
$size = ! empty( $attachment['image-size'] ) ? $attachment['image-size'] : 'medium';
$alt = ! empty( $attachment['image_alt'] ) ? $attachment['image_alt'] : '';
- $rel = ( strpos( $url, 'attachment_id' ) || get_attachment_link( $attachment_id ) === $url );
+ $rel = ( str_contains( $url, 'attachment_id' ) || get_attachment_link( $attachment_id ) === $url );
return get_image_send_to_editor( $attachment_id, $attachment['post_excerpt'], $attachment['post_title'], $align, $url, $rel, $size, $alt );
}
@@ -1454,7 +1471,7 @@
$form_fields = array_merge_recursive( $form_fields, (array) $errors );
// This was formerly in image_attachment_fields_to_edit().
- if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) {
+ if ( str_starts_with( $post->post_mime_type, 'image' ) ) {
$alt = get_post_meta( $post->ID, '_wp_attachment_image_alt', true );
if ( empty( $alt ) ) {
@@ -1647,7 +1664,8 @@
$meta = wp_get_attachment_metadata( $post->ID );
if ( isset( $meta['width'], $meta['height'] ) ) {
- $media_dims .= "{$meta['width']} × {$meta['height']} ";
+ /* translators: 1: A number of pixels wide, 2: A number of pixels tall. */
+ $media_dims .= "" . sprintf( __( '%1$s by %2$s pixels' ), $meta['width'], $meta['height'] ) . ' ';
}
/**
@@ -1698,8 +1716,7 @@
\n
\n
" .
- /* translators: %s: Asterisk symbol (*). */
- sprintf( __( 'Required fields are marked %s' ), '* ' ) .
+ wp_required_field_message() .
"
\n";
$defaults = array(
@@ -1779,7 +1796,7 @@
continue;
}
- $required = $field['required'] ? '* ' : '';
+ $required = $field['required'] ? ' ' . wp_required_field_indicator() : '';
$required_attr = $field['required'] ? ' required' : '';
$class = $id;
$class .= $field['required'] ? ' form-required' : '';
@@ -1970,7 +1987,7 @@
}
$readonly = ! $user_can_edit && ! empty( $field['taxonomy'] ) ? " readonly='readonly' " : '';
- $required = $field['required'] ? '* ' : '';
+ $required = $field['required'] ? ' ' . wp_required_field_indicator() : '';
$required_attr = $field['required'] ? ' required' : '';
$class = 'compat-field-' . $id;
$class .= $field['required'] ? ' form-required' : '';
@@ -2026,8 +2043,7 @@
if ( $item ) {
$item = '' .
- /* translators: %s: Asterisk symbol (*). */
- sprintf( __( 'Required fields are marked %s' ), '* ' ) .
+ wp_required_field_message() .
'
' .
'';
}
@@ -2070,13 +2086,11 @@
*
* @global string $type
* @global string $tab
- * @global bool $is_IE
- * @global bool $is_opera
*
* @param array $errors
*/
function media_upload_form( $errors = null ) {
- global $type, $tab, $is_IE, $is_opera;
+ global $type, $tab;
if ( ! _device_can_upload() ) {
echo '' . sprintf(
@@ -2174,8 +2188,8 @@
*/
if (
wp_is_mobile() &&
- strpos( $_SERVER['HTTP_USER_AGENT'], 'OS 7_' ) !== false &&
- strpos( $_SERVER['HTTP_USER_AGENT'], 'like Mac OS X' ) !== false
+ str_contains( $_SERVER['HTTP_USER_AGENT'], 'OS 7_' ) &&
+ str_contains( $_SERVER['HTTP_USER_AGENT'], 'like Mac OS X' )
) {
$plupload_init['multi_selection'] = false;
}
@@ -2185,6 +2199,11 @@
$plupload_init['webp_upload_error'] = true;
}
+ // Check if AVIF images can be edited.
+ if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/avif' ) ) ) {
+ $plupload_init['avif_upload_error'] = true;
+ }
+
/**
* Filters the default Plupload settings.
*
@@ -2255,7 +2274,12 @@
?>
-
+
+
+
@@ -2723,7 +2747,12 @@
- :
+
+
+
@@ -2804,7 +2833,7 @@
'format' => '',
'prev_text' => __( '«' ),
'next_text' => __( '»' ),
- 'total' => ceil( $wp_query->found_posts / 10 ),
+ 'total' => (int) ceil( $wp_query->found_posts / 10 ),
'current' => $q['paged'],
)
);
@@ -2924,13 +2953,12 @@
return '
' . __( 'Image' ) . ' ' . __( 'Audio, Video, or Other File' ) . '
' .
- /* translators: %s: Asterisk symbol (*). */
- sprintf( __( 'Required fields are marked %s' ), '* ' ) .
+ wp_required_field_message() .
'
- ' . __( 'URL' ) . ' *
+ ' . __( 'URL' ) . ' ' . wp_required_field_indicator() . '
@@ -2938,7 +2966,7 @@
- ' . __( 'Title' ) . ' *
+ ' . __( 'Title' ) . ' ' . wp_required_field_indicator() . '
@@ -2947,7 +2975,7 @@
- ' . __( 'Alternative Text' ) . '
+ ' . __( 'Alternative Text' ) . ' ' . wp_required_field_indicator() . '
' . __( 'Alt text for the image, e.g. “The Mona Lisa”' ) . '
@@ -3202,10 +3230,10 @@
?>
+
@@ -3411,6 +3451,9 @@
echo ' ' . strtoupper( esc_html( $meta['bitrate_mode'] ) );
}
break;
+ case 'length_formatted':
+ echo human_readable_duration( $meta['length_formatted'] );
+ break;
default:
echo esc_html( $meta[ $key ] );
break;
@@ -3464,10 +3507,10 @@
if ( ! empty( $meta['original_image'] ) ) {
?>
-