wp/wp-admin/includes/media.php
changeset 18 be944660c56a
parent 16 a86126ab1dd4
child 19 3d72ae0968f4
equal deleted inserted replaced
17:34716fd837a4 18:be944660c56a
    47 	if ( ! isset( $_REQUEST['post_id'] ) ) {
    47 	if ( ! isset( $_REQUEST['post_id'] ) ) {
    48 		unset( $tabs['gallery'] );
    48 		unset( $tabs['gallery'] );
    49 		return $tabs;
    49 		return $tabs;
    50 	}
    50 	}
    51 
    51 
    52 	$post_id = intval( $_REQUEST['post_id'] );
    52 	$post_id = (int) $_REQUEST['post_id'];
    53 
    53 
    54 	if ( $post_id ) {
    54 	if ( $post_id ) {
    55 		$attachments = intval( $wpdb->get_var( $wpdb->prepare( "SELECT count(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent = %d", $post_id ) ) );
    55 		$attachments = (int) $wpdb->get_var( $wpdb->prepare( "SELECT count(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent = %d", $post_id ) );
    56 	}
    56 	}
    57 
    57 
    58 	if ( empty( $attachments ) ) {
    58 	if ( empty( $attachments ) ) {
    59 		unset( $tabs['gallery'] );
    59 		unset( $tabs['gallery'] );
    60 		return $tabs;
    60 		return $tabs;
   123  * @param string       $caption Image caption.
   123  * @param string       $caption Image caption.
   124  * @param string       $title   Image title attribute.
   124  * @param string       $title   Image title attribute.
   125  * @param string       $align   Image CSS alignment property.
   125  * @param string       $align   Image CSS alignment property.
   126  * @param string       $url     Optional. Image src URL. Default empty.
   126  * @param string       $url     Optional. Image src URL. Default empty.
   127  * @param bool|string  $rel     Optional. Value for rel attribute or whether to add a default value. Default false.
   127  * @param bool|string  $rel     Optional. Value for rel attribute or whether to add a default value. Default false.
   128  * @param string|array $size    Optional. Image size. Accepts any valid image size, or an array of width
   128  * @param string|int[] $size    Optional. Image size. Accepts any registered image size name, or an array of
   129  *                              and height values in pixels (in that order). Default 'medium'.
   129  *                              width and height values in pixels (in that order). Default 'medium'.
   130  * @param string       $alt     Optional. Image alt attribute. Default empty.
   130  * @param string       $alt     Optional. Image alt attribute. Default empty.
   131  * @return string The HTML output to insert into the editor.
   131  * @return string The HTML output to insert into the editor.
   132  */
   132  */
   133 function get_image_send_to_editor( $id, $caption, $title, $align, $url = '', $rel = false, $size = 'medium', $alt = '' ) {
   133 function get_image_send_to_editor( $id, $caption, $title, $align, $url = '', $rel = false, $size = 'medium', $alt = '' ) {
   134 
   134 
   136 
   136 
   137 	if ( $rel ) {
   137 	if ( $rel ) {
   138 		if ( is_string( $rel ) ) {
   138 		if ( is_string( $rel ) ) {
   139 			$rel = ' rel="' . esc_attr( $rel ) . '"';
   139 			$rel = ' rel="' . esc_attr( $rel ) . '"';
   140 		} else {
   140 		} else {
   141 			$rel = ' rel="attachment wp-att-' . intval( $id ) . '"';
   141 			$rel = ' rel="attachment wp-att-' . (int) $id . '"';
   142 		}
   142 		}
   143 	} else {
   143 	} else {
   144 		$rel = '';
   144 		$rel = '';
   145 	}
   145 	}
   146 
   146 
   150 
   150 
   151 	/**
   151 	/**
   152 	 * Filters the image HTML markup to send to the editor when inserting an image.
   152 	 * Filters the image HTML markup to send to the editor when inserting an image.
   153 	 *
   153 	 *
   154 	 * @since 2.5.0
   154 	 * @since 2.5.0
       
   155 	 * @since 5.6.0 The `$rel` parameter was added.
   155 	 *
   156 	 *
   156 	 * @param string       $html    The image HTML markup to send.
   157 	 * @param string       $html    The image HTML markup to send.
   157 	 * @param int          $id      The attachment ID.
   158 	 * @param int          $id      The attachment ID.
   158 	 * @param string       $caption The image caption.
   159 	 * @param string       $caption The image caption.
   159 	 * @param string       $title   The image title.
   160 	 * @param string       $title   The image title.
   160 	 * @param string       $align   The image alignment.
   161 	 * @param string       $align   The image alignment.
   161 	 * @param string       $url     The image source URL.
   162 	 * @param string       $url     The image source URL.
   162 	 * @param string|array $size    Size of image. Image size or array of width and height values
   163 	 * @param string|int[] $size    Requested image size. Can be any registered image size name, or
   163 	 *                              (in that order). Default 'medium'.
   164 	 *                              an array of width and height values in pixels (in that order).
   164 	 * @param string       $alt     The image alternative, or alt, text.
   165 	 * @param string       $alt     The image alternative, or alt, text.
       
   166 	 * @param string       $rel     The image rel attribute.
   165 	 */
   167 	 */
   166 	$html = apply_filters( 'image_send_to_editor', $html, $id, $caption, $title, $align, $url, $size, $alt );
   168 	$html = apply_filters( 'image_send_to_editor', $html, $id, $caption, $title, $align, $url, $size, $alt, $rel );
   167 
   169 
   168 	return $html;
   170 	return $html;
   169 }
   171 }
   170 
   172 
   171 /**
   173 /**
   172  * Adds image shortcode with caption to editor.
   174  * Adds image shortcode with caption to editor.
   173  *
   175  *
   174  * @since 2.6.0
   176  * @since 2.6.0
   175  *
   177  *
   176  * @param string  $html    The image HTML markup to send.
   178  * @param string  $html    The image HTML markup to send.
   177  * @param integer $id      Image attachment ID.
   179  * @param int     $id      Image attachment ID.
   178  * @param string  $caption Image caption.
   180  * @param string  $caption Image caption.
   179  * @param string  $title   Image title attribute (not used).
   181  * @param string  $title   Image title attribute (not used).
   180  * @param string  $align   Image CSS alignment property.
   182  * @param string  $align   Image CSS alignment property.
   181  * @param string  $url     Image source URL (not used).
   183  * @param string  $url     Image source URL (not used).
   182  * @param string  $size    Image size (`thumbnail`, `medium`, `large`, `full`, or added with `add_image_size()`) (not used).
   184  * @param string  $size    Image size (not used).
   183  * @param string  $alt     Image `alt` attribute (not used).
   185  * @param string  $alt     Image `alt` attribute (not used).
   184  * @return string The image HTML markup with caption shortcode.
   186  * @return string The image HTML markup with caption shortcode.
   185  */
   187  */
   186 function image_add_caption( $html, $id, $caption, $title, $align, $url, $size, $alt = '' ) {
   188 function image_add_caption( $html, $id, $caption, $title, $align, $url, $size, $alt = '' ) {
   187 
   189 
   426  * Handles a side-loaded file in the same way as an uploaded file is handled by media_handle_upload().
   428  * Handles a side-loaded file in the same way as an uploaded file is handled by media_handle_upload().
   427  *
   429  *
   428  * @since 2.6.0
   430  * @since 2.6.0
   429  * @since 5.3.0 The `$post_id` parameter was made optional.
   431  * @since 5.3.0 The `$post_id` parameter was made optional.
   430  *
   432  *
   431  * @param array  $file_array Array similar to a `$_FILES` upload array.
   433  * @param string[] $file_array Array that represents a `$_FILES` upload array.
   432  * @param int    $post_id    Optional. The post ID the media is associated with.
   434  * @param int      $post_id    Optional. The post ID the media is associated with.
   433  * @param string $desc       Optional. Description of the side-loaded file. Default null.
   435  * @param string   $desc       Optional. Description of the side-loaded file. Default null.
   434  * @param array  $post_data  Optional. Post data to override. Default empty array.
   436  * @param array    $post_data  Optional. Post data to override. Default empty array.
   435  * @return int|WP_Error The ID of the attachment or a WP_Error on failure.
   437  * @return int|WP_Error The ID of the attachment or a WP_Error on failure.
   436  */
   438  */
   437 function media_handle_sideload( $file_array, $post_id = 0, $desc = null, $post_data = array() ) {
   439 function media_handle_sideload( $file_array, $post_id = 0, $desc = null, $post_data = array() ) {
   438 	$overrides = array( 'test_form' => false );
   440 	$overrides = array( 'test_form' => false );
   439 
   441 
   440 	$time = current_time( 'mysql' );
   442 	if ( isset( $post_data['post_date'] ) && substr( $post_data['post_date'], 0, 4 ) > 0 ) {
   441 	$post = get_post( $post_id );
   443 		$time = $post_data['post_date'];
   442 
   444 	} else {
   443 	if ( $post ) {
   445 		$post = get_post( $post_id );
   444 		if ( substr( $post->post_date, 0, 4 ) > 0 ) {
   446 		if ( $post && substr( $post->post_date, 0, 4 ) > 0 ) {
   445 			$time = $post->post_date;
   447 			$time = $post->post_date;
       
   448 		} else {
       
   449 			$time = current_time( 'mysql' );
   446 		}
   450 		}
   447 	}
   451 	}
   448 
   452 
   449 	$file = wp_handle_sideload( $file_array, $overrides, $time );
   453 	$file = wp_handle_sideload( $file_array, $overrides, $time );
   450 
   454 
   527 		wp_enqueue_style( 'deprecated-media' );
   531 		wp_enqueue_style( 'deprecated-media' );
   528 	}
   532 	}
   529 
   533 
   530 	?>
   534 	?>
   531 	<script type="text/javascript">
   535 	<script type="text/javascript">
   532 	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();}}};
   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();}}};
   533 	var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>', pagenow = 'media-upload-popup', adminpage = 'media-upload-popup',
   537 	var ajaxurl = '<?php echo esc_js( admin_url( 'admin-ajax.php', 'relative' ) ); ?>', pagenow = 'media-upload-popup', adminpage = 'media-upload-popup',
   534 	isRtl = <?php echo (int) is_rtl(); ?>;
   538 	isRtl = <?php echo (int) is_rtl(); ?>;
   535 	</script>
   539 	</script>
   536 	<?php
   540 	<?php
   537 	/** This action is documented in wp-admin/admin-header.php */
   541 	/** This action is documented in wp-admin/admin-header.php */
   538 	do_action( 'admin_enqueue_scripts', 'media-upload-popup' );
   542 	do_action( 'admin_enqueue_scripts', 'media-upload-popup' );
   601 
   605 
   602 	/** This action is documented in wp-admin/admin-footer.php */
   606 	/** This action is documented in wp-admin/admin-footer.php */
   603 	do_action( 'admin_print_footer_scripts' );
   607 	do_action( 'admin_print_footer_scripts' );
   604 
   608 
   605 	?>
   609 	?>
   606 	<script type="text/javascript">if(typeof wpOnload=='function')wpOnload();</script>
   610 	<script type="text/javascript">if(typeof wpOnload==='function')wpOnload();</script>
   607 	</body>
   611 	</body>
   608 	</html>
   612 	</html>
   609 	<?php
   613 	<?php
   610 }
   614 }
   611 
   615 
   690 	 * Filters the upload iframe source URL for a specific media type.
   694 	 * Filters the upload iframe source URL for a specific media type.
   691 	 *
   695 	 *
   692 	 * The dynamic portion of the hook name, `$type`, refers to the type
   696 	 * The dynamic portion of the hook name, `$type`, refers to the type
   693 	 * of media uploaded.
   697 	 * of media uploaded.
   694 	 *
   698 	 *
       
   699 	 * Possible hook names include:
       
   700 	 *
       
   701 	 *  - `image_upload_iframe_src`
       
   702 	 *  - `media_upload_iframe_src`
       
   703 	 *
   695 	 * @since 3.0.0
   704 	 * @since 3.0.0
   696 	 *
   705 	 *
   697 	 * @param string $upload_iframe_src The upload iframe source URL by type.
   706 	 * @param string $upload_iframe_src The upload iframe source URL.
   698 	 */
   707 	 */
   699 	$upload_iframe_src = apply_filters( "{$type}_upload_iframe_src", $upload_iframe_src );
   708 	$upload_iframe_src = apply_filters( "{$type}_upload_iframe_src", $upload_iframe_src );
   700 
   709 
   701 	return add_query_arg( 'TB_iframe', true, $upload_iframe_src );
   710 	return add_query_arg( 'TB_iframe', true, $upload_iframe_src );
   702 }
   711 }
   887 			 * Filters the URL sent to the editor for a specific media type.
   896 			 * Filters the URL sent to the editor for a specific media type.
   888 			 *
   897 			 *
   889 			 * The dynamic portion of the hook name, `$type`, refers to the type
   898 			 * The dynamic portion of the hook name, `$type`, refers to the type
   890 			 * of media being sent.
   899 			 * of media being sent.
   891 			 *
   900 			 *
       
   901 			 * Possible hook names include:
       
   902 			 *
       
   903 			 *  - `audio_send_to_editor_url`
       
   904 			 *  - `file_send_to_editor_url`
       
   905 			 *  - `video_send_to_editor_url`
       
   906 			 *
   892 			 * @since 3.3.0
   907 			 * @since 3.3.0
   893 			 *
   908 			 *
   894 			 * @param string $html  HTML markup sent to the editor.
   909 			 * @param string $html  HTML markup sent to the editor.
   895 			 * @param string $src   Media source URL.
   910 			 * @param string $src   Media source URL.
   896 			 * @param string $title Media title.
   911 			 * @param string $title Media title.
   956 
   971 
   957 	return wp_iframe( 'media_upload_type_form', 'image', $errors, $id );
   972 	return wp_iframe( 'media_upload_type_form', 'image', $errors, $id );
   958 }
   973 }
   959 
   974 
   960 /**
   975 /**
   961  * Downloads an image from the specified URL and attaches it to a post.
   976  * Downloads an image from the specified URL, saves it as an attachment, and optionally attaches it to a post.
   962  *
   977  *
   963  * @since 2.6.0
   978  * @since 2.6.0
   964  * @since 4.2.0 Introduced the `$return` parameter.
   979  * @since 4.2.0 Introduced the `$return` parameter.
   965  * @since 4.8.0 Introduced the 'id' option within the `$return` parameter.
   980  * @since 4.8.0 Introduced the 'id' option for the `$return` parameter.
   966  * @since 5.3.0 The `$post_id` parameter was made optional.
   981  * @since 5.3.0 The `$post_id` parameter was made optional.
   967  * @since 5.4.0 The original URL of the attachment is stored in the `_source_url`
   982  * @since 5.4.0 The original URL of the attachment is stored in the `_source_url`
   968  *              post meta value.
   983  *              post meta value.
   969  *
   984  *
   970  * @param string $file    The URL of the image to download.
   985  * @param string $file    The URL of the image to download.
   971  * @param int    $post_id Optional. The post ID the media is to be associated with.
   986  * @param int    $post_id Optional. The post ID the media is to be associated with.
   972  * @param string $desc    Optional. Description of the image.
   987  * @param string $desc    Optional. Description of the image.
   973  * @param string $return  Optional. Accepts 'html' (image tag html) or 'src' (URL),
   988  * @param string $return  Optional. Accepts 'html' (image tag html) or 'src' (URL),
   974  *                        or 'id' (attachment ID). Default 'html'.
   989  *                        or 'id' (attachment ID). Default 'html'.
   975  * @return string|WP_Error Populated HTML img tag on success, WP_Error object otherwise.
   990  * @return string|int|WP_Error Populated HTML img tag, attachment ID, or attachment source
       
   991  *                             on success, WP_Error object otherwise.
   976  */
   992  */
   977 function media_sideload_image( $file, $post_id = 0, $desc = null, $return = 'html' ) {
   993 function media_sideload_image( $file, $post_id = 0, $desc = null, $return = 'html' ) {
   978 	if ( ! empty( $file ) ) {
   994 	if ( ! empty( $file ) ) {
   979 
   995 
       
   996 		$allowed_extensions = array( 'jpg', 'jpeg', 'jpe', 'png', 'gif', 'webp' );
       
   997 
       
   998 		/**
       
   999 		 * Filters the list of allowed file extensions when sideloading an image from a URL.
       
  1000 		 *
       
  1001 		 * The default allowed extensions are:
       
  1002 		 *
       
  1003 		 *  - `jpg`
       
  1004 		 *  - `jpeg`
       
  1005 		 *  - `jpe`
       
  1006 		 *  - `png`
       
  1007 		 *  - `gif`
       
  1008 		 *
       
  1009 		 * @since 5.6.0
       
  1010 		 *
       
  1011 		 * @param string[] $allowed_extensions Array of allowed file extensions.
       
  1012 		 * @param string   $file               The URL of the image to download.
       
  1013 		 */
       
  1014 		$allowed_extensions = apply_filters( 'image_sideload_extensions', $allowed_extensions, $file );
       
  1015 		$allowed_extensions = array_map( 'preg_quote', $allowed_extensions );
       
  1016 
   980 		// Set variables for storage, fix file filename for query strings.
  1017 		// Set variables for storage, fix file filename for query strings.
   981 		preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches );
  1018 		preg_match( '/[^\?]+\.(' . implode( '|', $allowed_extensions ) . ')\b/i', $file, $matches );
   982 
  1019 
   983 		if ( ! $matches ) {
  1020 		if ( ! $matches ) {
   984 			return new WP_Error( 'image_sideload_failed', __( 'Invalid image URL.' ) );
  1021 			return new WP_Error( 'image_sideload_failed', __( 'Invalid image URL.' ) );
   985 		}
  1022 		}
   986 
  1023 
  1113 		$out[] = "<input type='radio' name='attachments[{$post->ID}][align]' id='image-align-{$name}-{$post->ID}' value='$name'" .
  1150 		$out[] = "<input type='radio' name='attachments[{$post->ID}][align]' id='image-align-{$name}-{$post->ID}' value='$name'" .
  1114 			( $checked == $name ? " checked='checked'" : '' ) .
  1151 			( $checked == $name ? " checked='checked'" : '' ) .
  1115 			" /><label for='image-align-{$name}-{$post->ID}' class='align image-align-{$name}-label'>$label</label>";
  1152 			" /><label for='image-align-{$name}-{$post->ID}' class='align image-align-{$name}-label'>$label</label>";
  1116 	}
  1153 	}
  1117 
  1154 
  1118 	return join( "\n", $out );
  1155 	return implode( "\n", $out );
  1119 }
  1156 }
  1120 
  1157 
  1121 /**
  1158 /**
  1122  * Retrieve HTML for the size radio buttons with the specified one checked.
  1159  * Retrieve HTML for the size radio buttons with the specified one checked.
  1123  *
  1160  *
  1190 	}
  1227 	}
  1191 
  1228 
  1192 	return array(
  1229 	return array(
  1193 		'label' => __( 'Size' ),
  1230 		'label' => __( 'Size' ),
  1194 		'input' => 'html',
  1231 		'input' => 'html',
  1195 		'html'  => join( "\n", $out ),
  1232 		'html'  => implode( "\n", $out ),
  1196 	);
  1233 	);
  1197 }
  1234 }
  1198 
  1235 
  1199 /**
  1236 /**
  1200  * Retrieve HTML for the Link URL buttons with the default link type as specified.
  1237  * Retrieve HTML for the Link URL buttons with the default link type as specified.
  1315  * Retrieves the media element HTML to send to the editor.
  1352  * Retrieves the media element HTML to send to the editor.
  1316  *
  1353  *
  1317  * @since 2.5.0
  1354  * @since 2.5.0
  1318  *
  1355  *
  1319  * @param string  $html
  1356  * @param string  $html
  1320  * @param integer $attachment_id
  1357  * @param int     $attachment_id
  1321  * @param array   $attachment
  1358  * @param array   $attachment
  1322  * @return string
  1359  * @return string
  1323  */
  1360  */
  1324 function image_media_send_to_editor( $html, $attachment_id, $attachment ) {
  1361 function image_media_send_to_editor( $html, $attachment_id, $attachment ) {
  1325 	$post = get_post( $attachment_id );
  1362 	$post = get_post( $attachment_id );
  1419 
  1456 
  1420 		foreach ( $terms as $term ) {
  1457 		foreach ( $terms as $term ) {
  1421 			$values[] = $term->slug;
  1458 			$values[] = $term->slug;
  1422 		}
  1459 		}
  1423 
  1460 
  1424 		$t['value'] = join( ', ', $values );
  1461 		$t['value'] = implode( ', ', $values );
  1425 
  1462 
  1426 		$form_fields[ $taxonomy ] = $t;
  1463 		$form_fields[ $taxonomy ] = $t;
  1427 	}
  1464 	}
  1428 
  1465 
  1429 	/*
  1466 	/*
  1545  */
  1582  */
  1546 function get_media_item( $attachment_id, $args = null ) {
  1583 function get_media_item( $attachment_id, $args = null ) {
  1547 	global $redir_tab;
  1584 	global $redir_tab;
  1548 
  1585 
  1549 	$thumb_url     = false;
  1586 	$thumb_url     = false;
  1550 	$attachment_id = intval( $attachment_id );
  1587 	$attachment_id = (int) $attachment_id;
  1551 
  1588 
  1552 	if ( $attachment_id ) {
  1589 	if ( $attachment_id ) {
  1553 		$thumb_url = wp_get_attachment_image_src( $attachment_id, 'thumbnail', true );
  1590 		$thumb_url = wp_get_attachment_image_src( $attachment_id, 'thumbnail', true );
  1554 
  1591 
  1555 		if ( $thumb_url ) {
  1592 		if ( $thumb_url ) {
  1779 		} else {
  1816 		} else {
  1780 			$item .= "<input type='text' class='text' id='$name' name='$name' value='" . esc_attr( $field['value'] ) . "'{$required_attr} />";
  1817 			$item .= "<input type='text' class='text' id='$name' name='$name' value='" . esc_attr( $field['value'] ) . "'{$required_attr} />";
  1781 		}
  1818 		}
  1782 
  1819 
  1783 		if ( ! empty( $field['helps'] ) ) {
  1820 		if ( ! empty( $field['helps'] ) ) {
  1784 			$item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>';
  1821 			$item .= "<p class='help'>" . implode( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>';
  1785 		}
  1822 		}
  1786 		$item .= "</td>\n\t\t</tr>\n";
  1823 		$item .= "</td>\n\t\t</tr>\n";
  1787 
  1824 
  1788 		$extra_rows = array();
  1825 		$extra_rows = array();
  1789 
  1826 
  1878 
  1915 
  1879 			foreach ( $terms as $term ) {
  1916 			foreach ( $terms as $term ) {
  1880 				$values[] = $term->slug;
  1917 				$values[] = $term->slug;
  1881 			}
  1918 			}
  1882 
  1919 
  1883 			$t['value']    = join( ', ', $values );
  1920 			$t['value']    = implode( ', ', $values );
  1884 			$t['taxonomy'] = true;
  1921 			$t['taxonomy'] = true;
  1885 
  1922 
  1886 			$form_fields[ $taxonomy ] = $t;
  1923 			$form_fields[ $taxonomy ] = $t;
  1887 		}
  1924 		}
  1888 	}
  1925 	}
  1971 		} else {
  2008 		} else {
  1972 			$item .= "<input type='text' class='text' id='$id_attr' name='$name' value='" . esc_attr( $field['value'] ) . "' $readonly{$required_attr} />";
  2009 			$item .= "<input type='text' class='text' id='$id_attr' name='$name' value='" . esc_attr( $field['value'] ) . "' $readonly{$required_attr} />";
  1973 		}
  2010 		}
  1974 
  2011 
  1975 		if ( ! empty( $field['helps'] ) ) {
  2012 		if ( ! empty( $field['helps'] ) ) {
  1976 			$item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>';
  2013 			$item .= "<p class='help'>" . implode( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>';
  1977 		}
  2014 		}
  1978 
  2015 
  1979 		$item .= "</td>\n\t\t</tr>\n";
  2016 		$item .= "</td>\n\t\t</tr>\n";
  1980 
  2017 
  1981 		$extra_rows = array();
  2018 		$extra_rows = array();
  2031  * Outputs the legacy media upload header.
  2068  * Outputs the legacy media upload header.
  2032  *
  2069  *
  2033  * @since 2.5.0
  2070  * @since 2.5.0
  2034  */
  2071  */
  2035 function media_upload_header() {
  2072 function media_upload_header() {
  2036 	$post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0;
  2073 	$post_id = isset( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0;
  2037 
  2074 
  2038 	echo '<script type="text/javascript">post_id = ' . $post_id . ';</script>';
  2075 	echo '<script type="text/javascript">post_id = ' . $post_id . ';</script>';
  2039 
  2076 
  2040 	if ( empty( $_GET['chromeless'] ) ) {
  2077 	if ( empty( $_GET['chromeless'] ) ) {
  2041 		echo '<div id="media-upload-header">';
  2078 		echo '<div id="media-upload-header">';
  2067 		) . '</p>';
  2104 		) . '</p>';
  2068 		return;
  2105 		return;
  2069 	}
  2106 	}
  2070 
  2107 
  2071 	$upload_action_url = admin_url( 'async-upload.php' );
  2108 	$upload_action_url = admin_url( 'async-upload.php' );
  2072 	$post_id           = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0;
  2109 	$post_id           = isset( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0;
  2073 	$_type             = isset( $type ) ? $type : '';
  2110 	$_type             = isset( $type ) ? $type : '';
  2074 	$_tab              = isset( $tab ) ? $tab : '';
  2111 	$_tab              = isset( $tab ) ? $tab : '';
  2075 
  2112 
  2076 	$max_upload_size = wp_max_upload_size();
  2113 	$max_upload_size = wp_max_upload_size();
  2077 	if ( ! $max_upload_size ) {
  2114 	if ( ! $max_upload_size ) {
  2159 		strpos( $_SERVER['HTTP_USER_AGENT'], 'like Mac OS X' ) !== false
  2196 		strpos( $_SERVER['HTTP_USER_AGENT'], 'like Mac OS X' ) !== false
  2160 	) {
  2197 	) {
  2161 		$plupload_init['multi_selection'] = false;
  2198 		$plupload_init['multi_selection'] = false;
  2162 	}
  2199 	}
  2163 
  2200 
       
  2201 	// Check if WebP images can be edited.
       
  2202 	if ( ! wp_image_editor_supports( array( 'mime_type' => 'image/webp' ) ) ) {
       
  2203 		$plupload_init['webp_upload_error'] = true;
       
  2204 	}
       
  2205 
  2164 	/**
  2206 	/**
  2165 	 * Filters the default Plupload settings.
  2207 	 * Filters the default Plupload settings.
  2166 	 *
  2208 	 *
  2167 	 * @since 3.3.0
  2209 	 * @since 3.3.0
  2168 	 *
  2210 	 *
  2269 /**
  2311 /**
  2270  * Outputs the legacy media upload form for a given media type.
  2312  * Outputs the legacy media upload form for a given media type.
  2271  *
  2313  *
  2272  * @since 2.5.0
  2314  * @since 2.5.0
  2273  *
  2315  *
  2274  * @param string  $type
  2316  * @param string       $type
  2275  * @param object  $errors
  2317  * @param array        $errors
  2276  * @param integer $id
  2318  * @param int|WP_Error $id
  2277  */
  2319  */
  2278 function media_upload_type_form( $type = 'file', $errors = null, $id = null ) {
  2320 function media_upload_type_form( $type = 'file', $errors = null, $id = null ) {
  2279 
  2321 
  2280 	media_upload_header();
  2322 	media_upload_header();
  2281 
  2323 
  2282 	$post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0;
  2324 	$post_id = isset( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0;
  2283 
  2325 
  2284 	$form_action_url = admin_url( "media-upload.php?type=$type&tab=type&post_id=$post_id" );
  2326 	$form_action_url = admin_url( "media-upload.php?type=$type&tab=type&post_id=$post_id" );
  2285 
  2327 
  2286 	/**
  2328 	/**
  2287 	 * Filters the media upload form action URL.
  2329 	 * Filters the media upload form action URL.
  2345  *
  2387  *
  2346  * @since 2.7.0
  2388  * @since 2.7.0
  2347  *
  2389  *
  2348  * @param string  $type
  2390  * @param string  $type
  2349  * @param object  $errors
  2391  * @param object  $errors
  2350  * @param integer $id
  2392  * @param int     $id
  2351  */
  2393  */
  2352 function media_upload_type_url_form( $type = null, $errors = null, $id = null ) {
  2394 function media_upload_type_url_form( $type = null, $errors = null, $id = null ) {
  2353 	if ( null === $type ) {
  2395 	if ( null === $type ) {
  2354 		$type = 'image';
  2396 		$type = 'image';
  2355 	}
  2397 	}
  2356 
  2398 
  2357 	media_upload_header();
  2399 	media_upload_header();
  2358 
  2400 
  2359 	$post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0;
  2401 	$post_id = isset( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0;
  2360 
  2402 
  2361 	$form_action_url = admin_url( "media-upload.php?type=$type&tab=type&post_id=$post_id" );
  2403 	$form_action_url = admin_url( "media-upload.php?type=$type&tab=type&post_id=$post_id" );
  2362 	/** This filter is documented in wp-admin/includes/media.php */
  2404 	/** This filter is documented in wp-admin/includes/media.php */
  2363 	$form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type );
  2405 	$form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type );
  2364 	$form_class      = 'media-upload-form type-form validate';
  2406 	$form_class      = 'media-upload-form type-form validate';
  2502 	global $redir_tab, $type;
  2544 	global $redir_tab, $type;
  2503 
  2545 
  2504 	$redir_tab = 'gallery';
  2546 	$redir_tab = 'gallery';
  2505 	media_upload_header();
  2547 	media_upload_header();
  2506 
  2548 
  2507 	$post_id         = intval( $_REQUEST['post_id'] );
  2549 	$post_id         = (int) $_REQUEST['post_id'];
  2508 	$form_action_url = admin_url( "media-upload.php?type=$type&tab=gallery&post_id=$post_id" );
  2550 	$form_action_url = admin_url( "media-upload.php?type=$type&tab=gallery&post_id=$post_id" );
  2509 	/** This filter is documented in wp-admin/includes/media.php */
  2551 	/** This filter is documented in wp-admin/includes/media.php */
  2510 	$form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type );
  2552 	$form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type );
  2511 	$form_class      = 'media-upload-form validate';
  2553 	$form_class      = 'media-upload-form validate';
  2512 
  2554 
  2665 function media_upload_library_form( $errors ) {
  2707 function media_upload_library_form( $errors ) {
  2666 	global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types;
  2708 	global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types;
  2667 
  2709 
  2668 	media_upload_header();
  2710 	media_upload_header();
  2669 
  2711 
  2670 	$post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0;
  2712 	$post_id = isset( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0;
  2671 
  2713 
  2672 	$form_action_url = admin_url( "media-upload.php?type=$type&tab=library&post_id=$post_id" );
  2714 	$form_action_url = admin_url( "media-upload.php?type=$type&tab=library&post_id=$post_id" );
  2673 	/** This filter is documented in wp-admin/includes/media.php */
  2715 	/** This filter is documented in wp-admin/includes/media.php */
  2674 	$form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type );
  2716 	$form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type );
  2675 	$form_class      = 'media-upload-form validate';
  2717 	$form_class      = 'media-upload-form validate';
  2678 		$form_class .= ' html-uploader';
  2720 		$form_class .= ' html-uploader';
  2679 	}
  2721 	}
  2680 
  2722 
  2681 	$q                   = $_GET;
  2723 	$q                   = $_GET;
  2682 	$q['posts_per_page'] = 10;
  2724 	$q['posts_per_page'] = 10;
  2683 	$q['paged']          = isset( $q['paged'] ) ? intval( $q['paged'] ) : 0;
  2725 	$q['paged']          = isset( $q['paged'] ) ? (int) $q['paged'] : 0;
  2684 	if ( $q['paged'] < 1 ) {
  2726 	if ( $q['paged'] < 1 ) {
  2685 		$q['paged'] = 1;
  2727 		$q['paged'] = 1;
  2686 	}
  2728 	}
  2687 	$q['offset'] = ( $q['paged'] - 1 ) * 10;
  2729 	$q['offset'] = ( $q['paged'] - 1 ) * 10;
  2688 	if ( $q['offset'] < 1 ) {
  2730 	if ( $q['offset'] < 1 ) {
  2980 function media_upload_flash_bypass() {
  3022 function media_upload_flash_bypass() {
  2981 	$browser_uploader = admin_url( 'media-new.php?browser-uploader' );
  3023 	$browser_uploader = admin_url( 'media-new.php?browser-uploader' );
  2982 
  3024 
  2983 	$post = get_post();
  3025 	$post = get_post();
  2984 	if ( $post ) {
  3026 	if ( $post ) {
  2985 		$browser_uploader .= '&amp;post_id=' . intval( $post->ID );
  3027 		$browser_uploader .= '&amp;post_id=' . (int) $post->ID;
  2986 	} elseif ( ! empty( $GLOBALS['post_ID'] ) ) {
  3028 	} elseif ( ! empty( $GLOBALS['post_ID'] ) ) {
  2987 		$browser_uploader .= '&amp;post_id=' . intval( $GLOBALS['post_ID'] );
  3029 		$browser_uploader .= '&amp;post_id=' . (int) $GLOBALS['post_ID'];
  2988 	}
  3030 	}
  2989 
  3031 
  2990 	?>
  3032 	?>
  2991 	<p class="upload-flash-bypass">
  3033 	<p class="upload-flash-bypass">
  2992 	<?php
  3034 	<?php
  3074 	if ( $open ) {
  3116 	if ( $open ) {
  3075 		require_once ABSPATH . 'wp-admin/includes/image-edit.php';
  3117 		require_once ABSPATH . 'wp-admin/includes/image-edit.php';
  3076 	}
  3118 	}
  3077 
  3119 
  3078 	$thumb_url     = false;
  3120 	$thumb_url     = false;
  3079 	$attachment_id = intval( $post->ID );
  3121 	$attachment_id = (int) $post->ID;
  3080 
  3122 
  3081 	if ( $attachment_id ) {
  3123 	if ( $attachment_id ) {
  3082 		$thumb_url = wp_get_attachment_image_src( $attachment_id, array( 900, 450 ), true );
  3124 		$thumb_url = wp_get_attachment_image_src( $attachment_id, array( 900, 450 ), true );
  3083 	}
  3125 	}
  3084 
  3126 
  3190 
  3232 
  3191 		printf(
  3233 		printf(
  3192 			/* translators: 1: Link to tutorial, 2: Additional link attributes, 3: Accessibility text. */
  3234 			/* translators: 1: Link to tutorial, 2: Additional link attributes, 3: Accessibility text. */
  3193 			__( '<a href="%1$s" %2$s>Describe the purpose of the image%3$s</a>. Leave empty if the image is purely decorative.' ),
  3235 			__( '<a href="%1$s" %2$s>Describe the purpose of the image%3$s</a>. Leave empty if the image is purely decorative.' ),
  3194 			esc_url( 'https://www.w3.org/WAI/tutorials/images/decision-tree' ),
  3236 			esc_url( 'https://www.w3.org/WAI/tutorials/images/decision-tree' ),
  3195 			'target="_blank" rel="noopener noreferrer"',
  3237 			'target="_blank" rel="noopener"',
  3196 			sprintf(
  3238 			sprintf(
  3197 				'<span class="screen-reader-text"> %s</span>',
  3239 				'<span class="screen-reader-text"> %s</span>',
  3198 				/* translators: Accessibility text. */
  3240 				/* translators: Accessibility text. */
  3199 				__( '(opens in a new tab)' )
  3241 				__( '(opens in a new tab)' )
  3200 			)
  3242 			)
  3262 	/** This filter is documented in wp-admin/includes/media.php */
  3304 	/** This filter is documented in wp-admin/includes/media.php */
  3263 	$media_dims = apply_filters( 'media_meta', $media_dims, $post );
  3305 	$media_dims = apply_filters( 'media_meta', $media_dims, $post );
  3264 
  3306 
  3265 	$att_url = wp_get_attachment_url( $attachment_id );
  3307 	$att_url = wp_get_attachment_url( $attachment_id );
  3266 
  3308 
       
  3309 	$author = new WP_User( $post->post_author );
       
  3310 
       
  3311 	$uploaded_by_name = __( '(no author)' );
       
  3312 	$uploaded_by_link = '';
       
  3313 
       
  3314 	if ( $author->exists() ) {
       
  3315 		$uploaded_by_name = $author->display_name ? $author->display_name : $author->nickname;
       
  3316 		$uploaded_by_link = get_edit_user_link( $author->ID );
       
  3317 	}
  3267 	?>
  3318 	?>
       
  3319 	<div class="misc-pub-section misc-pub-uploadedby">
       
  3320 		<?php if ( $uploaded_by_link ) { ?>
       
  3321 			<?php _e( 'Uploaded by:' ); ?> <a href="<?php echo $uploaded_by_link; ?>"><strong><?php echo $uploaded_by_name; ?></strong></a>
       
  3322 		<?php } else { ?>
       
  3323 			<?php _e( 'Uploaded by:' ); ?> <strong><?php echo $uploaded_by_name; ?></strong>
       
  3324 		<?php } ?>
       
  3325 	</div>
       
  3326 
       
  3327 	<?php
       
  3328 	if ( $post->post_parent ) {
       
  3329 		$post_parent = get_post( $post->post_parent );
       
  3330 		if ( $post_parent ) {
       
  3331 			$uploaded_to_title = $post_parent->post_title ? $post_parent->post_title : __( '(no title)' );
       
  3332 			$uploaded_to_link  = get_edit_post_link( $post->post_parent, 'raw' );
       
  3333 			?>
       
  3334 			<div class="misc-pub-section misc-pub-uploadedto">
       
  3335 				<?php if ( $uploaded_to_link ) { ?>
       
  3336 					<?php _e( 'Uploaded to:' ); ?> <a href="<?php echo $uploaded_to_link; ?>"><strong><?php echo $uploaded_to_title; ?></strong></a>
       
  3337 				<?php } else { ?>
       
  3338 					<?php _e( 'Uploaded to:' ); ?> <strong><?php echo $uploaded_to_title; ?></strong>
       
  3339 				<?php } ?>
       
  3340 			</div>
       
  3341 			<?php
       
  3342 		}
       
  3343 	}
       
  3344 	?>
       
  3345 
  3268 	<div class="misc-pub-section misc-pub-attachment">
  3346 	<div class="misc-pub-section misc-pub-attachment">
  3269 		<label for="attachment_url"><?php _e( 'File URL:' ); ?></label>
  3347 		<label for="attachment_url"><?php _e( 'File URL:' ); ?></label>
  3270 		<input type="text" class="widefat urlfield" readonly="readonly" name="attachment_url" id="attachment_url" value="<?php echo esc_attr( $att_url ); ?>" />
  3348 		<input type="text" class="widefat urlfield" readonly="readonly" name="attachment_url" id="attachment_url" value="<?php echo esc_attr( $att_url ); ?>" />
  3271 		<span class="copy-to-clipboard-container">
  3349 		<span class="copy-to-clipboard-container">
  3272 			<button type="button" class="button copy-attachment-url edit-media" data-clipboard-target="#attachment_url"><?php _e( 'Copy URL' ); ?></button>
  3350 			<button type="button" class="button copy-attachment-url edit-media" data-clipboard-target="#attachment_url"><?php _e( 'Copy URL to clipboard' ); ?></button>
  3273 			<span class="success hidden" aria-hidden="true"><?php _e( 'Copied!' ); ?></span>
  3351 			<span class="success hidden" aria-hidden="true"><?php _e( 'Copied!' ); ?></span>
  3274 		</span>
  3352 		</span>
  3275 	</div>
  3353 	</div>
  3276 	<div class="misc-pub-section misc-pub-filename">
  3354 	<div class="misc-pub-section misc-pub-filename">
  3277 		<?php _e( 'File name:' ); ?> <strong><?php echo $filename; ?></strong>
  3355 		<?php _e( 'File name:' ); ?> <strong><?php echo $filename; ?></strong>
  3465  * Retrieve metadata from a video file's ID3 tags
  3543  * Retrieve metadata from a video file's ID3 tags
  3466  *
  3544  *
  3467  * @since 3.6.0
  3545  * @since 3.6.0
  3468  *
  3546  *
  3469  * @param string $file Path to file.
  3547  * @param string $file Path to file.
  3470  * @return array|bool Returns array of metadata, if found.
  3548  * @return array|false Returns array of metadata, if found.
  3471  */
  3549  */
  3472 function wp_read_video_metadata( $file ) {
  3550 function wp_read_video_metadata( $file ) {
  3473 	if ( ! file_exists( $file ) ) {
  3551 	if ( ! file_exists( $file ) ) {
  3474 		return false;
  3552 		return false;
  3475 	}
  3553 	}
  3576  * Retrieve metadata from an audio file's ID3 tags.
  3654  * Retrieve metadata from an audio file's ID3 tags.
  3577  *
  3655  *
  3578  * @since 3.6.0
  3656  * @since 3.6.0
  3579  *
  3657  *
  3580  * @param string $file Path to file.
  3658  * @param string $file Path to file.
  3581  * @return array|bool Returns array of metadata, if found.
  3659  * @return array|false Returns array of metadata, if found.
  3582  */
  3660  */
  3583 function wp_read_audio_metadata( $file ) {
  3661 function wp_read_audio_metadata( $file ) {
  3584 	if ( ! file_exists( $file ) ) {
  3662 	if ( ! file_exists( $file ) ) {
  3585 		return false;
  3663 		return false;
  3586 	}
  3664 	}
  3645  * @since 4.9.0
  3723  * @since 4.9.0
  3646  *
  3724  *
  3647  * @link https://github.com/JamesHeinrich/getID3/blob/master/structure.txt
  3725  * @link https://github.com/JamesHeinrich/getID3/blob/master/structure.txt
  3648  *
  3726  *
  3649  * @param array $metadata The metadata returned by getID3::analyze().
  3727  * @param array $metadata The metadata returned by getID3::analyze().
  3650  * @return int|bool A UNIX timestamp for the media's creation date if available
  3728  * @return int|false A UNIX timestamp for the media's creation date if available
  3651  *                  or a boolean FALSE if a timestamp could not be determined.
  3729  *                   or a boolean FALSE if a timestamp could not be determined.
  3652  */
  3730  */
  3653 function wp_get_media_creation_timestamp( $metadata ) {
  3731 function wp_get_media_creation_timestamp( $metadata ) {
  3654 	$creation_date = false;
  3732 	$creation_date = false;
  3655 
  3733 
  3656 	if ( empty( $metadata['fileformat'] ) ) {
  3734 	if ( empty( $metadata['fileformat'] ) ) {