wp/wp-admin/includes/media.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    13  *
    13  *
    14  * @return array default tabs
    14  * @return array default tabs
    15  */
    15  */
    16 function media_upload_tabs() {
    16 function media_upload_tabs() {
    17 	$_default_tabs = array(
    17 	$_default_tabs = array(
    18 		'type' => __('From Computer'), // handler action suffix => tab text
    18 		'type'     => __( 'From Computer' ), // handler action suffix => tab text
    19 		'type_url' => __('From URL'),
    19 		'type_url' => __( 'From URL' ),
    20 		'gallery' => __('Gallery'),
    20 		'gallery'  => __( 'Gallery' ),
    21 		'library' => __('Media Library')
    21 		'library'  => __( 'Media Library' ),
    22 	);
    22 	);
    23 
    23 
    24 	/**
    24 	/**
    25 	 * Filters the available tabs in the legacy (pre-3.5.0) media popup.
    25 	 * Filters the available tabs in the legacy (pre-3.5.0) media popup.
    26 	 *
    26 	 *
    39  * @global wpdb $wpdb WordPress database abstraction object.
    39  * @global wpdb $wpdb WordPress database abstraction object.
    40  *
    40  *
    41  * @param array $tabs
    41  * @param array $tabs
    42  * @return array $tabs with gallery if post has image attachment
    42  * @return array $tabs with gallery if post has image attachment
    43  */
    43  */
    44 function update_gallery_tab($tabs) {
    44 function update_gallery_tab( $tabs ) {
    45 	global $wpdb;
    45 	global $wpdb;
    46 
    46 
    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 = intval( $_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 = 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 ) ) );
    56 
    56 	}
    57 	if ( empty($attachments) ) {
    57 
    58 		unset($tabs['gallery']);
    58 	if ( empty( $attachments ) ) {
       
    59 		unset( $tabs['gallery'] );
    59 		return $tabs;
    60 		return $tabs;
    60 	}
    61 	}
    61 
    62 
    62 	$tabs['gallery'] = sprintf(__('Gallery (%s)'), "<span id='attachments-count'>$attachments</span>");
    63 	$tabs['gallery'] = sprintf( __( 'Gallery (%s)' ), "<span id='attachments-count'>$attachments</span>" );
    63 
    64 
    64 	return $tabs;
    65 	return $tabs;
    65 }
    66 }
    66 
    67 
    67 /**
    68 /**
    71  *
    72  *
    72  * @global string $redir_tab
    73  * @global string $redir_tab
    73  */
    74  */
    74 function the_media_upload_tabs() {
    75 function the_media_upload_tabs() {
    75 	global $redir_tab;
    76 	global $redir_tab;
    76 	$tabs = media_upload_tabs();
    77 	$tabs    = media_upload_tabs();
    77 	$default = 'type';
    78 	$default = 'type';
    78 
    79 
    79 	if ( !empty($tabs) ) {
    80 	if ( ! empty( $tabs ) ) {
    80 		echo "<ul id='sidemenu'>\n";
    81 		echo "<ul id='sidemenu'>\n";
    81 		if ( isset($redir_tab) && array_key_exists($redir_tab, $tabs) ) {
    82 		if ( isset( $redir_tab ) && array_key_exists( $redir_tab, $tabs ) ) {
    82 			$current = $redir_tab;
    83 			$current = $redir_tab;
    83 		} elseif ( isset($_GET['tab']) && array_key_exists($_GET['tab'], $tabs) ) {
    84 		} elseif ( isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $tabs ) ) {
    84 			$current = $_GET['tab'];
    85 			$current = $_GET['tab'];
    85 		} else {
    86 		} else {
    86 			/** This filter is documented in wp-admin/media-upload.php */
    87 			/** This filter is documented in wp-admin/media-upload.php */
    87 			$current = apply_filters( 'media_upload_default_tab', $default );
    88 			$current = apply_filters( 'media_upload_default_tab', $default );
    88 		}
    89 		}
    89 
    90 
    90 		foreach ( $tabs as $callback => $text ) {
    91 		foreach ( $tabs as $callback => $text ) {
    91 			$class = '';
    92 			$class = '';
    92 
    93 
    93 			if ( $current == $callback )
    94 			if ( $current == $callback ) {
    94 				$class = " class='current'";
    95 				$class = " class='current'";
    95 
    96 			}
    96 			$href = add_query_arg(array('tab' => $callback, 's' => false, 'paged' => false, 'post_mime_type' => false, 'm' => false));
    97 
    97 			$link = "<a href='" . esc_url($href) . "'$class>$text</a>";
    98 			$href = add_query_arg(
    98 			echo "\t<li id='" . esc_attr("tab-$callback") . "'>$link</li>\n";
    99 				array(
       
   100 					'tab'            => $callback,
       
   101 					's'              => false,
       
   102 					'paged'          => false,
       
   103 					'post_mime_type' => false,
       
   104 					'm'              => false,
       
   105 				)
       
   106 			);
       
   107 			$link = "<a href='" . esc_url( $href ) . "'$class>$text</a>";
       
   108 			echo "\t<li id='" . esc_attr( "tab-$callback" ) . "'>$link</li>\n";
    99 		}
   109 		}
   100 		echo "</ul>\n";
   110 		echo "</ul>\n";
   101 	}
   111 	}
   102 }
   112 }
   103 
   113 
   129 		}
   139 		}
   130 	} else {
   140 	} else {
   131 		$rel = '';
   141 		$rel = '';
   132 	}
   142 	}
   133 
   143 
   134 	if ( $url )
   144 	if ( $url ) {
   135 		$html = '<a href="' . esc_attr( $url ) . '"' . $rel . '>' . $html . '</a>';
   145 		$html = '<a href="' . esc_attr( $url ) . '"' . $rel . '>' . $html . '</a>';
       
   146 	}
   136 
   147 
   137 	/**
   148 	/**
   138 	 * Filters the image HTML markup to send to the editor when inserting an image.
   149 	 * Filters the image HTML markup to send to the editor when inserting an image.
   139 	 *
   150 	 *
   140 	 * @since 2.5.0
   151 	 * @since 2.5.0
   157 /**
   168 /**
   158  * Adds image shortcode with caption to editor
   169  * Adds image shortcode with caption to editor
   159  *
   170  *
   160  * @since 2.6.0
   171  * @since 2.6.0
   161  *
   172  *
   162  * @param string $html
   173  * @param string  $html    The image HTML markup to send.
   163  * @param integer $id
   174  * @param integer $id      Image attachment ID.
   164  * @param string $caption image caption
   175  * @param string  $caption Image caption.
   165  * @param string $title image title attribute
   176  * @param string  $title   Image title attribute (not used).
   166  * @param string $align image css alignment property
   177  * @param string  $align   Image CSS alignment property.
   167  * @param string $url image src url
   178  * @param string  $url     Image source URL (not used).
   168  * @param string $size image size (thumbnail, medium, large, full or added with add_image_size() )
   179  * @param string  $size    Image size (`thumbnail`, `medium`, `large`, `full`, or added with `add_image_size()`) (not used).
   169  * @param string $alt image alt attribute
   180  * @param string  $alt     Image `alt` attribute (not used).
   170  * @return string
   181  * @return string The image HTML markup with caption shortcode.
   171  */
   182  */
   172 function image_add_caption( $html, $id, $caption, $title, $align, $url, $size, $alt = '' ) {
   183 function image_add_caption( $html, $id, $caption, $title, $align, $url, $size, $alt = '' ) {
   173 
   184 
   174 	/**
   185 	/**
   175 	 * Filters the caption text.
   186 	 * Filters the caption text.
   195 	 * @since 2.6.0
   206 	 * @since 2.6.0
   196 	 *
   207 	 *
   197 	 * @param bool $bool Whether to disable appending captions. Returning true to the filter
   208 	 * @param bool $bool Whether to disable appending captions. Returning true to the filter
   198 	 *                   will disable captions. Default empty string.
   209 	 *                   will disable captions. Default empty string.
   199 	 */
   210 	 */
   200 	if ( empty($caption) || apply_filters( 'disable_captions', '' ) )
   211 	if ( empty( $caption ) || apply_filters( 'disable_captions', '' ) ) {
   201 		return $html;
   212 		return $html;
       
   213 	}
   202 
   214 
   203 	$id = ( 0 < (int) $id ) ? 'attachment_' . $id : '';
   215 	$id = ( 0 < (int) $id ) ? 'attachment_' . $id : '';
   204 
   216 
   205 	if ( ! preg_match( '/width=["\']([0-9]+)/', $html, $matches ) )
   217 	if ( ! preg_match( '/width=["\']([0-9]+)/', $html, $matches ) ) {
   206 		return $html;
   218 		return $html;
       
   219 	}
   207 
   220 
   208 	$width = $matches[1];
   221 	$width = $matches[1];
   209 
   222 
   210 	$caption = str_replace( array("\r\n", "\r"), "\n", $caption);
   223 	$caption = str_replace( array( "\r\n", "\r" ), "\n", $caption );
   211 	$caption = preg_replace_callback( '/<[a-zA-Z0-9]+(?: [^<>]+>)*/', '_cleanup_image_add_caption', $caption );
   224 	$caption = preg_replace_callback( '/<[a-zA-Z0-9]+(?: [^<>]+>)*/', '_cleanup_image_add_caption', $caption );
   212 
   225 
   213 	// Convert any remaining line breaks to <br>.
   226 	// Convert any remaining line breaks to <br>.
   214 	$caption = preg_replace( '/[ \n\t]*\n[ \t]*/', '<br />', $caption );
   227 	$caption = preg_replace( '/[ \n\t]*\n[ \t]*/', '<br />', $caption );
   215 
   228 
   216 	$html = preg_replace( '/(class=["\'][^\'"]*)align(none|left|right|center)\s?/', '$1', $html );
   229 	$html = preg_replace( '/(class=["\'][^\'"]*)align(none|left|right|center)\s?/', '$1', $html );
   217 	if ( empty($align) )
   230 	if ( empty( $align ) ) {
   218 		$align = 'none';
   231 		$align = 'none';
   219 
   232 	}
   220 	$shcode = '[caption id="' . $id . '" align="align' . $align	. '" width="' . $width . '"]' . $html . ' ' . $caption . '[/caption]';
   233 
       
   234 	$shcode = '[caption id="' . $id . '" align="align' . $align . '" width="' . $width . '"]' . $html . ' ' . $caption . '[/caption]';
   221 
   235 
   222 	/**
   236 	/**
   223 	 * Filters the image HTML markup including the caption shortcode.
   237 	 * Filters the image HTML markup including the caption shortcode.
   224 	 *
   238 	 *
   225 	 * @since 2.6.0
   239 	 * @since 2.6.0
   246  *
   260  *
   247  * @since 2.5.0
   261  * @since 2.5.0
   248  *
   262  *
   249  * @param string $html
   263  * @param string $html
   250  */
   264  */
   251 function media_send_to_editor($html) {
   265 function media_send_to_editor( $html ) {
   252 ?>
   266 	?>
   253 <script type="text/javascript">
   267 <script type="text/javascript">
   254 var win = window.dialogArguments || opener || parent || top;
   268 var win = window.dialogArguments || opener || parent || top;
   255 win.send_to_editor( <?php echo wp_json_encode( $html ); ?> );
   269 win.send_to_editor( <?php echo wp_json_encode( $html ); ?> );
   256 </script>
   270 </script>
   257 <?php
   271 	<?php
   258 	exit;
   272 	exit;
   259 }
   273 }
   260 
   274 
   261 /**
   275 /**
   262  * Save a file submitted from a POST request and create an attachment post for it.
   276  * Save a file submitted from a POST request and create an attachment post for it.
   268  *                          be set to 0, creating a media item that has no relationship to a post.
   282  *                          be set to 0, creating a media item that has no relationship to a post.
   269  * @param array  $post_data Overwrite some of the attachment. Optional.
   283  * @param array  $post_data Overwrite some of the attachment. Optional.
   270  * @param array  $overrides Override the wp_handle_upload() behavior. Optional.
   284  * @param array  $overrides Override the wp_handle_upload() behavior. Optional.
   271  * @return int|WP_Error ID of the attachment or a WP_Error object on failure.
   285  * @return int|WP_Error ID of the attachment or a WP_Error object on failure.
   272  */
   286  */
   273 function media_handle_upload($file_id, $post_id, $post_data = array(), $overrides = array( 'test_form' => false )) {
   287 function media_handle_upload( $file_id, $post_id, $post_data = array(), $overrides = array( 'test_form' => false ) ) {
   274 
   288 
   275 	$time = current_time('mysql');
   289 	$time = current_time( 'mysql' );
   276 	if ( $post = get_post($post_id) ) {
   290 	if ( $post = get_post( $post_id ) ) {
   277 		// The post date doesn't usually matter for pages, so don't backdate this upload.
   291 		// The post date doesn't usually matter for pages, so don't backdate this upload.
   278 		if ( 'page' !== $post->post_type && substr( $post->post_date, 0, 4 ) > 0 )
   292 		if ( 'page' !== $post->post_type && substr( $post->post_date, 0, 4 ) > 0 ) {
   279 			$time = $post->post_date;
   293 			$time = $post->post_date;
   280 	}
   294 		}
   281 
   295 	}
   282 	$file = wp_handle_upload($_FILES[$file_id], $overrides, $time);
   296 
   283 
   297 	$file = wp_handle_upload( $_FILES[ $file_id ], $overrides, $time );
   284 	if ( isset($file['error']) )
   298 
       
   299 	if ( isset( $file['error'] ) ) {
   285 		return new WP_Error( 'upload_error', $file['error'] );
   300 		return new WP_Error( 'upload_error', $file['error'] );
   286 
   301 	}
   287 	$name = $_FILES[$file_id]['name'];
   302 
       
   303 	$name = $_FILES[ $file_id ]['name'];
   288 	$ext  = pathinfo( $name, PATHINFO_EXTENSION );
   304 	$ext  = pathinfo( $name, PATHINFO_EXTENSION );
   289 	$name = wp_basename( $name, ".$ext" );
   305 	$name = wp_basename( $name, ".$ext" );
   290 
   306 
   291 	$url = $file['url'];
   307 	$url     = $file['url'];
   292 	$type = $file['type'];
   308 	$type    = $file['type'];
   293 	$file = $file['file'];
   309 	$file    = $file['file'];
   294 	$title = sanitize_text_field( $name );
   310 	$title   = sanitize_text_field( $name );
   295 	$content = '';
   311 	$content = '';
   296 	$excerpt = '';
   312 	$excerpt = '';
   297 
   313 
   298 	if ( preg_match( '#^audio#', $type ) ) {
   314 	if ( preg_match( '#^audio#', $type ) ) {
   299 		$meta = wp_read_audio_metadata( $file );
   315 		$meta = wp_read_audio_metadata( $file );
   315 				$content .= sprintf( __( '"%1$s" by %2$s.' ), $title, $meta['artist'] );
   331 				$content .= sprintf( __( '"%1$s" by %2$s.' ), $title, $meta['artist'] );
   316 			} else {
   332 			} else {
   317 				/* translators: 1: audio track title */
   333 				/* translators: 1: audio track title */
   318 				$content .= sprintf( __( '"%s".' ), $title );
   334 				$content .= sprintf( __( '"%s".' ), $title );
   319 			}
   335 			}
   320 
       
   321 		} elseif ( ! empty( $meta['album'] ) ) {
   336 		} elseif ( ! empty( $meta['album'] ) ) {
   322 
   337 
   323 			if ( ! empty( $meta['artist'] ) ) {
   338 			if ( ! empty( $meta['artist'] ) ) {
   324 				/* translators: 1: audio album title, 2: artist name */
   339 				/* translators: 1: audio album title, 2: artist name */
   325 				$content .= sprintf( __( '%1$s by %2$s.' ), $meta['album'], $meta['artist'] );
   340 				$content .= sprintf( __( '%1$s by %2$s.' ), $meta['album'], $meta['artist'] );
   326 			} else {
   341 			} else {
   327 				$content .= $meta['album'] . '.';
   342 				$content .= $meta['album'] . '.';
   328 			}
   343 			}
   329 
       
   330 		} elseif ( ! empty( $meta['artist'] ) ) {
   344 		} elseif ( ! empty( $meta['artist'] ) ) {
   331 
   345 
   332 			$content .= $meta['artist'] . '.';
   346 			$content .= $meta['artist'] . '.';
   333 
   347 
   334 		}
   348 		}
   335 
   349 
   336 		if ( ! empty( $meta['year'] ) ) {
   350 		if ( ! empty( $meta['year'] ) ) {
   337 			/* translators: Audio file track information. 1: Year of audio track release */
   351 			/* translators: Audio file track information. %d: Year of audio track release */
   338 			$content .= ' ' . sprintf( __( 'Released: %d.' ), $meta['year'] );
   352 			$content .= ' ' . sprintf( __( 'Released: %d.' ), $meta['year'] );
   339 		}
   353 		}
   340 
   354 
   341 		if ( ! empty( $meta['track_number'] ) ) {
   355 		if ( ! empty( $meta['track_number'] ) ) {
   342 			$track_number = explode( '/', $meta['track_number'] );
   356 			$track_number = explode( '/', $meta['track_number'] );
   343 			if ( isset( $track_number[1] ) ) {
   357 			if ( isset( $track_number[1] ) ) {
   344 				/* translators: Audio file track information. 1: Audio track number, 2: Total audio tracks */
   358 				/* translators: Audio file track information. 1: Audio track number, 2: Total audio tracks */
   345 				$content .= ' ' . sprintf( __( 'Track %1$s of %2$s.' ), number_format_i18n( $track_number[0] ), number_format_i18n( $track_number[1] ) );
   359 				$content .= ' ' . sprintf( __( 'Track %1$s of %2$s.' ), number_format_i18n( $track_number[0] ), number_format_i18n( $track_number[1] ) );
   346 			} else {
   360 			} else {
   347 				/* translators: Audio file track information. 1: Audio track number */
   361 				/* translators: Audio file track information. %s: Audio track number */
   348 				$content .= ' ' . sprintf( __( 'Track %1$s.' ), number_format_i18n( $track_number[0] ) );
   362 				$content .= ' ' . sprintf( __( 'Track %s.' ), number_format_i18n( $track_number[0] ) );
   349 			}
   363 			}
   350 		}
   364 		}
   351 
   365 
   352 		if ( ! empty( $meta['genre'] ) ) {
   366 		if ( ! empty( $meta['genre'] ) ) {
   353 			/* translators: Audio file genre information. 1: Audio genre name */
   367 			/* translators: Audio file genre information. %s: Audio genre name */
   354 			$content .= ' ' . sprintf( __( 'Genre: %s.' ), $meta['genre'] );
   368 			$content .= ' ' . sprintf( __( 'Genre: %s.' ), $meta['genre'] );
   355 		}
   369 		}
   356 
   370 
   357 	// Use image exif/iptc data for title and caption defaults if possible.
   371 		// Use image exif/iptc data for title and caption defaults if possible.
   358 	} elseif ( 0 === strpos( $type, 'image/' ) && $image_meta = wp_read_image_metadata( $file ) ) {
   372 	} elseif ( 0 === strpos( $type, 'image/' ) && $image_meta = wp_read_image_metadata( $file ) ) {
   359 		if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) {
   373 		if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) {
   360 			$title = $image_meta['title'];
   374 			$title = $image_meta['title'];
   361 		}
   375 		}
   362 
   376 
   364 			$excerpt = $image_meta['caption'];
   378 			$excerpt = $image_meta['caption'];
   365 		}
   379 		}
   366 	}
   380 	}
   367 
   381 
   368 	// Construct the attachment array
   382 	// Construct the attachment array
   369 	$attachment = array_merge( array(
   383 	$attachment = array_merge(
   370 		'post_mime_type' => $type,
   384 		array(
   371 		'guid' => $url,
   385 			'post_mime_type' => $type,
   372 		'post_parent' => $post_id,
   386 			'guid'           => $url,
   373 		'post_title' => $title,
   387 			'post_parent'    => $post_id,
   374 		'post_content' => $content,
   388 			'post_title'     => $title,
   375 		'post_excerpt' => $excerpt,
   389 			'post_content'   => $content,
   376 	), $post_data );
   390 			'post_excerpt'   => $excerpt,
       
   391 		),
       
   392 		$post_data
       
   393 	);
   377 
   394 
   378 	// This should never be set as it would then overwrite an existing attachment.
   395 	// This should never be set as it would then overwrite an existing attachment.
   379 	unset( $attachment['ID'] );
   396 	unset( $attachment['ID'] );
   380 
   397 
   381 	// Save the data
   398 	// Save the data
   382 	$id = wp_insert_attachment( $attachment, $file, $post_id, true );
   399 	$id = wp_insert_attachment( $attachment, $file, $post_id, true );
   383 	if ( !is_wp_error($id) ) {
   400 	if ( ! is_wp_error( $id ) ) {
   384 		wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
   401 		wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
   385 	}
   402 	}
   386 
   403 
   387 	return $id;
   404 	return $id;
   388 
   405 
   398  * @param string $desc       Optional. Description of the side-loaded file. Default null.
   415  * @param string $desc       Optional. Description of the side-loaded file. Default null.
   399  * @param array  $post_data  Optional. Post data to override. Default empty array.
   416  * @param array  $post_data  Optional. Post data to override. Default empty array.
   400  * @return int|object The ID of the attachment or a WP_Error on failure.
   417  * @return int|object The ID of the attachment or a WP_Error on failure.
   401  */
   418  */
   402 function media_handle_sideload( $file_array, $post_id, $desc = null, $post_data = array() ) {
   419 function media_handle_sideload( $file_array, $post_id, $desc = null, $post_data = array() ) {
   403 	$overrides = array('test_form'=>false);
   420 	$overrides = array( 'test_form' => false );
   404 
   421 
   405 	$time = current_time( 'mysql' );
   422 	$time = current_time( 'mysql' );
   406 	if ( $post = get_post( $post_id ) ) {
   423 	if ( $post = get_post( $post_id ) ) {
   407 		if ( substr( $post->post_date, 0, 4 ) > 0 )
   424 		if ( substr( $post->post_date, 0, 4 ) > 0 ) {
   408 			$time = $post->post_date;
   425 			$time = $post->post_date;
       
   426 		}
   409 	}
   427 	}
   410 
   428 
   411 	$file = wp_handle_sideload( $file_array, $overrides, $time );
   429 	$file = wp_handle_sideload( $file_array, $overrides, $time );
   412 	if ( isset($file['error']) )
   430 	if ( isset( $file['error'] ) ) {
   413 		return new WP_Error( 'upload_error', $file['error'] );
   431 		return new WP_Error( 'upload_error', $file['error'] );
   414 
   432 	}
   415 	$url = $file['url'];
   433 
   416 	$type = $file['type'];
   434 	$url     = $file['url'];
   417 	$file = $file['file'];
   435 	$type    = $file['type'];
   418 	$title = preg_replace('/\.[^.]+$/', '', basename($file));
   436 	$file    = $file['file'];
       
   437 	$title   = preg_replace( '/\.[^.]+$/', '', wp_basename( $file ) );
   419 	$content = '';
   438 	$content = '';
   420 
   439 
   421 	// Use image exif/iptc data for title and caption defaults if possible.
   440 	// Use image exif/iptc data for title and caption defaults if possible.
   422 	if ( $image_meta = wp_read_image_metadata( $file ) ) {
   441 	if ( $image_meta = wp_read_image_metadata( $file ) ) {
   423 		if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) )
   442 		if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) ) {
   424 			$title = $image_meta['title'];
   443 			$title = $image_meta['title'];
   425 		if ( trim( $image_meta['caption'] ) )
   444 		}
       
   445 		if ( trim( $image_meta['caption'] ) ) {
   426 			$content = $image_meta['caption'];
   446 			$content = $image_meta['caption'];
   427 	}
   447 		}
   428 
   448 	}
   429 	if ( isset( $desc ) )
   449 
       
   450 	if ( isset( $desc ) ) {
   430 		$title = $desc;
   451 		$title = $desc;
       
   452 	}
   431 
   453 
   432 	// Construct the attachment array.
   454 	// Construct the attachment array.
   433 	$attachment = array_merge( array(
   455 	$attachment = array_merge(
   434 		'post_mime_type' => $type,
   456 		array(
   435 		'guid' => $url,
   457 			'post_mime_type' => $type,
   436 		'post_parent' => $post_id,
   458 			'guid'           => $url,
   437 		'post_title' => $title,
   459 			'post_parent'    => $post_id,
   438 		'post_content' => $content,
   460 			'post_title'     => $title,
   439 	), $post_data );
   461 			'post_content'   => $content,
       
   462 		),
       
   463 		$post_data
       
   464 	);
   440 
   465 
   441 	// This should never be set as it would then overwrite an existing attachment.
   466 	// This should never be set as it would then overwrite an existing attachment.
   442 	unset( $attachment['ID'] );
   467 	unset( $attachment['ID'] );
   443 
   468 
   444 	// Save the attachment metadata
   469 	// Save the attachment metadata
   445 	$id = wp_insert_attachment($attachment, $file, $post_id);
   470 	$id = wp_insert_attachment( $attachment, $file, $post_id, true );
   446 	if ( !is_wp_error($id) )
   471 	if ( ! is_wp_error( $id ) ) {
   447 		wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
   472 		wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
       
   473 	}
   448 
   474 
   449 	return $id;
   475 	return $id;
   450 }
   476 }
   451 
   477 
   452 /**
   478 /**
   456  *
   482  *
   457  * @global int $body_id
   483  * @global int $body_id
   458  *
   484  *
   459  * @param string|callable $content_func
   485  * @param string|callable $content_func
   460  */
   486  */
   461 function wp_iframe($content_func /* ... */) {
   487 function wp_iframe( $content_func /* ... */ ) {
   462 	_wp_admin_html_begin();
   488 	_wp_admin_html_begin();
   463 ?>
   489 	?>
   464 <title><?php bloginfo('name') ?> &rsaquo; <?php _e('Uploads'); ?> &#8212; <?php _e('WordPress'); ?></title>
   490 <title><?php bloginfo( 'name' ); ?> &rsaquo; <?php _e( 'Uploads' ); ?> &#8212; <?php _e( 'WordPress' ); ?></title>
   465 <?php
   491 	<?php
   466 
   492 
   467 wp_enqueue_style( 'colors' );
   493 	wp_enqueue_style( 'colors' );
   468 // Check callback name for 'media'
   494 	// Check callback name for 'media'
   469 if ( ( is_array( $content_func ) && ! empty( $content_func[1] ) && 0 === strpos( (string) $content_func[1], 'media' ) )
   495 	if ( ( is_array( $content_func ) && ! empty( $content_func[1] ) && 0 === strpos( (string) $content_func[1], 'media' ) )
   470 	|| ( ! is_array( $content_func ) && 0 === strpos( $content_func, 'media' ) ) )
   496 	|| ( ! is_array( $content_func ) && 0 === strpos( $content_func, 'media' ) ) ) {
   471 	wp_enqueue_style( 'deprecated-media' );
   497 		wp_enqueue_style( 'deprecated-media' );
   472 wp_enqueue_style( 'ie' );
   498 	}
   473 ?>
   499 	wp_enqueue_style( 'ie' );
       
   500 	?>
   474 <script type="text/javascript">
   501 <script type="text/javascript">
   475 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();}}};
   502 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();}}};
   476 var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>', pagenow = 'media-upload-popup', adminpage = 'media-upload-popup',
   503 var ajaxurl = '<?php echo admin_url( 'admin-ajax.php', 'relative' ); ?>', pagenow = 'media-upload-popup', adminpage = 'media-upload-popup',
   477 isRtl = <?php echo (int) is_rtl(); ?>;
   504 isRtl = <?php echo (int) is_rtl(); ?>;
   478 </script>
   505 </script>
   479 <?php
   506 	<?php
   480 	/** This action is documented in wp-admin/admin-header.php */
   507 	/** This action is documented in wp-admin/admin-header.php */
   481 	do_action( 'admin_enqueue_scripts', 'media-upload-popup' );
   508 	do_action( 'admin_enqueue_scripts', 'media-upload-popup' );
   482 
   509 
   483 	/**
   510 	/**
   484 	 * Fires when admin styles enqueued for the legacy (pre-3.5.0) media upload popup are printed.
   511 	 * Fires when admin styles enqueued for the legacy (pre-3.5.0) media upload popup are printed.
   509 	do_action( 'admin_head-media-upload-popup' );
   536 	do_action( 'admin_head-media-upload-popup' );
   510 
   537 
   511 	/** This action is documented in wp-admin/admin-header.php */
   538 	/** This action is documented in wp-admin/admin-header.php */
   512 	do_action( 'admin_head' );
   539 	do_action( 'admin_head' );
   513 
   540 
   514 if ( is_string( $content_func ) ) {
   541 	if ( is_string( $content_func ) ) {
   515 	/**
   542 		/**
   516 	 * Fires in the admin header for each specific form tab in the legacy
   543 		 * Fires in the admin header for each specific form tab in the legacy
   517 	 * (pre-3.5.0) media upload popup.
   544 		 * (pre-3.5.0) media upload popup.
   518 	 *
   545 		 *
   519 	 * The dynamic portion of the hook, `$content_func`, refers to the form
   546 		 * The dynamic portion of the hook, `$content_func`, refers to the form
   520 	 * callback for the media upload type. Possible values include
   547 		 * callback for the media upload type. Possible values include
   521 	 * 'media_upload_type_form', 'media_upload_type_url_form', and
   548 		 * 'media_upload_type_form', 'media_upload_type_url_form', and
   522 	 * 'media_upload_library_form'.
   549 		 * 'media_upload_library_form'.
   523 	 *
   550 		 *
   524 	 * @since 2.5.0
   551 		 * @since 2.5.0
   525 	 */
   552 		 */
   526 	do_action( "admin_head_{$content_func}" );
   553 		do_action( "admin_head_{$content_func}" );
   527 }
   554 	}
   528 ?>
   555 
       
   556 	$body_id_attr = '';
       
   557 	if ( isset( $GLOBALS['body_id'] ) ) {
       
   558 		$body_id_attr = ' id="' . $GLOBALS['body_id'] . '"';
       
   559 	}
       
   560 	?>
   529 </head>
   561 </head>
   530 <body<?php if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?> class="wp-core-ui no-js">
   562 <body<?php echo $body_id_attr; ?> class="wp-core-ui no-js">
   531 <script type="text/javascript">
   563 <script type="text/javascript">
   532 document.body.className = document.body.className.replace('no-js', 'js');
   564 document.body.className = document.body.className.replace('no-js', 'js');
   533 </script>
   565 </script>
   534 <?php
   566 	<?php
   535 	$args = func_get_args();
   567 	$args = func_get_args();
   536 	$args = array_slice($args, 1);
   568 	$args = array_slice( $args, 1 );
   537 	call_user_func_array($content_func, $args);
   569 	call_user_func_array( $content_func, $args );
   538 
   570 
   539 	/** This action is documented in wp-admin/admin-footer.php */
   571 	/** This action is documented in wp-admin/admin-footer.php */
   540 	do_action( 'admin_print_footer_scripts' );
   572 	do_action( 'admin_print_footer_scripts' );
   541 ?>
   573 	?>
   542 <script type="text/javascript">if(typeof wpOnload=='function')wpOnload();</script>
   574 <script type="text/javascript">if(typeof wpOnload=='function')wpOnload();</script>
   543 </body>
   575 </body>
   544 </html>
   576 </html>
   545 <?php
   577 	<?php
   546 }
   578 }
   547 
   579 
   548 /**
   580 /**
   549  * Adds the media button to the editor
   581  * Adds the media button to the editor
   550  *
   582  *
   554  *
   586  *
   555  * @staticvar int $instance
   587  * @staticvar int $instance
   556  *
   588  *
   557  * @param string $editor_id
   589  * @param string $editor_id
   558  */
   590  */
   559 function media_buttons($editor_id = 'content') {
   591 function media_buttons( $editor_id = 'content' ) {
   560 	static $instance = 0;
   592 	static $instance = 0;
   561 	$instance++;
   593 	$instance++;
   562 
   594 
   563 	$post = get_post();
   595 	$post = get_post();
   564 	if ( ! $post && ! empty( $GLOBALS['post_ID'] ) )
   596 	if ( ! $post && ! empty( $GLOBALS['post_ID'] ) ) {
   565 		$post = $GLOBALS['post_ID'];
   597 		$post = $GLOBALS['post_ID'];
   566 
   598 	}
   567 	wp_enqueue_media( array(
   599 
   568 		'post' => $post
   600 	wp_enqueue_media(
   569 	) );
   601 		array(
       
   602 			'post' => $post,
       
   603 		)
       
   604 	);
   570 
   605 
   571 	$img = '<span class="wp-media-buttons-icon"></span> ';
   606 	$img = '<span class="wp-media-buttons-icon"></span> ';
   572 
   607 
   573 	$id_attribute = $instance === 1 ? ' id="insert-media-button"' : '';
   608 	$id_attribute = $instance === 1 ? ' id="insert-media-button"' : '';
   574 	printf( '<button type="button"%s class="button insert-media add_media" data-editor="%s">%s</button>',
   609 	printf(
       
   610 		'<button type="button"%s class="button insert-media add_media" data-editor="%s">%s</button>',
   575 		$id_attribute,
   611 		$id_attribute,
   576 		esc_attr( $editor_id ),
   612 		esc_attr( $editor_id ),
   577 		$img . __( 'Add Media' )
   613 		$img . __( 'Add Media' )
   578 	);
   614 	);
   579 	/**
   615 	/**
   588 	 */
   624 	 */
   589 	$legacy_filter = apply_filters( 'media_buttons_context', '' );
   625 	$legacy_filter = apply_filters( 'media_buttons_context', '' );
   590 
   626 
   591 	if ( $legacy_filter ) {
   627 	if ( $legacy_filter ) {
   592 		// #WP22559. Close <a> if a plugin started by closing <a> to open their own <a> tag.
   628 		// #WP22559. Close <a> if a plugin started by closing <a> to open their own <a> tag.
   593 		if ( 0 === stripos( trim( $legacy_filter ), '</a>' ) )
   629 		if ( 0 === stripos( trim( $legacy_filter ), '</a>' ) ) {
   594 			$legacy_filter .= '</a>';
   630 			$legacy_filter .= '</a>';
       
   631 		}
   595 		echo $legacy_filter;
   632 		echo $legacy_filter;
   596 	}
   633 	}
   597 }
   634 }
   598 
   635 
   599 /**
   636 /**
   600  *
       
   601  * @global int $post_ID
   637  * @global int $post_ID
   602  * @param string $type
   638  * @param string $type
   603  * @param int $post_id
   639  * @param int $post_id
   604  * @param string $tab
   640  * @param string $tab
   605  * @return string
   641  * @return string
   606  */
   642  */
   607 function get_upload_iframe_src( $type = null, $post_id = null, $tab = null ) {
   643 function get_upload_iframe_src( $type = null, $post_id = null, $tab = null ) {
   608 	global $post_ID;
   644 	global $post_ID;
   609 
   645 
   610 	if ( empty( $post_id ) )
   646 	if ( empty( $post_id ) ) {
   611 		$post_id = $post_ID;
   647 		$post_id = $post_ID;
   612 
   648 	}
   613 	$upload_iframe_src = add_query_arg( 'post_id', (int) $post_id, admin_url('media-upload.php') );
   649 
   614 
   650 	$upload_iframe_src = add_query_arg( 'post_id', (int) $post_id, admin_url( 'media-upload.php' ) );
   615 	if ( $type && 'media' != $type )
   651 
   616 		$upload_iframe_src = add_query_arg('type', $type, $upload_iframe_src);
   652 	if ( $type && 'media' != $type ) {
   617 
   653 		$upload_iframe_src = add_query_arg( 'type', $type, $upload_iframe_src );
   618 	if ( ! empty( $tab ) )
   654 	}
   619 		$upload_iframe_src = add_query_arg('tab', $tab, $upload_iframe_src);
   655 
       
   656 	if ( ! empty( $tab ) ) {
       
   657 		$upload_iframe_src = add_query_arg( 'tab', $tab, $upload_iframe_src );
       
   658 	}
   620 
   659 
   621 	/**
   660 	/**
   622 	 * Filters the upload iframe source URL for a specific media type.
   661 	 * Filters the upload iframe source URL for a specific media type.
   623 	 *
   662 	 *
   624 	 * The dynamic portion of the hook name, `$type`, refers to the type
   663 	 * The dynamic portion of the hook name, `$type`, refers to the type
   628 	 *
   667 	 *
   629 	 * @param string $upload_iframe_src The upload iframe source URL by type.
   668 	 * @param string $upload_iframe_src The upload iframe source URL by type.
   630 	 */
   669 	 */
   631 	$upload_iframe_src = apply_filters( "{$type}_upload_iframe_src", $upload_iframe_src );
   670 	$upload_iframe_src = apply_filters( "{$type}_upload_iframe_src", $upload_iframe_src );
   632 
   671 
   633 	return add_query_arg('TB_iframe', true, $upload_iframe_src);
   672 	return add_query_arg( 'TB_iframe', true, $upload_iframe_src );
   634 }
   673 }
   635 
   674 
   636 /**
   675 /**
   637  * Handles form submissions for the legacy media uploader.
   676  * Handles form submissions for the legacy media uploader.
   638  *
   677  *
   639  * @since 2.5.0
   678  * @since 2.5.0
   640  *
   679  *
   641  * @return mixed void|object WP_Error on failure
   680  * @return mixed void|object WP_Error on failure
   642  */
   681  */
   643 function media_upload_form_handler() {
   682 function media_upload_form_handler() {
   644 	check_admin_referer('media-form');
   683 	check_admin_referer( 'media-form' );
   645 
   684 
   646 	$errors = null;
   685 	$errors = null;
   647 
   686 
   648 	if ( isset($_POST['send']) ) {
   687 	if ( isset( $_POST['send'] ) ) {
   649 		$keys = array_keys( $_POST['send'] );
   688 		$keys    = array_keys( $_POST['send'] );
   650 		$send_id = (int) reset( $keys );
   689 		$send_id = (int) reset( $keys );
   651 	}
   690 	}
   652 
   691 
   653 	if ( !empty($_POST['attachments']) ) foreach ( $_POST['attachments'] as $attachment_id => $attachment ) {
   692 	if ( ! empty( $_POST['attachments'] ) ) {
   654 		$post = $_post = get_post($attachment_id, ARRAY_A);
   693 		foreach ( $_POST['attachments'] as $attachment_id => $attachment ) {
   655 
   694 			$post = $_post = get_post( $attachment_id, ARRAY_A );
   656 		if ( !current_user_can( 'edit_post', $attachment_id ) )
   695 
   657 			continue;
   696 			if ( ! current_user_can( 'edit_post', $attachment_id ) ) {
   658 
   697 				continue;
   659 		if ( isset($attachment['post_content']) )
   698 			}
   660 			$post['post_content'] = $attachment['post_content'];
   699 
   661 		if ( isset($attachment['post_title']) )
   700 			if ( isset( $attachment['post_content'] ) ) {
   662 			$post['post_title'] = $attachment['post_title'];
   701 				$post['post_content'] = $attachment['post_content'];
   663 		if ( isset($attachment['post_excerpt']) )
   702 			}
   664 			$post['post_excerpt'] = $attachment['post_excerpt'];
   703 			if ( isset( $attachment['post_title'] ) ) {
   665 		if ( isset($attachment['menu_order']) )
   704 				$post['post_title'] = $attachment['post_title'];
   666 			$post['menu_order'] = $attachment['menu_order'];
   705 			}
   667 
   706 			if ( isset( $attachment['post_excerpt'] ) ) {
   668 		if ( isset($send_id) && $attachment_id == $send_id ) {
   707 				$post['post_excerpt'] = $attachment['post_excerpt'];
   669 			if ( isset($attachment['post_parent']) )
   708 			}
   670 				$post['post_parent'] = $attachment['post_parent'];
   709 			if ( isset( $attachment['menu_order'] ) ) {
   671 		}
   710 				$post['menu_order'] = $attachment['menu_order'];
   672 
   711 			}
   673 		/**
   712 
   674 		 * Filters the attachment fields to be saved.
   713 			if ( isset( $send_id ) && $attachment_id == $send_id ) {
   675 		 *
   714 				if ( isset( $attachment['post_parent'] ) ) {
   676 		 * @since 2.5.0
   715 					$post['post_parent'] = $attachment['post_parent'];
   677 		 *
   716 				}
   678 		 * @see wp_get_attachment_metadata()
   717 			}
   679 		 *
   718 
   680 		 * @param array $post       An array of post data.
   719 			/**
   681 		 * @param array $attachment An array of attachment metadata.
   720 			 * Filters the attachment fields to be saved.
   682 		 */
   721 			 *
   683 		$post = apply_filters( 'attachment_fields_to_save', $post, $attachment );
   722 			 * @since 2.5.0
   684 
   723 			 *
   685 		if ( isset($attachment['image_alt']) ) {
   724 			 * @see wp_get_attachment_metadata()
   686 			$image_alt = wp_unslash( $attachment['image_alt'] );
   725 			 *
   687 			if ( $image_alt != get_post_meta($attachment_id, '_wp_attachment_image_alt', true) ) {
   726 			 * @param array $post       An array of post data.
   688 				$image_alt = wp_strip_all_tags( $image_alt, true );
   727 			 * @param array $attachment An array of attachment metadata.
   689 
   728 			 */
   690 				// Update_meta expects slashed.
   729 			$post = apply_filters( 'attachment_fields_to_save', $post, $attachment );
   691 				update_post_meta( $attachment_id, '_wp_attachment_image_alt', wp_slash( $image_alt ) );
   730 
   692 			}
   731 			if ( isset( $attachment['image_alt'] ) ) {
   693 		}
   732 				$image_alt = wp_unslash( $attachment['image_alt'] );
   694 
   733 				if ( $image_alt != get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) {
   695 		if ( isset($post['errors']) ) {
   734 					$image_alt = wp_strip_all_tags( $image_alt, true );
   696 			$errors[$attachment_id] = $post['errors'];
   735 
   697 			unset($post['errors']);
   736 					// Update_meta expects slashed.
   698 		}
   737 					update_post_meta( $attachment_id, '_wp_attachment_image_alt', wp_slash( $image_alt ) );
   699 
   738 				}
   700 		if ( $post != $_post )
   739 			}
   701 			wp_update_post($post);
   740 
   702 
   741 			if ( isset( $post['errors'] ) ) {
   703 		foreach ( get_attachment_taxonomies($post) as $t ) {
   742 				$errors[ $attachment_id ] = $post['errors'];
   704 			if ( isset($attachment[$t]) )
   743 				unset( $post['errors'] );
   705 				wp_set_object_terms($attachment_id, array_map('trim', preg_split('/,+/', $attachment[$t])), $t, false);
   744 			}
   706 		}
   745 
   707 	}
   746 			if ( $post != $_post ) {
   708 
   747 				wp_update_post( $post );
   709 	if ( isset($_POST['insert-gallery']) || isset($_POST['update-gallery']) ) { ?>
   748 			}
       
   749 
       
   750 			foreach ( get_attachment_taxonomies( $post ) as $t ) {
       
   751 				if ( isset( $attachment[ $t ] ) ) {
       
   752 					wp_set_object_terms( $attachment_id, array_map( 'trim', preg_split( '/,+/', $attachment[ $t ] ) ), $t, false );
       
   753 				}
       
   754 			}
       
   755 		}
       
   756 	}
       
   757 
       
   758 	if ( isset( $_POST['insert-gallery'] ) || isset( $_POST['update-gallery'] ) ) {
       
   759 		?>
   710 		<script type="text/javascript">
   760 		<script type="text/javascript">
   711 		var win = window.dialogArguments || opener || parent || top;
   761 		var win = window.dialogArguments || opener || parent || top;
   712 		win.tb_remove();
   762 		win.tb_remove();
   713 		</script>
   763 		</script>
   714 		<?php
   764 		<?php
   715 		exit;
   765 		exit;
   716 	}
   766 	}
   717 
   767 
   718 	if ( isset($send_id) ) {
   768 	if ( isset( $send_id ) ) {
   719 		$attachment = wp_unslash( $_POST['attachments'][$send_id] );
   769 		$attachment = wp_unslash( $_POST['attachments'][ $send_id ] );
   720 
   770 
   721 		$html = isset( $attachment['post_title'] ) ? $attachment['post_title'] : '';
   771 		$html = isset( $attachment['post_title'] ) ? $attachment['post_title'] : '';
   722 		if ( !empty($attachment['url']) ) {
   772 		if ( ! empty( $attachment['url'] ) ) {
   723 			$rel = '';
   773 			$rel = '';
   724 			if ( strpos($attachment['url'], 'attachment_id') || get_attachment_link($send_id) == $attachment['url'] )
   774 			if ( strpos( $attachment['url'], 'attachment_id' ) || get_attachment_link( $send_id ) == $attachment['url'] ) {
   725 				$rel = " rel='attachment wp-att-" . esc_attr($send_id) . "'";
   775 				$rel = " rel='attachment wp-att-" . esc_attr( $send_id ) . "'";
       
   776 			}
   726 			$html = "<a href='{$attachment['url']}'$rel>$html</a>";
   777 			$html = "<a href='{$attachment['url']}'$rel>$html</a>";
   727 		}
   778 		}
   728 
   779 
   729 		/**
   780 		/**
   730 		 * Filters the HTML markup for a media item sent to the editor.
   781 		 * Filters the HTML markup for a media item sent to the editor.
   736 		 * @param string $html       HTML markup for a media item sent to the editor.
   787 		 * @param string $html       HTML markup for a media item sent to the editor.
   737 		 * @param int    $send_id    The first key from the $_POST['send'] data.
   788 		 * @param int    $send_id    The first key from the $_POST['send'] data.
   738 		 * @param array  $attachment Array of attachment metadata.
   789 		 * @param array  $attachment Array of attachment metadata.
   739 		 */
   790 		 */
   740 		$html = apply_filters( 'media_send_to_editor', $html, $send_id, $attachment );
   791 		$html = apply_filters( 'media_send_to_editor', $html, $send_id, $attachment );
   741 		return media_send_to_editor($html);
   792 		return media_send_to_editor( $html );
   742 	}
   793 	}
   743 
   794 
   744 	return $errors;
   795 	return $errors;
   745 }
   796 }
   746 
   797 
   751  *
   802  *
   752  * @return null|string
   803  * @return null|string
   753  */
   804  */
   754 function wp_media_upload_handler() {
   805 function wp_media_upload_handler() {
   755 	$errors = array();
   806 	$errors = array();
   756 	$id = 0;
   807 	$id     = 0;
   757 
   808 
   758 	if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
   809 	if ( isset( $_POST['html-upload'] ) && ! empty( $_FILES ) ) {
   759 		check_admin_referer('media-form');
   810 		check_admin_referer( 'media-form' );
   760 		// Upload File button was clicked
   811 		// Upload File button was clicked
   761 		$id = media_handle_upload('async-upload', $_REQUEST['post_id']);
   812 		$id = media_handle_upload( 'async-upload', $_REQUEST['post_id'] );
   762 		unset($_FILES);
   813 		unset( $_FILES );
   763 		if ( is_wp_error($id) ) {
   814 		if ( is_wp_error( $id ) ) {
   764 			$errors['upload_error'] = $id;
   815 			$errors['upload_error'] = $id;
   765 			$id = false;
   816 			$id                     = false;
   766 		}
   817 		}
   767 	}
   818 	}
   768 
   819 
   769 	if ( !empty($_POST['insertonlybutton']) ) {
   820 	if ( ! empty( $_POST['insertonlybutton'] ) ) {
   770 		$src = $_POST['src'];
   821 		$src = $_POST['src'];
   771 		if ( !empty($src) && !strpos($src, '://') )
   822 		if ( ! empty( $src ) && ! strpos( $src, '://' ) ) {
   772 			$src = "http://$src";
   823 			$src = "http://$src";
       
   824 		}
   773 
   825 
   774 		if ( isset( $_POST['media_type'] ) && 'image' != $_POST['media_type'] ) {
   826 		if ( isset( $_POST['media_type'] ) && 'image' != $_POST['media_type'] ) {
   775 			$title = esc_html( wp_unslash( $_POST['title'] ) );
   827 			$title = esc_html( wp_unslash( $_POST['title'] ) );
   776 			if ( empty( $title ) )
   828 			if ( empty( $title ) ) {
   777 				$title = esc_html( basename( $src ) );
   829 				$title = esc_html( wp_basename( $src ) );
   778 
   830 			}
   779 			if ( $title && $src )
   831 
   780 				$html = "<a href='" . esc_url($src) . "'>$title</a>";
   832 			if ( $title && $src ) {
       
   833 				$html = "<a href='" . esc_url( $src ) . "'>$title</a>";
       
   834 			}
   781 
   835 
   782 			$type = 'file';
   836 			$type = 'file';
   783 			if ( ( $ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $src ) ) && ( $ext_type = wp_ext2type( $ext ) )
   837 			if ( ( $ext = preg_replace( '/^.+?\.([^.]+)$/', '$1', $src ) ) && ( $ext_type = wp_ext2type( $ext ) )
   784 				&& ( 'audio' == $ext_type || 'video' == $ext_type ) )
   838 				&& ( 'audio' == $ext_type || 'video' == $ext_type ) ) {
   785 					$type = $ext_type;
   839 					$type = $ext_type;
       
   840 			}
   786 
   841 
   787 			/**
   842 			/**
   788 			 * Filters the URL sent to the editor for a specific media type.
   843 			 * Filters the URL sent to the editor for a specific media type.
   789 			 *
   844 			 *
   790 			 * The dynamic portion of the hook name, `$type`, refers to the type
   845 			 * The dynamic portion of the hook name, `$type`, refers to the type
   797 			 * @param string $title Media title.
   852 			 * @param string $title Media title.
   798 			 */
   853 			 */
   799 			$html = apply_filters( "{$type}_send_to_editor_url", $html, esc_url_raw( $src ), $title );
   854 			$html = apply_filters( "{$type}_send_to_editor_url", $html, esc_url_raw( $src ), $title );
   800 		} else {
   855 		} else {
   801 			$align = '';
   856 			$align = '';
   802 			$alt = esc_attr( wp_unslash( $_POST['alt'] ) );
   857 			$alt   = esc_attr( wp_unslash( $_POST['alt'] ) );
   803 			if ( isset($_POST['align']) ) {
   858 			if ( isset( $_POST['align'] ) ) {
   804 				$align = esc_attr( wp_unslash( $_POST['align'] ) );
   859 				$align = esc_attr( wp_unslash( $_POST['align'] ) );
   805 				$class = " class='align$align'";
   860 				$class = " class='align$align'";
   806 			}
   861 			}
   807 			if ( !empty($src) )
   862 			if ( ! empty( $src ) ) {
   808 				$html = "<img src='" . esc_url($src) . "' alt='$alt'$class />";
   863 				$html = "<img src='" . esc_url( $src ) . "' alt='$alt'$class />";
       
   864 			}
   809 
   865 
   810 			/**
   866 			/**
   811 			 * Filters the image URL sent to the editor.
   867 			 * Filters the image URL sent to the editor.
   812 			 *
   868 			 *
   813 			 * @since 2.8.0
   869 			 * @since 2.8.0
   819 			 *                      'alignleft', 'aligncenter', 'alignright', 'alignnone'.
   875 			 *                      'alignleft', 'aligncenter', 'alignright', 'alignnone'.
   820 			 */
   876 			 */
   821 			$html = apply_filters( 'image_send_to_editor_url', $html, esc_url_raw( $src ), $alt, $align );
   877 			$html = apply_filters( 'image_send_to_editor_url', $html, esc_url_raw( $src ), $alt, $align );
   822 		}
   878 		}
   823 
   879 
   824 		return media_send_to_editor($html);
   880 		return media_send_to_editor( $html );
   825 	}
   881 	}
   826 
   882 
   827 	if ( isset( $_POST['save'] ) ) {
   883 	if ( isset( $_POST['save'] ) ) {
   828 		$errors['upload_notice'] = __('Saved.');
   884 		$errors['upload_notice'] = __( 'Saved.' );
   829 		wp_enqueue_script( 'admin-gallery' );
   885 		wp_enqueue_script( 'admin-gallery' );
   830  		return wp_iframe( 'media_upload_gallery_form', $errors );
   886 		return wp_iframe( 'media_upload_gallery_form', $errors );
   831 
   887 
   832 	} elseif ( ! empty( $_POST ) ) {
   888 	} elseif ( ! empty( $_POST ) ) {
   833 		$return = media_upload_form_handler();
   889 		$return = media_upload_form_handler();
   834 
   890 
   835 		if ( is_string($return) )
   891 		if ( is_string( $return ) ) {
   836 			return $return;
   892 			return $return;
   837 		if ( is_array($return) )
   893 		}
       
   894 		if ( is_array( $return ) ) {
   838 			$errors = $return;
   895 			$errors = $return;
   839 	}
   896 		}
   840 
   897 	}
   841 	if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' ) {
   898 
       
   899 	if ( isset( $_GET['tab'] ) && $_GET['tab'] == 'type_url' ) {
   842 		$type = 'image';
   900 		$type = 'image';
   843 		if ( isset( $_GET['type'] ) && in_array( $_GET['type'], array( 'video', 'audio', 'file' ) ) )
   901 		if ( isset( $_GET['type'] ) && in_array( $_GET['type'], array( 'video', 'audio', 'file' ) ) ) {
   844 			$type = $_GET['type'];
   902 			$type = $_GET['type'];
       
   903 		}
   845 		return wp_iframe( 'media_upload_type_url_form', $type, $errors, $id );
   904 		return wp_iframe( 'media_upload_type_url_form', $type, $errors, $id );
   846 	}
   905 	}
   847 
   906 
   848 	return wp_iframe( 'media_upload_type_form', 'image', $errors, $id );
   907 	return wp_iframe( 'media_upload_type_form', 'image', $errors, $id );
   849 }
   908 }
   868 		preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches );
   927 		preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches );
   869 		if ( ! $matches ) {
   928 		if ( ! $matches ) {
   870 			return new WP_Error( 'image_sideload_failed', __( 'Invalid image URL' ) );
   929 			return new WP_Error( 'image_sideload_failed', __( 'Invalid image URL' ) );
   871 		}
   930 		}
   872 
   931 
   873 		$file_array = array();
   932 		$file_array         = array();
   874 		$file_array['name'] = basename( $matches[0] );
   933 		$file_array['name'] = wp_basename( $matches[0] );
   875 
   934 
   876 		// Download file to temp location.
   935 		// Download file to temp location.
   877 		$file_array['tmp_name'] = download_url( $file );
   936 		$file_array['tmp_name'] = download_url( $file );
   878 
   937 
   879 		// If error storing temporarily, return the error.
   938 		// If error storing temporarily, return the error.
   886 
   945 
   887 		// If error storing permanently, unlink.
   946 		// If error storing permanently, unlink.
   888 		if ( is_wp_error( $id ) ) {
   947 		if ( is_wp_error( $id ) ) {
   889 			@unlink( $file_array['tmp_name'] );
   948 			@unlink( $file_array['tmp_name'] );
   890 			return $id;
   949 			return $id;
   891 		// If attachment id was requested, return it early.
   950 			// If attachment id was requested, return it early.
   892 		} elseif ( $return === 'id' ) {
   951 		} elseif ( $return === 'id' ) {
   893 			return $id;
   952 			return $id;
   894 		}
   953 		}
   895 
   954 
   896 		$src = wp_get_attachment_url( $id );
   955 		$src = wp_get_attachment_url( $id );
   900 	if ( ! empty( $src ) ) {
   959 	if ( ! empty( $src ) ) {
   901 		if ( $return === 'src' ) {
   960 		if ( $return === 'src' ) {
   902 			return $src;
   961 			return $src;
   903 		}
   962 		}
   904 
   963 
   905 		$alt = isset( $desc ) ? esc_attr( $desc ) : '';
   964 		$alt  = isset( $desc ) ? esc_attr( $desc ) : '';
   906 		$html = "<img src='$src' alt='$alt' />";
   965 		$html = "<img src='$src' alt='$alt' />";
   907 		return $html;
   966 		return $html;
   908 	} else {
   967 	} else {
   909 		return new WP_Error( 'image_sideload_failed' );
   968 		return new WP_Error( 'image_sideload_failed' );
   910 	}
   969 	}
   918  * @return string|null
   977  * @return string|null
   919  */
   978  */
   920 function media_upload_gallery() {
   979 function media_upload_gallery() {
   921 	$errors = array();
   980 	$errors = array();
   922 
   981 
   923 	if ( !empty($_POST) ) {
   982 	if ( ! empty( $_POST ) ) {
   924 		$return = media_upload_form_handler();
   983 		$return = media_upload_form_handler();
   925 
   984 
   926 		if ( is_string($return) )
   985 		if ( is_string( $return ) ) {
   927 			return $return;
   986 			return $return;
   928 		if ( is_array($return) )
   987 		}
       
   988 		if ( is_array( $return ) ) {
   929 			$errors = $return;
   989 			$errors = $return;
   930 	}
   990 		}
   931 
   991 	}
   932 	wp_enqueue_script('admin-gallery');
   992 
       
   993 	wp_enqueue_script( 'admin-gallery' );
   933 	return wp_iframe( 'media_upload_gallery_form', $errors );
   994 	return wp_iframe( 'media_upload_gallery_form', $errors );
   934 }
   995 }
   935 
   996 
   936 /**
   997 /**
   937  * Retrieves the legacy media library form in an iframe.
   998  * Retrieves the legacy media library form in an iframe.
   940  *
  1001  *
   941  * @return string|null
  1002  * @return string|null
   942  */
  1003  */
   943 function media_upload_library() {
  1004 function media_upload_library() {
   944 	$errors = array();
  1005 	$errors = array();
   945 	if ( !empty($_POST) ) {
  1006 	if ( ! empty( $_POST ) ) {
   946 		$return = media_upload_form_handler();
  1007 		$return = media_upload_form_handler();
   947 
  1008 
   948 		if ( is_string($return) )
  1009 		if ( is_string( $return ) ) {
   949 			return $return;
  1010 			return $return;
   950 		if ( is_array($return) )
  1011 		}
       
  1012 		if ( is_array( $return ) ) {
   951 			$errors = $return;
  1013 			$errors = $return;
       
  1014 		}
   952 	}
  1015 	}
   953 
  1016 
   954 	return wp_iframe( 'media_upload_library_form', $errors );
  1017 	return wp_iframe( 'media_upload_library_form', $errors );
   955 }
  1018 }
   956 
  1019 
   963  * @param string $checked
  1026  * @param string $checked
   964  * @return string
  1027  * @return string
   965  */
  1028  */
   966 function image_align_input_fields( $post, $checked = '' ) {
  1029 function image_align_input_fields( $post, $checked = '' ) {
   967 
  1030 
   968 	if ( empty($checked) )
  1031 	if ( empty( $checked ) ) {
   969 		$checked = get_user_setting('align', 'none');
  1032 		$checked = get_user_setting( 'align', 'none' );
   970 
  1033 	}
   971 	$alignments = array('none' => __('None'), 'left' => __('Left'), 'center' => __('Center'), 'right' => __('Right'));
  1034 
   972 	if ( !array_key_exists( (string) $checked, $alignments ) )
  1035 	$alignments = array(
       
  1036 		'none'   => __( 'None' ),
       
  1037 		'left'   => __( 'Left' ),
       
  1038 		'center' => __( 'Center' ),
       
  1039 		'right'  => __( 'Right' ),
       
  1040 	);
       
  1041 	if ( ! array_key_exists( (string) $checked, $alignments ) ) {
   973 		$checked = 'none';
  1042 		$checked = 'none';
       
  1043 	}
   974 
  1044 
   975 	$out = array();
  1045 	$out = array();
   976 	foreach ( $alignments as $name => $label ) {
  1046 	foreach ( $alignments as $name => $label ) {
   977 		$name = esc_attr($name);
  1047 		$name  = esc_attr( $name );
   978 		$out[] = "<input type='radio' name='attachments[{$post->ID}][align]' id='image-align-{$name}-{$post->ID}' value='$name'".
  1048 		$out[] = "<input type='radio' name='attachments[{$post->ID}][align]' id='image-align-{$name}-{$post->ID}' value='$name'" .
   979 			( $checked == $name ? " checked='checked'" : "" ) .
  1049 			( $checked == $name ? " checked='checked'" : '' ) .
   980 			" /><label for='image-align-{$name}-{$post->ID}' class='align image-align-{$name}-label'>$label</label>";
  1050 			" /><label for='image-align-{$name}-{$post->ID}' class='align image-align-{$name}-label'>$label</label>";
   981 	}
  1051 	}
   982 	return join("\n", $out);
  1052 	return join( "\n", $out );
   983 }
  1053 }
   984 
  1054 
   985 /**
  1055 /**
   986  * Retrieve HTML for the size radio buttons with the specified one checked.
  1056  * Retrieve HTML for the size radio buttons with the specified one checked.
   987  *
  1057  *
   998 	 * @since 3.3.0
  1068 	 * @since 3.3.0
   999 	 *
  1069 	 *
  1000 	 * @param array $size_names Array of image sizes and their names. Default values
  1070 	 * @param array $size_names Array of image sizes and their names. Default values
  1001 	 *                          include 'Thumbnail', 'Medium', 'Large', 'Full Size'.
  1071 	 *                          include 'Thumbnail', 'Medium', 'Large', 'Full Size'.
  1002 	 */
  1072 	 */
  1003 	$size_names = apply_filters( 'image_size_names_choose', array(
  1073 	$size_names = apply_filters(
  1004 		'thumbnail' => __( 'Thumbnail' ),
  1074 		'image_size_names_choose',
  1005 		'medium'    => __( 'Medium' ),
  1075 		array(
  1006 		'large'     => __( 'Large' ),
  1076 			'thumbnail' => __( 'Thumbnail' ),
  1007 		'full'      => __( 'Full Size' )
  1077 			'medium'    => __( 'Medium' ),
  1008 	) );
  1078 			'large'     => __( 'Large' ),
       
  1079 			'full'      => __( 'Full Size' ),
       
  1080 		)
       
  1081 	);
  1009 
  1082 
  1010 	if ( empty( $check ) ) {
  1083 	if ( empty( $check ) ) {
  1011 		$check = get_user_setting('imgsize', 'medium');
  1084 		$check = get_user_setting( 'imgsize', 'medium' );
  1012 	}
  1085 	}
  1013 	$out = array();
  1086 	$out = array();
  1014 
  1087 
  1015 	foreach ( $size_names as $size => $label ) {
  1088 	foreach ( $size_names as $size => $label ) {
  1016 		$downsize = image_downsize( $post->ID, $size );
  1089 		$downsize = image_downsize( $post->ID, $size );
  1017 		$checked = '';
  1090 		$checked  = '';
  1018 
  1091 
  1019 		// Is this size selectable?
  1092 		// Is this size selectable?
  1020 		$enabled = ( $downsize[3] || 'full' == $size );
  1093 		$enabled = ( $downsize[3] || 'full' == $size );
  1021 		$css_id = "image-size-{$size}-{$post->ID}";
  1094 		$css_id  = "image-size-{$size}-{$post->ID}";
  1022 
  1095 
  1023 		// If this size is the default but that's not available, don't select it.
  1096 		// If this size is the default but that's not available, don't select it.
  1024 		if ( $size == $check ) {
  1097 		if ( $size == $check ) {
  1025 			if ( $enabled ) {
  1098 			if ( $enabled ) {
  1026 				$checked = " checked='checked'";
  1099 				$checked = " checked='checked'";
  1030 		} elseif ( ! $check && $enabled && 'thumbnail' != $size ) {
  1103 		} elseif ( ! $check && $enabled && 'thumbnail' != $size ) {
  1031 			/*
  1104 			/*
  1032 			 * If $check is not enabled, default to the first available size
  1105 			 * If $check is not enabled, default to the first available size
  1033 			 * that's bigger than a thumbnail.
  1106 			 * that's bigger than a thumbnail.
  1034 			 */
  1107 			 */
  1035 			$check = $size;
  1108 			$check   = $size;
  1036 			$checked = " checked='checked'";
  1109 			$checked = " checked='checked'";
  1037 		}
  1110 		}
  1038 
  1111 
  1039 		$html = "<div class='image-size-item'><input type='radio' " . disabled( $enabled, false, false ) . "name='attachments[$post->ID][image-size]' id='{$css_id}' value='{$size}'$checked />";
  1112 		$html = "<div class='image-size-item'><input type='radio' " . disabled( $enabled, false, false ) . "name='attachments[$post->ID][image-size]' id='{$css_id}' value='{$size}'$checked />";
  1040 
  1113 
  1041 		$html .= "<label for='{$css_id}'>$label</label>";
  1114 		$html .= "<label for='{$css_id}'>$label</label>";
  1042 
  1115 
  1043 		// Only show the dimensions if that choice is available.
  1116 		// Only show the dimensions if that choice is available.
  1044 		if ( $enabled ) {
  1117 		if ( $enabled ) {
  1045 			$html .= " <label for='{$css_id}' class='help'>" . sprintf( "(%d&nbsp;&times;&nbsp;%d)", $downsize[1], $downsize[2] ). "</label>";
  1118 			$html .= " <label for='{$css_id}' class='help'>" . sprintf( '(%d&nbsp;&times;&nbsp;%d)', $downsize[1], $downsize[2] ) . '</label>';
  1046 		}
  1119 		}
  1047 		$html .= '</div>';
  1120 		$html .= '</div>';
  1048 
  1121 
  1049 		$out[] = $html;
  1122 		$out[] = $html;
  1050 	}
  1123 	}
  1063  *
  1136  *
  1064  * @param WP_Post $post
  1137  * @param WP_Post $post
  1065  * @param string $url_type
  1138  * @param string $url_type
  1066  * @return string
  1139  * @return string
  1067  */
  1140  */
  1068 function image_link_input_fields($post, $url_type = '') {
  1141 function image_link_input_fields( $post, $url_type = '' ) {
  1069 
  1142 
  1070 	$file = wp_get_attachment_url($post->ID);
  1143 	$file = wp_get_attachment_url( $post->ID );
  1071 	$link = get_attachment_link($post->ID);
  1144 	$link = get_attachment_link( $post->ID );
  1072 
  1145 
  1073 	if ( empty($url_type) )
  1146 	if ( empty( $url_type ) ) {
  1074 		$url_type = get_user_setting('urlbutton', 'post');
  1147 		$url_type = get_user_setting( 'urlbutton', 'post' );
       
  1148 	}
  1075 
  1149 
  1076 	$url = '';
  1150 	$url = '';
  1077 	if ( $url_type == 'file' )
  1151 	if ( $url_type == 'file' ) {
  1078 		$url = $file;
  1152 		$url = $file;
  1079 	elseif ( $url_type == 'post' )
  1153 	} elseif ( $url_type == 'post' ) {
  1080 		$url = $link;
  1154 		$url = $link;
       
  1155 	}
  1081 
  1156 
  1082 	return "
  1157 	return "
  1083 	<input type='text' class='text urlfield' name='attachments[$post->ID][url]' value='" . esc_attr($url) . "' /><br />
  1158 	<input type='text' class='text urlfield' name='attachments[$post->ID][url]' value='" . esc_attr( $url ) . "' /><br />
  1084 	<button type='button' class='button urlnone' data-link-url=''>" . __('None') . "</button>
  1159 	<button type='button' class='button urlnone' data-link-url=''>" . __( 'None' ) . "</button>
  1085 	<button type='button' class='button urlfile' data-link-url='" . esc_attr($file) . "'>" . __('File URL') . "</button>
  1160 	<button type='button' class='button urlfile' data-link-url='" . esc_attr( $file ) . "'>" . __( 'File URL' ) . "</button>
  1086 	<button type='button' class='button urlpost' data-link-url='" . esc_attr($link) . "'>" . __('Attachment Post URL') . "</button>
  1161 	<button type='button' class='button urlpost' data-link-url='" . esc_attr( $link ) . "'>" . __( 'Attachment Post URL' ) . '</button>
  1087 ";
  1162 ';
  1088 }
  1163 }
  1089 
  1164 
  1090 /**
  1165 /**
  1091  * Output a textarea element for inputting an attachment caption.
  1166  * Output a textarea element for inputting an attachment caption.
  1092  *
  1167  *
  1093  * @since 3.4.0
  1168  * @since 3.4.0
  1094  *
  1169  *
  1095  * @param WP_Post $edit_post Attachment WP_Post object.
  1170  * @param WP_Post $edit_post Attachment WP_Post object.
  1096  * @return string HTML markup for the textarea element.
  1171  * @return string HTML markup for the textarea element.
  1097  */
  1172  */
  1098 function wp_caption_input_textarea($edit_post) {
  1173 function wp_caption_input_textarea( $edit_post ) {
  1099 	// Post data is already escaped.
  1174 	// Post data is already escaped.
  1100 	$name = "attachments[{$edit_post->ID}][post_excerpt]";
  1175 	$name = "attachments[{$edit_post->ID}][post_excerpt]";
  1101 
  1176 
  1102 	return '<textarea name="' . $name . '" id="' . $name . '">' . $edit_post->post_excerpt . '</textarea>';
  1177 	return '<textarea name="' . $name . '" id="' . $name . '">' . $edit_post->post_excerpt . '</textarea>';
  1103 }
  1178 }
  1109  *
  1184  *
  1110  * @param array $form_fields
  1185  * @param array $form_fields
  1111  * @param object $post
  1186  * @param object $post
  1112  * @return array
  1187  * @return array
  1113  */
  1188  */
  1114 function image_attachment_fields_to_edit($form_fields, $post) {
  1189 function image_attachment_fields_to_edit( $form_fields, $post ) {
  1115 	return $form_fields;
  1190 	return $form_fields;
  1116 }
  1191 }
  1117 
  1192 
  1118 /**
  1193 /**
  1119  * Retrieves the single non-image attachment fields to edit form fields.
  1194  * Retrieves the single non-image attachment fields to edit form fields.
  1123  * @param array   $form_fields An array of attachment form fields.
  1198  * @param array   $form_fields An array of attachment form fields.
  1124  * @param WP_Post $post        The WP_Post attachment object.
  1199  * @param WP_Post $post        The WP_Post attachment object.
  1125  * @return array Filtered attachment form fields.
  1200  * @return array Filtered attachment form fields.
  1126  */
  1201  */
  1127 function media_single_attachment_fields_to_edit( $form_fields, $post ) {
  1202 function media_single_attachment_fields_to_edit( $form_fields, $post ) {
  1128 	unset($form_fields['url'], $form_fields['align'], $form_fields['image-size']);
  1203 	unset( $form_fields['url'], $form_fields['align'], $form_fields['image-size'] );
  1129 	return $form_fields;
  1204 	return $form_fields;
  1130 }
  1205 }
  1131 
  1206 
  1132 /**
  1207 /**
  1133  * Retrieves the post non-image attachment fields to edito form fields.
  1208  * Retrieves the post non-image attachment fields to edito form fields.
  1137  * @param array   $form_fields An array of attachment form fields.
  1212  * @param array   $form_fields An array of attachment form fields.
  1138  * @param WP_Post $post        The WP_Post attachment object.
  1213  * @param WP_Post $post        The WP_Post attachment object.
  1139  * @return array Filtered attachment form fields.
  1214  * @return array Filtered attachment form fields.
  1140  */
  1215  */
  1141 function media_post_single_attachment_fields_to_edit( $form_fields, $post ) {
  1216 function media_post_single_attachment_fields_to_edit( $form_fields, $post ) {
  1142 	unset($form_fields['image_url']);
  1217 	unset( $form_fields['image_url'] );
  1143 	return $form_fields;
  1218 	return $form_fields;
  1144 }
  1219 }
  1145 
  1220 
  1146 /**
  1221 /**
  1147  * Filters input from media_upload_form_handler() and assigns a default
  1222  * Filters input from media_upload_form_handler() and assigns a default
  1157  * @return array Filtered attachment post object.
  1232  * @return array Filtered attachment post object.
  1158  */
  1233  */
  1159 function image_attachment_fields_to_save( $post, $attachment ) {
  1234 function image_attachment_fields_to_save( $post, $attachment ) {
  1160 	if ( substr( $post['post_mime_type'], 0, 5 ) == 'image' ) {
  1235 	if ( substr( $post['post_mime_type'], 0, 5 ) == 'image' ) {
  1161 		if ( strlen( trim( $post['post_title'] ) ) == 0 ) {
  1236 		if ( strlen( trim( $post['post_title'] ) ) == 0 ) {
  1162 			$attachment_url = ( isset( $post['attachment_url'] ) ) ? $post['attachment_url'] : $post['guid'];
  1237 			$attachment_url                           = ( isset( $post['attachment_url'] ) ) ? $post['attachment_url'] : $post['guid'];
  1163 			$post['post_title'] = preg_replace( '/\.\w+$/', '', wp_basename( $attachment_url ) );
  1238 			$post['post_title']                       = preg_replace( '/\.\w+$/', '', wp_basename( $attachment_url ) );
  1164 			$post['errors']['post_title']['errors'][] = __( 'Empty Title filled from filename.' );
  1239 			$post['errors']['post_title']['errors'][] = __( 'Empty Title filled from filename.' );
  1165 		}
  1240 		}
  1166 	}
  1241 	}
  1167 
  1242 
  1168 	return $post;
  1243 	return $post;
  1176  * @param string $html
  1251  * @param string $html
  1177  * @param integer $attachment_id
  1252  * @param integer $attachment_id
  1178  * @param array $attachment
  1253  * @param array $attachment
  1179  * @return string
  1254  * @return string
  1180  */
  1255  */
  1181 function image_media_send_to_editor($html, $attachment_id, $attachment) {
  1256 function image_media_send_to_editor( $html, $attachment_id, $attachment ) {
  1182 	$post = get_post($attachment_id);
  1257 	$post = get_post( $attachment_id );
  1183 	if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
  1258 	if ( substr( $post->post_mime_type, 0, 5 ) == 'image' ) {
  1184 		$url = $attachment['url'];
  1259 		$url   = $attachment['url'];
  1185 		$align = !empty($attachment['align']) ? $attachment['align'] : 'none';
  1260 		$align = ! empty( $attachment['align'] ) ? $attachment['align'] : 'none';
  1186 		$size = !empty($attachment['image-size']) ? $attachment['image-size'] : 'medium';
  1261 		$size  = ! empty( $attachment['image-size'] ) ? $attachment['image-size'] : 'medium';
  1187 		$alt = !empty($attachment['image_alt']) ? $attachment['image_alt'] : '';
  1262 		$alt   = ! empty( $attachment['image_alt'] ) ? $attachment['image_alt'] : '';
  1188 		$rel = ( strpos( $url, 'attachment_id') || $url === get_attachment_link( $attachment_id ) );
  1263 		$rel   = ( strpos( $url, 'attachment_id' ) || $url === get_attachment_link( $attachment_id ) );
  1189 
  1264 
  1190 		return get_image_send_to_editor($attachment_id, $attachment['post_excerpt'], $attachment['post_title'], $align, $url, $rel, $size, $alt);
  1265 		return get_image_send_to_editor( $attachment_id, $attachment['post_excerpt'], $attachment['post_title'], $align, $url, $rel, $size, $alt );
  1191 	}
  1266 	}
  1192 
  1267 
  1193 	return $html;
  1268 	return $html;
  1194 }
  1269 }
  1195 
  1270 
  1200  *
  1275  *
  1201  * @param WP_Post $post
  1276  * @param WP_Post $post
  1202  * @param array $errors
  1277  * @param array $errors
  1203  * @return array
  1278  * @return array
  1204  */
  1279  */
  1205 function get_attachment_fields_to_edit($post, $errors = null) {
  1280 function get_attachment_fields_to_edit( $post, $errors = null ) {
  1206 	if ( is_int($post) )
  1281 	if ( is_int( $post ) ) {
  1207 		$post = get_post($post);
  1282 		$post = get_post( $post );
  1208 	if ( is_array($post) )
  1283 	}
       
  1284 	if ( is_array( $post ) ) {
  1209 		$post = new WP_Post( (object) $post );
  1285 		$post = new WP_Post( (object) $post );
  1210 
  1286 	}
  1211 	$image_url = wp_get_attachment_url($post->ID);
  1287 
  1212 
  1288 	$image_url = wp_get_attachment_url( $post->ID );
  1213 	$edit_post = sanitize_post($post, 'edit');
  1289 
       
  1290 	$edit_post = sanitize_post( $post, 'edit' );
  1214 
  1291 
  1215 	$form_fields = array(
  1292 	$form_fields = array(
  1216 		'post_title'   => array(
  1293 		'post_title'   => array(
  1217 			'label'      => __('Title'),
  1294 			'label' => __( 'Title' ),
  1218 			'value'      => $edit_post->post_title
  1295 			'value' => $edit_post->post_title,
  1219 		),
  1296 		),
  1220 		'image_alt'   => array(),
  1297 		'image_alt'    => array(),
  1221 		'post_excerpt' => array(
  1298 		'post_excerpt' => array(
  1222 			'label'      => __('Caption'),
  1299 			'label' => __( 'Caption' ),
  1223 			'input'      => 'html',
  1300 			'input' => 'html',
  1224 			'html'       => wp_caption_input_textarea($edit_post)
  1301 			'html'  => wp_caption_input_textarea( $edit_post ),
  1225 		),
  1302 		),
  1226 		'post_content' => array(
  1303 		'post_content' => array(
  1227 			'label'      => __('Description'),
  1304 			'label' => __( 'Description' ),
  1228 			'value'      => $edit_post->post_content,
  1305 			'value' => $edit_post->post_content,
  1229 			'input'      => 'textarea'
  1306 			'input' => 'textarea',
  1230 		),
  1307 		),
  1231 		'url'          => array(
  1308 		'url'          => array(
  1232 			'label'      => __('Link URL'),
  1309 			'label' => __( 'Link URL' ),
  1233 			'input'      => 'html',
  1310 			'input' => 'html',
  1234 			'html'       => image_link_input_fields($post, get_option('image_default_link_type')),
  1311 			'html'  => image_link_input_fields( $post, get_option( 'image_default_link_type' ) ),
  1235 			'helps'      => __('Enter a link URL or click above for presets.')
  1312 			'helps' => __( 'Enter a link URL or click above for presets.' ),
  1236 		),
  1313 		),
  1237 		'menu_order'   => array(
  1314 		'menu_order'   => array(
  1238 			'label'      => __('Order'),
  1315 			'label' => __( 'Order' ),
  1239 			'value'      => $edit_post->menu_order
  1316 			'value' => $edit_post->menu_order,
  1240 		),
  1317 		),
  1241 		'image_url'	=> array(
  1318 		'image_url'    => array(
  1242 			'label'      => __('File URL'),
  1319 			'label' => __( 'File URL' ),
  1243 			'input'      => 'html',
  1320 			'input' => 'html',
  1244 			'html'       => "<input type='text' class='text urlfield' readonly='readonly' name='attachments[$post->ID][url]' value='" . esc_attr($image_url) . "' /><br />",
  1321 			'html'  => "<input type='text' class='text urlfield' readonly='readonly' name='attachments[$post->ID][url]' value='" . esc_attr( $image_url ) . "' /><br />",
  1245 			'value'      => wp_get_attachment_url($post->ID),
  1322 			'value' => wp_get_attachment_url( $post->ID ),
  1246 			'helps'      => __('Location of the uploaded file.')
  1323 			'helps' => __( 'Location of the uploaded file.' ),
  1247 		)
  1324 		),
  1248 	);
  1325 	);
  1249 
  1326 
  1250 	foreach ( get_attachment_taxonomies($post) as $taxonomy ) {
  1327 	foreach ( get_attachment_taxonomies( $post ) as $taxonomy ) {
  1251 		$t = (array) get_taxonomy($taxonomy);
  1328 		$t = (array) get_taxonomy( $taxonomy );
  1252 		if ( ! $t['public'] || ! $t['show_ui'] )
  1329 		if ( ! $t['public'] || ! $t['show_ui'] ) {
  1253 			continue;
  1330 			continue;
  1254 		if ( empty($t['label']) )
  1331 		}
       
  1332 		if ( empty( $t['label'] ) ) {
  1255 			$t['label'] = $taxonomy;
  1333 			$t['label'] = $taxonomy;
  1256 		if ( empty($t['args']) )
  1334 		}
       
  1335 		if ( empty( $t['args'] ) ) {
  1257 			$t['args'] = array();
  1336 			$t['args'] = array();
  1258 
  1337 		}
  1259 		$terms = get_object_term_cache($post->ID, $taxonomy);
  1338 
  1260 		if ( false === $terms )
  1339 		$terms = get_object_term_cache( $post->ID, $taxonomy );
  1261 			$terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
  1340 		if ( false === $terms ) {
       
  1341 			$terms = wp_get_object_terms( $post->ID, $taxonomy, $t['args'] );
       
  1342 		}
  1262 
  1343 
  1263 		$values = array();
  1344 		$values = array();
  1264 
  1345 
  1265 		foreach ( $terms as $term )
  1346 		foreach ( $terms as $term ) {
  1266 			$values[] = $term->slug;
  1347 			$values[] = $term->slug;
  1267 		$t['value'] = join(', ', $values);
  1348 		}
  1268 
  1349 		$t['value'] = join( ', ', $values );
  1269 		$form_fields[$taxonomy] = $t;
  1350 
       
  1351 		$form_fields[ $taxonomy ] = $t;
  1270 	}
  1352 	}
  1271 
  1353 
  1272 	// Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default
  1354 	// Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default
  1273 	// The recursive merge is easily traversed with array casting: foreach ( (array) $things as $thing )
  1355 	// The recursive merge is easily traversed with array casting: foreach ( (array) $things as $thing )
  1274 	$form_fields = array_merge_recursive($form_fields, (array) $errors);
  1356 	$form_fields = array_merge_recursive( $form_fields, (array) $errors );
  1275 
  1357 
  1276 	// This was formerly in image_attachment_fields_to_edit().
  1358 	// This was formerly in image_attachment_fields_to_edit().
  1277 	if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
  1359 	if ( substr( $post->post_mime_type, 0, 5 ) == 'image' ) {
  1278 		$alt = get_post_meta($post->ID, '_wp_attachment_image_alt', true);
  1360 		$alt = get_post_meta( $post->ID, '_wp_attachment_image_alt', true );
  1279 		if ( empty($alt) )
  1361 		if ( empty( $alt ) ) {
  1280 			$alt = '';
  1362 			$alt = '';
       
  1363 		}
  1281 
  1364 
  1282 		$form_fields['post_title']['required'] = true;
  1365 		$form_fields['post_title']['required'] = true;
  1283 
  1366 
  1284 		$form_fields['image_alt'] = array(
  1367 		$form_fields['image_alt'] = array(
  1285 			'value' => $alt,
  1368 			'value' => $alt,
  1286 			'label' => __('Alternative Text'),
  1369 			'label' => __( 'Alternative Text' ),
  1287 			'helps' => __('Alt text for the image, e.g. &#8220;The Mona Lisa&#8221;')
  1370 			'helps' => __( 'Alt text for the image, e.g. &#8220;The Mona Lisa&#8221;' ),
  1288 		);
  1371 		);
  1289 
  1372 
  1290 		$form_fields['align'] = array(
  1373 		$form_fields['align'] = array(
  1291 			'label' => __('Alignment'),
  1374 			'label' => __( 'Alignment' ),
  1292 			'input' => 'html',
  1375 			'input' => 'html',
  1293 			'html'  => image_align_input_fields($post, get_option('image_default_align')),
  1376 			'html'  => image_align_input_fields( $post, get_option( 'image_default_align' ) ),
  1294 		);
  1377 		);
  1295 
  1378 
  1296 		$form_fields['image-size'] = image_size_input_fields( $post, get_option('image_default_size', 'medium') );
  1379 		$form_fields['image-size'] = image_size_input_fields( $post, get_option( 'image_default_size', 'medium' ) );
  1297 
  1380 
  1298 	} else {
  1381 	} else {
  1299 		unset( $form_fields['image_alt'] );
  1382 		unset( $form_fields['image_alt'] );
  1300 	}
  1383 	}
  1301 
  1384 
  1328  * @return string
  1411  * @return string
  1329  */
  1412  */
  1330 function get_media_items( $post_id, $errors ) {
  1413 function get_media_items( $post_id, $errors ) {
  1331 	$attachments = array();
  1414 	$attachments = array();
  1332 	if ( $post_id ) {
  1415 	if ( $post_id ) {
  1333 		$post = get_post($post_id);
  1416 		$post = get_post( $post_id );
  1334 		if ( $post && $post->post_type == 'attachment' )
  1417 		if ( $post && $post->post_type == 'attachment' ) {
  1335 			$attachments = array($post->ID => $post);
  1418 			$attachments = array( $post->ID => $post );
  1336 		else
  1419 		} else {
  1337 			$attachments = get_children( array( 'post_parent' => $post_id, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC') );
  1420 			$attachments = get_children(
       
  1421 				array(
       
  1422 					'post_parent' => $post_id,
       
  1423 					'post_type'   => 'attachment',
       
  1424 					'orderby'     => 'menu_order ASC, ID',
       
  1425 					'order'       => 'DESC',
       
  1426 				)
       
  1427 			);
       
  1428 		}
  1338 	} else {
  1429 	} else {
  1339 		if ( is_array($GLOBALS['wp_the_query']->posts) )
  1430 		if ( is_array( $GLOBALS['wp_the_query']->posts ) ) {
  1340 			foreach ( $GLOBALS['wp_the_query']->posts as $attachment )
  1431 			foreach ( $GLOBALS['wp_the_query']->posts as $attachment ) {
  1341 				$attachments[$attachment->ID] = $attachment;
  1432 				$attachments[ $attachment->ID ] = $attachment;
       
  1433 			}
       
  1434 		}
  1342 	}
  1435 	}
  1343 
  1436 
  1344 	$output = '';
  1437 	$output = '';
  1345 	foreach ( (array) $attachments as $id => $attachment ) {
  1438 	foreach ( (array) $attachments as $id => $attachment ) {
  1346 		if ( $attachment->post_status == 'trash' )
  1439 		if ( $attachment->post_status == 'trash' ) {
  1347 			continue;
  1440 			continue;
  1348 		if ( $item = get_media_item( $id, array( 'errors' => isset($errors[$id]) ? $errors[$id] : null) ) )
  1441 		}
       
  1442 		if ( $item = get_media_item( $id, array( 'errors' => isset( $errors[ $id ] ) ? $errors[ $id ] : null ) ) ) {
  1349 			$output .= "\n<div id='media-item-$id' class='media-item child-of-$attachment->post_parent preloaded'><div class='progress hidden'><div class='bar'></div></div><div id='media-upload-error-$id' class='hidden'></div><div class='filename hidden'></div>$item\n</div>";
  1443 			$output .= "\n<div id='media-item-$id' class='media-item child-of-$attachment->post_parent preloaded'><div class='progress hidden'><div class='bar'></div></div><div id='media-upload-error-$id' class='hidden'></div><div class='filename hidden'></div>$item\n</div>";
       
  1444 		}
  1350 	}
  1445 	}
  1351 
  1446 
  1352 	return $output;
  1447 	return $output;
  1353 }
  1448 }
  1354 
  1449 
  1364  * @return string HTML form for attachment.
  1459  * @return string HTML form for attachment.
  1365  */
  1460  */
  1366 function get_media_item( $attachment_id, $args = null ) {
  1461 function get_media_item( $attachment_id, $args = null ) {
  1367 	global $redir_tab;
  1462 	global $redir_tab;
  1368 
  1463 
  1369 	if ( ( $attachment_id = intval( $attachment_id ) ) && $thumb_url = wp_get_attachment_image_src( $attachment_id, 'thumbnail', true ) )
  1464 	if ( ( $attachment_id = intval( $attachment_id ) ) && $thumb_url = wp_get_attachment_image_src( $attachment_id, 'thumbnail', true ) ) {
  1370 		$thumb_url = $thumb_url[0];
  1465 		$thumb_url = $thumb_url[0];
  1371 	else
  1466 	} else {
  1372 		$thumb_url = false;
  1467 		$thumb_url = false;
  1373 
  1468 	}
  1374 	$post = get_post( $attachment_id );
  1469 
  1375 	$current_post_id = !empty( $_GET['post_id'] ) ? (int) $_GET['post_id'] : 0;
  1470 	$post            = get_post( $attachment_id );
       
  1471 	$current_post_id = ! empty( $_GET['post_id'] ) ? (int) $_GET['post_id'] : 0;
  1376 
  1472 
  1377 	$default_args = array(
  1473 	$default_args = array(
  1378 		'errors' => null,
  1474 		'errors'     => null,
  1379 		'send' => $current_post_id ? post_type_supports( get_post_type( $current_post_id ), 'editor' ) : true,
  1475 		'send'       => $current_post_id ? post_type_supports( get_post_type( $current_post_id ), 'editor' ) : true,
  1380 		'delete' => true,
  1476 		'delete'     => true,
  1381 		'toggle' => true,
  1477 		'toggle'     => true,
  1382 		'show_title' => true
  1478 		'show_title' => true,
  1383 	);
  1479 	);
  1384 	$args = wp_parse_args( $args, $default_args );
  1480 	$args         = wp_parse_args( $args, $default_args );
  1385 
  1481 
  1386 	/**
  1482 	/**
  1387 	 * Filters the arguments used to retrieve an image for the edit image form.
  1483 	 * Filters the arguments used to retrieve an image for the edit image form.
  1388 	 *
  1484 	 *
  1389 	 * @since 3.1.0
  1485 	 * @since 3.1.0
  1395 	$r = apply_filters( 'get_media_item_args', $args );
  1491 	$r = apply_filters( 'get_media_item_args', $args );
  1396 
  1492 
  1397 	$toggle_on  = __( 'Show' );
  1493 	$toggle_on  = __( 'Show' );
  1398 	$toggle_off = __( 'Hide' );
  1494 	$toggle_off = __( 'Hide' );
  1399 
  1495 
  1400 	$file = get_attached_file( $post->ID );
  1496 	$file     = get_attached_file( $post->ID );
  1401 	$filename = esc_html( wp_basename( $file ) );
  1497 	$filename = esc_html( wp_basename( $file ) );
  1402 	$title = esc_attr( $post->post_title );
  1498 	$title    = esc_attr( $post->post_title );
  1403 
  1499 
  1404 	$post_mime_types = get_post_mime_types();
  1500 	$post_mime_types = get_post_mime_types();
  1405 	$keys = array_keys( wp_match_mime_types( array_keys( $post_mime_types ), $post->post_mime_type ) );
  1501 	$keys            = array_keys( wp_match_mime_types( array_keys( $post_mime_types ), $post->post_mime_type ) );
  1406 	$type = reset( $keys );
  1502 	$type            = reset( $keys );
  1407 	$type_html = "<input type='hidden' id='type-of-$attachment_id' value='" . esc_attr( $type ) . "' />";
  1503 	$type_html       = "<input type='hidden' id='type-of-$attachment_id' value='" . esc_attr( $type ) . "' />";
  1408 
  1504 
  1409 	$form_fields = get_attachment_fields_to_edit( $post, $r['errors'] );
  1505 	$form_fields = get_attachment_fields_to_edit( $post, $r['errors'] );
  1410 
  1506 
  1411 	if ( $r['toggle'] ) {
  1507 	if ( $r['toggle'] ) {
  1412 		$class = empty( $r['errors'] ) ? 'startclosed' : 'startopen';
  1508 		$class        = empty( $r['errors'] ) ? 'startclosed' : 'startopen';
  1413 		$toggle_links = "
  1509 		$toggle_links = "
  1414 	<a class='toggle describe-toggle-on' href='#'>$toggle_on</a>
  1510 	<a class='toggle describe-toggle-on' href='#'>$toggle_on</a>
  1415 	<a class='toggle describe-toggle-off' href='#'>$toggle_off</a>";
  1511 	<a class='toggle describe-toggle-off' href='#'>$toggle_off</a>";
  1416 	} else {
  1512 	} else {
  1417 		$class = '';
  1513 		$class        = '';
  1418 		$toggle_links = '';
  1514 		$toggle_links = '';
  1419 	}
  1515 	}
  1420 
  1516 
  1421 	$display_title = ( !empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case
  1517 	$display_title = ( ! empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case
  1422 	$display_title = $r['show_title'] ? "<div class='filename new'><span class='title'>" . wp_html_excerpt( $display_title, 60, '&hellip;' ) . "</span></div>" : '';
  1518 	$display_title = $r['show_title'] ? "<div class='filename new'><span class='title'>" . wp_html_excerpt( $display_title, 60, '&hellip;' ) . '</span></div>' : '';
  1423 
  1519 
  1424 	$gallery = ( ( isset( $_REQUEST['tab'] ) && 'gallery' == $_REQUEST['tab'] ) || ( isset( $redir_tab ) && 'gallery' == $redir_tab ) );
  1520 	$gallery = ( ( isset( $_REQUEST['tab'] ) && 'gallery' == $_REQUEST['tab'] ) || ( isset( $redir_tab ) && 'gallery' == $redir_tab ) );
  1425 	$order = '';
  1521 	$order   = '';
  1426 
  1522 
  1427 	foreach ( $form_fields as $key => $val ) {
  1523 	foreach ( $form_fields as $key => $val ) {
  1428 		if ( 'menu_order' == $key ) {
  1524 		if ( 'menu_order' == $key ) {
  1429 			if ( $gallery )
  1525 			if ( $gallery ) {
  1430 				$order = "<div class='menu_order'> <input class='menu_order_input' type='text' id='attachments[$attachment_id][menu_order]' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $val['value'] ). "' /></div>";
  1526 				$order = "<div class='menu_order'> <input class='menu_order_input' type='text' id='attachments[$attachment_id][menu_order]' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $val['value'] ) . "' /></div>";
  1431 			else
  1527 			} else {
  1432 				$order = "<input type='hidden' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $val['value'] ) . "' />";
  1528 				$order = "<input type='hidden' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $val['value'] ) . "' />";
       
  1529 			}
  1433 
  1530 
  1434 			unset( $form_fields['menu_order'] );
  1531 			unset( $form_fields['menu_order'] );
  1435 			break;
  1532 			break;
  1436 		}
  1533 		}
  1437 	}
  1534 	}
  1438 
  1535 
  1439 	$media_dims = '';
  1536 	$media_dims = '';
  1440 	$meta = wp_get_attachment_metadata( $post->ID );
  1537 	$meta       = wp_get_attachment_metadata( $post->ID );
  1441 	if ( isset( $meta['width'], $meta['height'] ) )
  1538 	if ( isset( $meta['width'], $meta['height'] ) ) {
  1442 		$media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']}&nbsp;&times;&nbsp;{$meta['height']}</span> ";
  1539 		$media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']}&nbsp;&times;&nbsp;{$meta['height']}</span> ";
       
  1540 	}
  1443 
  1541 
  1444 	/**
  1542 	/**
  1445 	 * Filters the media metadata.
  1543 	 * Filters the media metadata.
  1446 	 *
  1544 	 *
  1447 	 * @since 2.5.0
  1545 	 * @since 2.5.0
  1451 	 */
  1549 	 */
  1452 	$media_dims = apply_filters( 'media_meta', $media_dims, $post );
  1550 	$media_dims = apply_filters( 'media_meta', $media_dims, $post );
  1453 
  1551 
  1454 	$image_edit_button = '';
  1552 	$image_edit_button = '';
  1455 	if ( wp_attachment_is_image( $post->ID ) && wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) {
  1553 	if ( wp_attachment_is_image( $post->ID ) && wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) {
  1456 		$nonce = wp_create_nonce( "image_editor-$post->ID" );
  1554 		$nonce             = wp_create_nonce( "image_editor-$post->ID" );
  1457 		$image_edit_button = "<input type='button' id='imgedit-open-btn-$post->ID' onclick='imageEdit.open( $post->ID, \"$nonce\" )' class='button' value='" . esc_attr__( 'Edit Image' ) . "' /> <span class='spinner'></span>";
  1555 		$image_edit_button = "<input type='button' id='imgedit-open-btn-$post->ID' onclick='imageEdit.open( $post->ID, \"$nonce\" )' class='button' value='" . esc_attr__( 'Edit Image' ) . "' /> <span class='spinner'></span>";
  1458 	}
  1556 	}
  1459 
  1557 
  1460 	$attachment_url = get_permalink( $attachment_id );
  1558 	$attachment_url = get_permalink( $attachment_id );
  1461 
  1559 
  1470 			<td class='A1B1' id='thumbnail-head-$post->ID'>
  1568 			<td class='A1B1' id='thumbnail-head-$post->ID'>
  1471 			<p><a href='$attachment_url' target='_blank'><img class='thumbnail' src='$thumb_url' alt='' /></a></p>
  1569 			<p><a href='$attachment_url' target='_blank'><img class='thumbnail' src='$thumb_url' alt='' /></a></p>
  1472 			<p>$image_edit_button</p>
  1570 			<p>$image_edit_button</p>
  1473 			</td>
  1571 			</td>
  1474 			<td>
  1572 			<td>
  1475 			<p><strong>" . __('File name:') . "</strong> $filename</p>
  1573 			<p><strong>" . __( 'File name:' ) . "</strong> $filename</p>
  1476 			<p><strong>" . __('File type:') . "</strong> $post->post_mime_type</p>
  1574 			<p><strong>" . __( 'File type:' ) . "</strong> $post->post_mime_type</p>
  1477 			<p><strong>" . __('Upload date:') . "</strong> " . mysql2date( __( 'F j, Y' ), $post->post_date ). '</p>';
  1575 			<p><strong>" . __( 'Upload date:' ) . '</strong> ' . mysql2date( __( 'F j, Y' ), $post->post_date ) . '</p>';
  1478 			if ( !empty( $media_dims ) )
  1576 	if ( ! empty( $media_dims ) ) {
  1479 				$item .= "<p><strong>" . __('Dimensions:') . "</strong> $media_dims</p>\n";
  1577 		$item .= '<p><strong>' . __( 'Dimensions:' ) . "</strong> $media_dims</p>\n";
       
  1578 	}
  1480 
  1579 
  1481 			$item .= "</td></tr>\n";
  1580 			$item .= "</td></tr>\n";
  1482 
  1581 
  1483 	$item .= "
  1582 	$item .= "
  1484 		</thead>
  1583 		</thead>
  1498 		$r['send'] = get_submit_button( __( 'Insert into Post' ), '', "send[$attachment_id]", false );
  1597 		$r['send'] = get_submit_button( __( 'Insert into Post' ), '', "send[$attachment_id]", false );
  1499 	}
  1598 	}
  1500 
  1599 
  1501 	$delete = empty( $r['delete'] ) ? '' : $r['delete'];
  1600 	$delete = empty( $r['delete'] ) ? '' : $r['delete'];
  1502 	if ( $delete && current_user_can( 'delete_post', $attachment_id ) ) {
  1601 	if ( $delete && current_user_can( 'delete_post', $attachment_id ) ) {
  1503 		if ( !EMPTY_TRASH_DAYS ) {
  1602 		if ( ! EMPTY_TRASH_DAYS ) {
  1504 			$delete = "<a href='" . wp_nonce_url( "post.php?action=delete&amp;post=$attachment_id", 'delete-post_' . $attachment_id ) . "' id='del[$attachment_id]' class='delete-permanently'>" . __( 'Delete Permanently' ) . '</a>';
  1603 			$delete = "<a href='" . wp_nonce_url( "post.php?action=delete&amp;post=$attachment_id", 'delete-post_' . $attachment_id ) . "' id='del[$attachment_id]' class='delete-permanently'>" . __( 'Delete Permanently' ) . '</a>';
  1505 		} elseif ( !MEDIA_TRASH ) {
  1604 		} elseif ( ! MEDIA_TRASH ) {
  1506 			$delete = "<a href='#' class='del-link' onclick=\"document.getElementById('del_attachment_$attachment_id').style.display='block';return false;\">" . __( 'Delete' ) . "</a>
  1605 			$delete = "<a href='#' class='del-link' onclick=\"document.getElementById('del_attachment_$attachment_id').style.display='block';return false;\">" . __( 'Delete' ) . "</a>
  1507 			 <div id='del_attachment_$attachment_id' class='del-attachment' style='display:none;'>" .
  1606 				<div id='del_attachment_$attachment_id' class='del-attachment' style='display:none;'>" .
  1508 			 /* translators: %s: file name */
  1607 				/* translators: %s: file name */
  1509 			'<p>' . sprintf( __( 'You are about to delete %s.' ), '<strong>' . $filename . '</strong>' ) . "</p>
  1608 				'<p>' . sprintf( __( 'You are about to delete %s.' ), '<strong>' . $filename . '</strong>' ) . "</p>
  1510 			 <a href='" . wp_nonce_url( "post.php?action=delete&amp;post=$attachment_id", 'delete-post_' . $attachment_id ) . "' id='del[$attachment_id]' class='button'>" . __( 'Continue' ) . "</a>
  1609 				<a href='" . wp_nonce_url( "post.php?action=delete&amp;post=$attachment_id", 'delete-post_' . $attachment_id ) . "' id='del[$attachment_id]' class='button'>" . __( 'Continue' ) . "</a>
  1511 			 <a href='#' class='button' onclick=\"this.parentNode.style.display='none';return false;\">" . __( 'Cancel' ) . "</a>
  1610 				<a href='#' class='button' onclick=\"this.parentNode.style.display='none';return false;\">" . __( 'Cancel' ) . '</a>
  1512 			 </div>";
  1611 				</div>';
  1513 		} else {
  1612 		} else {
  1514 			$delete = "<a href='" . wp_nonce_url( "post.php?action=trash&amp;post=$attachment_id", 'trash-post_' . $attachment_id ) . "' id='del[$attachment_id]' class='delete'>" . __( 'Move to Trash' ) . "</a>
  1613 			$delete = "<a href='" . wp_nonce_url( "post.php?action=trash&amp;post=$attachment_id", 'trash-post_' . $attachment_id ) . "' id='del[$attachment_id]' class='delete'>" . __( 'Move to Trash' ) . "</a>
  1515 			<a href='" . wp_nonce_url( "post.php?action=untrash&amp;post=$attachment_id", 'untrash-post_' . $attachment_id ) . "' id='undo[$attachment_id]' class='undo hidden'>" . __( 'Undo' ) . "</a>";
  1614 			<a href='" . wp_nonce_url( "post.php?action=untrash&amp;post=$attachment_id", 'untrash-post_' . $attachment_id ) . "' id='undo[$attachment_id]' class='undo hidden'>" . __( 'Undo' ) . '</a>';
  1516 		}
  1615 		}
  1517 	} else {
  1616 	} else {
  1518 		$delete = '';
  1617 		$delete = '';
  1519 	}
  1618 	}
  1520 
  1619 
  1521 	$thumbnail = '';
  1620 	$thumbnail       = '';
  1522 	$calling_post_id = 0;
  1621 	$calling_post_id = 0;
  1523 	if ( isset( $_GET['post_id'] ) ) {
  1622 	if ( isset( $_GET['post_id'] ) ) {
  1524 		$calling_post_id = absint( $_GET['post_id'] );
  1623 		$calling_post_id = absint( $_GET['post_id'] );
  1525 	} elseif ( isset( $_POST ) && count( $_POST ) ) {// Like for async-upload where $_GET['post_id'] isn't set
  1624 	} elseif ( isset( $_POST ) && count( $_POST ) ) {// Like for async-upload where $_GET['post_id'] isn't set
  1526 		$calling_post_id = $post->post_parent;
  1625 		$calling_post_id = $post->post_parent;
  1527 	}
  1626 	}
  1528 	if ( 'image' == $type && $calling_post_id && current_theme_supports( 'post-thumbnails', get_post_type( $calling_post_id ) )
  1627 	if ( 'image' == $type && $calling_post_id && current_theme_supports( 'post-thumbnails', get_post_type( $calling_post_id ) )
  1529 		&& post_type_supports( get_post_type( $calling_post_id ), 'thumbnail' ) && get_post_thumbnail_id( $calling_post_id ) != $attachment_id ) {
  1628 		&& post_type_supports( get_post_type( $calling_post_id ), 'thumbnail' ) && get_post_thumbnail_id( $calling_post_id ) != $attachment_id ) {
  1530 
  1629 
  1531 		$calling_post = get_post( $calling_post_id );
  1630 		$calling_post             = get_post( $calling_post_id );
  1532 		$calling_post_type_object = get_post_type_object( $calling_post->post_type );
  1631 		$calling_post_type_object = get_post_type_object( $calling_post->post_type );
  1533 
  1632 
  1534 		$ajax_nonce = wp_create_nonce( "set_post_thumbnail-$calling_post_id" );
  1633 		$ajax_nonce = wp_create_nonce( "set_post_thumbnail-$calling_post_id" );
  1535 		$thumbnail = "<a class='wp-post-thumbnail' id='wp-post-thumbnail-" . $attachment_id . "' href='#' onclick='WPSetAsThumbnail(\"$attachment_id\", \"$ajax_nonce\");return false;'>" . esc_html( $calling_post_type_object->labels->use_featured_image ) . "</a>";
  1634 		$thumbnail  = "<a class='wp-post-thumbnail' id='wp-post-thumbnail-" . $attachment_id . "' href='#' onclick='WPSetAsThumbnail(\"$attachment_id\", \"$ajax_nonce\");return false;'>" . esc_html( $calling_post_type_object->labels->use_featured_image ) . '</a>';
  1536 	}
  1635 	}
  1537 
  1636 
  1538 	if ( ( $r['send'] || $thumbnail || $delete ) && !isset( $form_fields['buttons'] ) ) {
  1637 	if ( ( $r['send'] || $thumbnail || $delete ) && ! isset( $form_fields['buttons'] ) ) {
  1539 		$form_fields['buttons'] = array( 'tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>" . $r['send'] . " $thumbnail $delete</td></tr>\n" );
  1638 		$form_fields['buttons'] = array( 'tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>" . $r['send'] . " $thumbnail $delete</td></tr>\n" );
  1540 	}
  1639 	}
  1541 	$hidden_fields = array();
  1640 	$hidden_fields = array();
  1542 
  1641 
  1543 	foreach ( $form_fields as $id => $field ) {
  1642 	foreach ( $form_fields as $id => $field ) {
  1544 		if ( $id[0] == '_' )
  1643 		if ( $id[0] == '_' ) {
  1545 			continue;
  1644 			continue;
  1546 
  1645 		}
  1547 		if ( !empty( $field['tr'] ) ) {
  1646 
       
  1647 		if ( ! empty( $field['tr'] ) ) {
  1548 			$item .= $field['tr'];
  1648 			$item .= $field['tr'];
  1549 			continue;
  1649 			continue;
  1550 		}
  1650 		}
  1551 
  1651 
  1552 		$field = array_merge( $defaults, $field );
  1652 		$field = array_merge( $defaults, $field );
  1553 		$name = "attachments[$attachment_id][$id]";
  1653 		$name  = "attachments[$attachment_id][$id]";
  1554 
  1654 
  1555 		if ( $field['input'] == 'hidden' ) {
  1655 		if ( $field['input'] == 'hidden' ) {
  1556 			$hidden_fields[$name] = $field['value'];
  1656 			$hidden_fields[ $name ] = $field['value'];
  1557 			continue;
  1657 			continue;
  1558 		}
  1658 		}
  1559 
  1659 
  1560 		$required      = $field['required'] ? '<span class="required">*</span>' : '';
  1660 		$required      = $field['required'] ? '<span class="required">*</span>' : '';
  1561 		$required_attr = $field['required'] ? ' required' : '';
  1661 		$required_attr = $field['required'] ? ' required' : '';
  1562 		$aria_required = $field['required'] ? " aria-required='true'" : '';
  1662 		$class         = $id;
  1563 		$class  = $id;
  1663 		$class        .= $field['required'] ? ' form-required' : '';
  1564 		$class .= $field['required'] ? ' form-required' : '';
       
  1565 
  1664 
  1566 		$item .= "\t\t<tr class='$class'>\n\t\t\t<th scope='row' class='label'><label for='$name'><span class='alignleft'>{$field['label']}{$required}</span><br class='clear' /></label></th>\n\t\t\t<td class='field'>";
  1665 		$item .= "\t\t<tr class='$class'>\n\t\t\t<th scope='row' class='label'><label for='$name'><span class='alignleft'>{$field['label']}{$required}</span><br class='clear' /></label></th>\n\t\t\t<td class='field'>";
  1567 		if ( !empty( $field[ $field['input'] ] ) )
  1666 		if ( ! empty( $field[ $field['input'] ] ) ) {
  1568 			$item .= $field[ $field['input'] ];
  1667 			$item .= $field[ $field['input'] ];
  1569 		elseif ( $field['input'] == 'textarea' ) {
  1668 		} elseif ( $field['input'] == 'textarea' ) {
  1570 			if ( 'post_content' == $id && user_can_richedit() ) {
  1669 			if ( 'post_content' == $id && user_can_richedit() ) {
  1571 				// Sanitize_post() skips the post_content when user_can_richedit.
  1670 				// Sanitize_post() skips the post_content when user_can_richedit.
  1572 				$field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES );
  1671 				$field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES );
  1573 			}
  1672 			}
  1574 			// Post_excerpt is already escaped by sanitize_post() in get_attachment_fields_to_edit().
  1673 			// Post_excerpt is already escaped by sanitize_post() in get_attachment_fields_to_edit().
  1575 			$item .= "<textarea id='$name' name='$name'{$required_attr}{$aria_required}>" . $field['value'] . '</textarea>';
  1674 			$item .= "<textarea id='$name' name='$name'{$required_attr}>" . $field['value'] . '</textarea>';
  1576 		} else {
  1675 		} else {
  1577 			$item .= "<input type='text' class='text' id='$name' name='$name' value='" . esc_attr( $field['value'] ) . "'{$required_attr}{$aria_required} />";
  1676 			$item .= "<input type='text' class='text' id='$name' name='$name' value='" . esc_attr( $field['value'] ) . "'{$required_attr} />";
  1578 		}
  1677 		}
  1579 		if ( !empty( $field['helps'] ) )
  1678 		if ( ! empty( $field['helps'] ) ) {
  1580 			$item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>';
  1679 			$item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>';
       
  1680 		}
  1581 		$item .= "</td>\n\t\t</tr>\n";
  1681 		$item .= "</td>\n\t\t</tr>\n";
  1582 
  1682 
  1583 		$extra_rows = array();
  1683 		$extra_rows = array();
  1584 
  1684 
  1585 		if ( !empty( $field['errors'] ) )
  1685 		if ( ! empty( $field['errors'] ) ) {
  1586 			foreach ( array_unique( (array) $field['errors'] ) as $error )
  1686 			foreach ( array_unique( (array) $field['errors'] ) as $error ) {
  1587 				$extra_rows['error'][] = $error;
  1687 				$extra_rows['error'][] = $error;
  1588 
  1688 			}
  1589 		if ( !empty( $field['extra_rows'] ) )
  1689 		}
  1590 			foreach ( $field['extra_rows'] as $class => $rows )
  1690 
  1591 				foreach ( (array) $rows as $html )
  1691 		if ( ! empty( $field['extra_rows'] ) ) {
  1592 					$extra_rows[$class][] = $html;
  1692 			foreach ( $field['extra_rows'] as $class => $rows ) {
  1593 
  1693 				foreach ( (array) $rows as $html ) {
  1594 		foreach ( $extra_rows as $class => $rows )
  1694 					$extra_rows[ $class ][] = $html;
  1595 			foreach ( $rows as $html )
  1695 				}
       
  1696 			}
       
  1697 		}
       
  1698 
       
  1699 		foreach ( $extra_rows as $class => $rows ) {
       
  1700 			foreach ( $rows as $html ) {
  1596 				$item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n";
  1701 				$item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n";
  1597 	}
  1702 			}
  1598 
  1703 		}
  1599 	if ( !empty( $form_fields['_final'] ) )
  1704 	}
       
  1705 
       
  1706 	if ( ! empty( $form_fields['_final'] ) ) {
  1600 		$item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n";
  1707 		$item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n";
       
  1708 	}
  1601 	$item .= "\t</tbody>\n";
  1709 	$item .= "\t</tbody>\n";
  1602 	$item .= "\t</table>\n";
  1710 	$item .= "\t</table>\n";
  1603 
  1711 
  1604 	foreach ( $hidden_fields as $name => $value )
  1712 	foreach ( $hidden_fields as $name => $value ) {
  1605 		$item .= "\t<input type='hidden' name='$name' id='$name' value='" . esc_attr( $value ) . "' />\n";
  1713 		$item .= "\t<input type='hidden' name='$name' id='$name' value='" . esc_attr( $value ) . "' />\n";
       
  1714 	}
  1606 
  1715 
  1607 	if ( $post->post_parent < 1 && isset( $_REQUEST['post_id'] ) ) {
  1716 	if ( $post->post_parent < 1 && isset( $_REQUEST['post_id'] ) ) {
  1608 		$parent = (int) $_REQUEST['post_id'];
  1717 		$parent      = (int) $_REQUEST['post_id'];
  1609 		$parent_name = "attachments[$attachment_id][post_parent]";
  1718 		$parent_name = "attachments[$attachment_id][post_parent]";
  1610 		$item .= "\t<input type='hidden' name='$parent_name' id='$parent_name' value='$parent' />\n";
  1719 		$item       .= "\t<input type='hidden' name='$parent_name' id='$parent_name' value='$parent' />\n";
  1611 	}
  1720 	}
  1612 
  1721 
  1613 	return $item;
  1722 	return $item;
  1614 }
  1723 }
  1615 
  1724 
  1622  */
  1731  */
  1623 function get_compat_media_markup( $attachment_id, $args = null ) {
  1732 function get_compat_media_markup( $attachment_id, $args = null ) {
  1624 	$post = get_post( $attachment_id );
  1733 	$post = get_post( $attachment_id );
  1625 
  1734 
  1626 	$default_args = array(
  1735 	$default_args = array(
  1627 		'errors' => null,
  1736 		'errors'   => null,
  1628 		'in_modal' => false,
  1737 		'in_modal' => false,
  1629 	);
  1738 	);
  1630 
  1739 
  1631 	$user_can_edit = current_user_can( 'edit_post', $attachment_id );
  1740 	$user_can_edit = current_user_can( 'edit_post', $attachment_id );
  1632 
  1741 
  1636 	$args = apply_filters( 'get_media_item_args', $args );
  1745 	$args = apply_filters( 'get_media_item_args', $args );
  1637 
  1746 
  1638 	$form_fields = array();
  1747 	$form_fields = array();
  1639 
  1748 
  1640 	if ( $args['in_modal'] ) {
  1749 	if ( $args['in_modal'] ) {
  1641 		foreach ( get_attachment_taxonomies($post) as $taxonomy ) {
  1750 		foreach ( get_attachment_taxonomies( $post ) as $taxonomy ) {
  1642 			$t = (array) get_taxonomy($taxonomy);
  1751 			$t = (array) get_taxonomy( $taxonomy );
  1643 			if ( ! $t['public'] || ! $t['show_ui'] )
  1752 			if ( ! $t['public'] || ! $t['show_ui'] ) {
  1644 				continue;
  1753 				continue;
  1645 			if ( empty($t['label']) )
  1754 			}
       
  1755 			if ( empty( $t['label'] ) ) {
  1646 				$t['label'] = $taxonomy;
  1756 				$t['label'] = $taxonomy;
  1647 			if ( empty($t['args']) )
  1757 			}
       
  1758 			if ( empty( $t['args'] ) ) {
  1648 				$t['args'] = array();
  1759 				$t['args'] = array();
  1649 
  1760 			}
  1650 			$terms = get_object_term_cache($post->ID, $taxonomy);
  1761 
  1651 			if ( false === $terms )
  1762 			$terms = get_object_term_cache( $post->ID, $taxonomy );
  1652 				$terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
  1763 			if ( false === $terms ) {
       
  1764 				$terms = wp_get_object_terms( $post->ID, $taxonomy, $t['args'] );
       
  1765 			}
  1653 
  1766 
  1654 			$values = array();
  1767 			$values = array();
  1655 
  1768 
  1656 			foreach ( $terms as $term )
  1769 			foreach ( $terms as $term ) {
  1657 				$values[] = $term->slug;
  1770 				$values[] = $term->slug;
  1658 			$t['value'] = join(', ', $values);
  1771 			}
       
  1772 			$t['value']    = join( ', ', $values );
  1659 			$t['taxonomy'] = true;
  1773 			$t['taxonomy'] = true;
  1660 
  1774 
  1661 			$form_fields[$taxonomy] = $t;
  1775 			$form_fields[ $taxonomy ] = $t;
  1662 		}
  1776 		}
  1663 	}
  1777 	}
  1664 
  1778 
  1665 	// Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default
  1779 	// Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default
  1666 	// The recursive merge is easily traversed with array casting: foreach ( (array) $things as $thing )
  1780 	// The recursive merge is easily traversed with array casting: foreach ( (array) $things as $thing )
  1667 	$form_fields = array_merge_recursive($form_fields, (array) $args['errors'] );
  1781 	$form_fields = array_merge_recursive( $form_fields, (array) $args['errors'] );
  1668 
  1782 
  1669 	/** This filter is documented in wp-admin/includes/media.php */
  1783 	/** This filter is documented in wp-admin/includes/media.php */
  1670 	$form_fields = apply_filters( 'attachment_fields_to_edit', $form_fields, $post );
  1784 	$form_fields = apply_filters( 'attachment_fields_to_edit', $form_fields, $post );
  1671 
  1785 
  1672 	unset( $form_fields['image-size'], $form_fields['align'], $form_fields['image_alt'],
  1786 	unset(
  1673 		$form_fields['post_title'], $form_fields['post_excerpt'], $form_fields['post_content'],
  1787 		$form_fields['image-size'],
  1674 		$form_fields['url'], $form_fields['menu_order'], $form_fields['image_url'] );
  1788 		$form_fields['align'],
       
  1789 		$form_fields['image_alt'],
       
  1790 		$form_fields['post_title'],
       
  1791 		$form_fields['post_excerpt'],
       
  1792 		$form_fields['post_content'],
       
  1793 		$form_fields['url'],
       
  1794 		$form_fields['menu_order'],
       
  1795 		$form_fields['image_url']
       
  1796 	);
  1675 
  1797 
  1676 	/** This filter is documented in wp-admin/includes/media.php */
  1798 	/** This filter is documented in wp-admin/includes/media.php */
  1677 	$media_meta = apply_filters( 'media_meta', '', $post );
  1799 	$media_meta = apply_filters( 'media_meta', '', $post );
  1678 
  1800 
  1679 	$defaults = array(
  1801 	$defaults = array(
  1687 
  1809 
  1688 	$hidden_fields = array();
  1810 	$hidden_fields = array();
  1689 
  1811 
  1690 	$item = '';
  1812 	$item = '';
  1691 	foreach ( $form_fields as $id => $field ) {
  1813 	foreach ( $form_fields as $id => $field ) {
  1692 		if ( $id[0] == '_' )
  1814 		if ( $id[0] == '_' ) {
  1693 			continue;
  1815 			continue;
  1694 
  1816 		}
  1695 		$name = "attachments[$attachment_id][$id]";
  1817 
       
  1818 		$name    = "attachments[$attachment_id][$id]";
  1696 		$id_attr = "attachments-$attachment_id-$id";
  1819 		$id_attr = "attachments-$attachment_id-$id";
  1697 
  1820 
  1698 		if ( !empty( $field['tr'] ) ) {
  1821 		if ( ! empty( $field['tr'] ) ) {
  1699 			$item .= $field['tr'];
  1822 			$item .= $field['tr'];
  1700 			continue;
  1823 			continue;
  1701 		}
  1824 		}
  1702 
  1825 
  1703 		$field = array_merge( $defaults, $field );
  1826 		$field = array_merge( $defaults, $field );
  1704 
  1827 
  1705 		if ( ( ! $field['show_in_edit'] && ! $args['in_modal'] ) || ( ! $field['show_in_modal'] && $args['in_modal'] ) )
  1828 		if ( ( ! $field['show_in_edit'] && ! $args['in_modal'] ) || ( ! $field['show_in_modal'] && $args['in_modal'] ) ) {
  1706 			continue;
  1829 			continue;
       
  1830 		}
  1707 
  1831 
  1708 		if ( $field['input'] == 'hidden' ) {
  1832 		if ( $field['input'] == 'hidden' ) {
  1709 			$hidden_fields[$name] = $field['value'];
  1833 			$hidden_fields[ $name ] = $field['value'];
  1710 			continue;
  1834 			continue;
  1711 		}
  1835 		}
  1712 
  1836 
  1713 		$readonly      = ! $user_can_edit && ! empty( $field['taxonomy'] ) ? " readonly='readonly' " : '';
  1837 		$readonly      = ! $user_can_edit && ! empty( $field['taxonomy'] ) ? " readonly='readonly' " : '';
  1714 		$required      = $field['required'] ? '<span class="required">*</span>' : '';
  1838 		$required      = $field['required'] ? '<span class="required">*</span>' : '';
  1715 		$required_attr = $field['required'] ? ' required' : '';
  1839 		$required_attr = $field['required'] ? ' required' : '';
  1716 		$aria_required = $field['required'] ? " aria-required='true'" : '';
  1840 		$class         = 'compat-field-' . $id;
  1717 		$class  = 'compat-field-' . $id;
  1841 		$class        .= $field['required'] ? ' form-required' : '';
  1718 		$class .= $field['required'] ? ' form-required' : '';
       
  1719 
  1842 
  1720 		$item .= "\t\t<tr class='$class'>";
  1843 		$item .= "\t\t<tr class='$class'>";
  1721 		$item .= "\t\t\t<th scope='row' class='label'><label for='$id_attr'><span class='alignleft'>{$field['label']}</span>$required<br class='clear' /></label>";
  1844 		$item .= "\t\t\t<th scope='row' class='label'><label for='$id_attr'><span class='alignleft'>{$field['label']}</span>$required<br class='clear' /></label>";
  1722 		$item .= "</th>\n\t\t\t<td class='field'>";
  1845 		$item .= "</th>\n\t\t\t<td class='field'>";
  1723 
  1846 
  1724 		if ( !empty( $field[ $field['input'] ] ) )
  1847 		if ( ! empty( $field[ $field['input'] ] ) ) {
  1725 			$item .= $field[ $field['input'] ];
  1848 			$item .= $field[ $field['input'] ];
  1726 		elseif ( $field['input'] == 'textarea' ) {
  1849 		} elseif ( $field['input'] == 'textarea' ) {
  1727 			if ( 'post_content' == $id && user_can_richedit() ) {
  1850 			if ( 'post_content' == $id && user_can_richedit() ) {
  1728 				// sanitize_post() skips the post_content when user_can_richedit.
  1851 				// sanitize_post() skips the post_content when user_can_richedit.
  1729 				$field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES );
  1852 				$field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES );
  1730 			}
  1853 			}
  1731 			$item .= "<textarea id='$id_attr' name='$name'{$required_attr}{$aria_required}>" . $field['value'] . '</textarea>';
  1854 			$item .= "<textarea id='$id_attr' name='$name'{$required_attr}>" . $field['value'] . '</textarea>';
  1732 		} else {
  1855 		} else {
  1733 			$item .= "<input type='text' class='text' id='$id_attr' name='$name' value='" . esc_attr( $field['value'] ) . "' $readonly{$required_attr}{$aria_required} />";
  1856 			$item .= "<input type='text' class='text' id='$id_attr' name='$name' value='" . esc_attr( $field['value'] ) . "' $readonly{$required_attr} />";
  1734 		}
  1857 		}
  1735 		if ( !empty( $field['helps'] ) )
  1858 		if ( ! empty( $field['helps'] ) ) {
  1736 			$item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>';
  1859 			$item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>';
       
  1860 		}
  1737 		$item .= "</td>\n\t\t</tr>\n";
  1861 		$item .= "</td>\n\t\t</tr>\n";
  1738 
  1862 
  1739 		$extra_rows = array();
  1863 		$extra_rows = array();
  1740 
  1864 
  1741 		if ( !empty( $field['errors'] ) )
  1865 		if ( ! empty( $field['errors'] ) ) {
  1742 			foreach ( array_unique( (array) $field['errors'] ) as $error )
  1866 			foreach ( array_unique( (array) $field['errors'] ) as $error ) {
  1743 				$extra_rows['error'][] = $error;
  1867 				$extra_rows['error'][] = $error;
  1744 
  1868 			}
  1745 		if ( !empty( $field['extra_rows'] ) )
  1869 		}
  1746 			foreach ( $field['extra_rows'] as $class => $rows )
  1870 
  1747 				foreach ( (array) $rows as $html )
  1871 		if ( ! empty( $field['extra_rows'] ) ) {
  1748 					$extra_rows[$class][] = $html;
  1872 			foreach ( $field['extra_rows'] as $class => $rows ) {
  1749 
  1873 				foreach ( (array) $rows as $html ) {
  1750 		foreach ( $extra_rows as $class => $rows )
  1874 					$extra_rows[ $class ][] = $html;
  1751 			foreach ( $rows as $html )
  1875 				}
       
  1876 			}
       
  1877 		}
       
  1878 
       
  1879 		foreach ( $extra_rows as $class => $rows ) {
       
  1880 			foreach ( $rows as $html ) {
  1752 				$item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n";
  1881 				$item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n";
  1753 	}
  1882 			}
  1754 
  1883 		}
  1755 	if ( !empty( $form_fields['_final'] ) )
  1884 	}
       
  1885 
       
  1886 	if ( ! empty( $form_fields['_final'] ) ) {
  1756 		$item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n";
  1887 		$item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n";
       
  1888 	}
  1757 
  1889 
  1758 	if ( $item ) {
  1890 	if ( $item ) {
  1759 		$item = '<p class="media-types media-types-required-info">' .
  1891 		$item = '<p class="media-types media-types-required-info">' .
  1760 			sprintf( __( 'Required fields are marked %s' ), '<span class="required">*</span>' ) . '</p>
  1892 			sprintf( __( 'Required fields are marked %s' ), '<span class="required">*</span>' ) . '</p>
  1761 			<table class="compat-attachment-fields">' . $item . '</table>';
  1893 			<table class="compat-attachment-fields">' . $item . '</table>';
  1763 
  1895 
  1764 	foreach ( $hidden_fields as $hidden_field => $value ) {
  1896 	foreach ( $hidden_fields as $hidden_field => $value ) {
  1765 		$item .= '<input type="hidden" name="' . esc_attr( $hidden_field ) . '" value="' . esc_attr( $value ) . '" />' . "\n";
  1897 		$item .= '<input type="hidden" name="' . esc_attr( $hidden_field ) . '" value="' . esc_attr( $value ) . '" />' . "\n";
  1766 	}
  1898 	}
  1767 
  1899 
  1768 	if ( $item )
  1900 	if ( $item ) {
  1769 		$item = '<input type="hidden" name="attachments[' . $attachment_id . '][menu_order]" value="' . esc_attr( $post->menu_order ) . '" />' . $item;
  1901 		$item = '<input type="hidden" name="attachments[' . $attachment_id . '][menu_order]" value="' . esc_attr( $post->menu_order ) . '" />' . $item;
       
  1902 	}
  1770 
  1903 
  1771 	return array(
  1904 	return array(
  1772 		'item'   => $item,
  1905 		'item' => $item,
  1773 		'meta'   => $media_meta,
  1906 		'meta' => $media_meta,
  1774 	);
  1907 	);
  1775 }
  1908 }
  1776 
  1909 
  1777 /**
  1910 /**
  1778  * Outputs the legacy media upload header.
  1911  * Outputs the legacy media upload header.
  1804  */
  1937  */
  1805 function media_upload_form( $errors = null ) {
  1938 function media_upload_form( $errors = null ) {
  1806 	global $type, $tab, $is_IE, $is_opera;
  1939 	global $type, $tab, $is_IE, $is_opera;
  1807 
  1940 
  1808 	if ( ! _device_can_upload() ) {
  1941 	if ( ! _device_can_upload() ) {
  1809 		echo '<p>' . sprintf( __('The web browser on your device cannot be used to upload files. You may be able to use the <a href="%s">native app for your device</a> instead.'), 'https://apps.wordpress.org/' ) . '</p>';
  1942 		echo '<p>' . sprintf( __( 'The web browser on your device cannot be used to upload files. You may be able to use the <a href="%s">native app for your device</a> instead.' ), 'https://apps.wordpress.org/' ) . '</p>';
  1810 		return;
  1943 		return;
  1811 	}
  1944 	}
  1812 
  1945 
  1813 	$upload_action_url = admin_url('async-upload.php');
  1946 	$upload_action_url = admin_url( 'async-upload.php' );
  1814 	$post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0;
  1947 	$post_id           = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0;
  1815 	$_type = isset($type) ? $type : '';
  1948 	$_type             = isset( $type ) ? $type : '';
  1816 	$_tab = isset($tab) ? $tab : '';
  1949 	$_tab              = isset( $tab ) ? $tab : '';
  1817 
  1950 
  1818 	$max_upload_size = wp_max_upload_size();
  1951 	$max_upload_size = wp_max_upload_size();
  1819 	if ( ! $max_upload_size ) {
  1952 	if ( ! $max_upload_size ) {
  1820 		$max_upload_size = 0;
  1953 		$max_upload_size = 0;
  1821 	}
  1954 	}
  1822 ?>
  1955 	?>
  1823 
  1956 
  1824 <div id="media-upload-notice"><?php
  1957 <div id="media-upload-notice">
  1825 
  1958 	<?php
  1826 	if (isset($errors['upload_notice']) )
  1959 
       
  1960 	if ( isset( $errors['upload_notice'] ) ) {
  1827 		echo $errors['upload_notice'];
  1961 		echo $errors['upload_notice'];
  1828 
  1962 	}
  1829 ?></div>
  1963 
  1830 <div id="media-upload-error"><?php
  1964 	?>
  1831 
  1965 </div>
  1832 	if (isset($errors['upload_error']) && is_wp_error($errors['upload_error']))
  1966 <div id="media-upload-error">
       
  1967 	<?php
       
  1968 
       
  1969 	if ( isset( $errors['upload_error'] ) && is_wp_error( $errors['upload_error'] ) ) {
  1833 		echo $errors['upload_error']->get_error_message();
  1970 		echo $errors['upload_error']->get_error_message();
  1834 
  1971 	}
  1835 ?></div>
  1972 
  1836 <?php
  1973 	?>
  1837 if ( is_multisite() && !is_upload_space_available() ) {
  1974 </div>
       
  1975 	<?php
       
  1976 	if ( is_multisite() && ! is_upload_space_available() ) {
       
  1977 		/**
       
  1978 		 * Fires when an upload will exceed the defined upload space quota for a network site.
       
  1979 		 *
       
  1980 		 * @since 3.5.0
       
  1981 		 */
       
  1982 		do_action( 'upload_ui_over_quota' );
       
  1983 		return;
       
  1984 	}
       
  1985 
  1838 	/**
  1986 	/**
  1839 	 * Fires when an upload will exceed the defined upload space quota for a network site.
  1987 	 * Fires just before the legacy (pre-3.5.0) upload interface is loaded.
  1840 	 *
  1988 	 *
  1841 	 * @since 3.5.0
  1989 	 * @since 2.6.0
  1842 	 */
  1990 	 */
  1843 	do_action( 'upload_ui_over_quota' );
  1991 	do_action( 'pre-upload-ui' );
  1844 	return;
  1992 
  1845 }
  1993 	$post_params = array(
  1846 
  1994 		'post_id'  => $post_id,
  1847 /**
  1995 		'_wpnonce' => wp_create_nonce( 'media-form' ),
  1848  * Fires just before the legacy (pre-3.5.0) upload interface is loaded.
  1996 		'type'     => $_type,
  1849  *
  1997 		'tab'      => $_tab,
  1850  * @since 2.6.0
  1998 		'short'    => '1',
  1851  */
  1999 	);
  1852 do_action( 'pre-upload-ui' );
  2000 
  1853 
  2001 	/**
  1854 $post_params = array(
  2002 	 * Filters the media upload post parameters.
  1855 	"post_id" => $post_id,
  2003 	 *
  1856 	"_wpnonce" => wp_create_nonce('media-form'),
  2004 	 * @since 3.1.0 As 'swfupload_post_params'
  1857 	"type" => $_type,
  2005 	 * @since 3.3.0
  1858 	"tab" => $_tab,
  2006 	 *
  1859 	"short" => "1",
  2007 	 * @param array $post_params An array of media upload parameters used by Plupload.
  1860 );
  2008 	 */
  1861 
  2009 	$post_params = apply_filters( 'upload_post_params', $post_params );
  1862 /**
  2010 
  1863  * Filters the media upload post parameters.
  2011 	/*
  1864  *
  2012 	* Since 4.9 the `runtimes` setting is hardcoded in our version of Plupload to `html5,html4`,
  1865  * @since 3.1.0 As 'swfupload_post_params'
  2013 	* and the `flash_swf_url` and `silverlight_xap_url` are not used.
  1866  * @since 3.3.0
  2014 	*/
  1867  *
  2015 	$plupload_init = array(
  1868  * @param array $post_params An array of media upload parameters used by Plupload.
  2016 		'browse_button'    => 'plupload-browse-button',
  1869  */
  2017 		'container'        => 'plupload-upload-ui',
  1870 $post_params = apply_filters( 'upload_post_params', $post_params );
  2018 		'drop_element'     => 'drag-drop-area',
  1871 
  2019 		'file_data_name'   => 'async-upload',
  1872 /*
  2020 		'url'              => $upload_action_url,
  1873  * Since 4.9 the `runtimes` setting is hardcoded in our version of Plupload to `html5,html4`,
  2021 		'filters'          => array(
  1874  * and the `flash_swf_url` and `silverlight_xap_url` are not used.
  2022 			'max_file_size' => $max_upload_size . 'b',
  1875  */
  2023 		),
  1876 $plupload_init = array(
  2024 		'multipart_params' => $post_params,
  1877 	'browse_button'       => 'plupload-browse-button',
  2025 	);
  1878 	'container'           => 'plupload-upload-ui',
  2026 
  1879 	'drop_element'        => 'drag-drop-area',
  2027 	// Currently only iOS Safari supports multiple files uploading but iOS 7.x has a bug that prevents uploading of videos
  1880 	'file_data_name'      => 'async-upload',
  2028 	// when enabled. See #29602.
  1881 	'url'                 => $upload_action_url,
  2029 	if ( wp_is_mobile() && strpos( $_SERVER['HTTP_USER_AGENT'], 'OS 7_' ) !== false &&
  1882 	'filters' => array(
       
  1883 		'max_file_size'   => $max_upload_size . 'b',
       
  1884 	),
       
  1885 	'multipart_params'    => $post_params,
       
  1886 );
       
  1887 
       
  1888 // Currently only iOS Safari supports multiple files uploading but iOS 7.x has a bug that prevents uploading of videos
       
  1889 // when enabled. See #29602.
       
  1890 if ( wp_is_mobile() && strpos( $_SERVER['HTTP_USER_AGENT'], 'OS 7_' ) !== false &&
       
  1891 	strpos( $_SERVER['HTTP_USER_AGENT'], 'like Mac OS X' ) !== false ) {
  2030 	strpos( $_SERVER['HTTP_USER_AGENT'], 'like Mac OS X' ) !== false ) {
  1892 
  2031 
  1893 	$plupload_init['multi_selection'] = false;
  2032 		$plupload_init['multi_selection'] = false;
  1894 }
  2033 	}
  1895 
  2034 
  1896 /**
  2035 	/**
  1897  * Filters the default Plupload settings.
  2036 	 * Filters the default Plupload settings.
  1898  *
  2037 	 *
  1899  * @since 3.3.0
  2038 	 * @since 3.3.0
  1900  *
  2039 	 *
  1901  * @param array $plupload_init An array of default settings used by Plupload.
  2040 	 * @param array $plupload_init An array of default settings used by Plupload.
  1902  */
  2041 	 */
  1903 $plupload_init = apply_filters( 'plupload_init', $plupload_init );
  2042 	$plupload_init = apply_filters( 'plupload_init', $plupload_init );
  1904 
  2043 
  1905 ?>
  2044 	?>
  1906 
  2045 
  1907 <script type="text/javascript">
  2046 <script type="text/javascript">
  1908 <?php
  2047 	<?php
  1909 // Verify size is an int. If not return default value.
  2048 	// Verify size is an int. If not return default value.
  1910 $large_size_h = absint( get_option('large_size_h') );
  2049 	$large_size_h = absint( get_option( 'large_size_h' ) );
  1911 if( !$large_size_h )
  2050 	if ( ! $large_size_h ) {
  1912 	$large_size_h = 1024;
  2051 		$large_size_h = 1024;
  1913 $large_size_w = absint( get_option('large_size_w') );
  2052 	}
  1914 if( !$large_size_w )
  2053 	$large_size_w = absint( get_option( 'large_size_w' ) );
  1915 	$large_size_w = 1024;
  2054 	if ( ! $large_size_w ) {
  1916 ?>
  2055 		$large_size_w = 1024;
       
  2056 	}
       
  2057 	?>
  1917 var resize_height = <?php echo $large_size_h; ?>, resize_width = <?php echo $large_size_w; ?>,
  2058 var resize_height = <?php echo $large_size_h; ?>, resize_width = <?php echo $large_size_w; ?>,
  1918 wpUploaderInit = <?php echo wp_json_encode( $plupload_init ); ?>;
  2059 wpUploaderInit = <?php echo wp_json_encode( $plupload_init ); ?>;
  1919 </script>
  2060 </script>
  1920 
  2061 
  1921 <div id="plupload-upload-ui" class="hide-if-no-js">
  2062 <div id="plupload-upload-ui" class="hide-if-no-js">
  1922 <?php
  2063 	<?php
  1923 /**
  2064 	/**
  1924  * Fires before the upload interface loads.
  2065 	 * Fires before the upload interface loads.
  1925  *
  2066 	 *
  1926  * @since 2.6.0 As 'pre-flash-upload-ui'
  2067 	 * @since 2.6.0 As 'pre-flash-upload-ui'
  1927  * @since 3.3.0
  2068 	 * @since 3.3.0
  1928  */
  2069 	 */
  1929 do_action( 'pre-plupload-upload-ui' ); ?>
  2070 	do_action( 'pre-plupload-upload-ui' );
       
  2071 	?>
  1930 <div id="drag-drop-area">
  2072 <div id="drag-drop-area">
  1931 	<div class="drag-drop-inside">
  2073 	<div class="drag-drop-inside">
  1932 	<p class="drag-drop-info"><?php _e('Drop files here'); ?></p>
  2074 	<p class="drag-drop-info"><?php _e( 'Drop files here' ); ?></p>
  1933 	<p><?php _ex('or', 'Uploader: Drop files here - or - Select Files'); ?></p>
  2075 	<p><?php _ex( 'or', 'Uploader: Drop files here - or - Select Files' ); ?></p>
  1934 	<p class="drag-drop-buttons"><input id="plupload-browse-button" type="button" value="<?php esc_attr_e('Select Files'); ?>" class="button" /></p>
  2076 	<p class="drag-drop-buttons"><input id="plupload-browse-button" type="button" value="<?php esc_attr_e( 'Select Files' ); ?>" class="button" /></p>
  1935 	</div>
  2077 	</div>
  1936 </div>
  2078 </div>
  1937 <?php
  2079 	<?php
  1938 /**
  2080 	/**
  1939  * Fires after the upload interface loads.
  2081 	 * Fires after the upload interface loads.
  1940  *
  2082 	 *
  1941  * @since 2.6.0 As 'post-flash-upload-ui'
  2083 	 * @since 2.6.0 As 'post-flash-upload-ui'
  1942  * @since 3.3.0
  2084 	 * @since 3.3.0
  1943  */
  2085 	 */
  1944 do_action( 'post-plupload-upload-ui' ); ?>
  2086 	do_action( 'post-plupload-upload-ui' );
       
  2087 	?>
  1945 </div>
  2088 </div>
  1946 
  2089 
  1947 <div id="html-upload-ui" class="hide-if-js">
  2090 <div id="html-upload-ui" class="hide-if-js">
  1948 	<?php
  2091 	<?php
  1949 	/**
  2092 	/**
  1952 	 * @since 2.6.0
  2095 	 * @since 2.6.0
  1953 	 */
  2096 	 */
  1954 	do_action( 'pre-html-upload-ui' );
  2097 	do_action( 'pre-html-upload-ui' );
  1955 	?>
  2098 	?>
  1956 	<p id="async-upload-wrap">
  2099 	<p id="async-upload-wrap">
  1957 		<label class="screen-reader-text" for="async-upload"><?php _e('Upload'); ?></label>
  2100 		<label class="screen-reader-text" for="async-upload"><?php _e( 'Upload' ); ?></label>
  1958 		<input type="file" name="async-upload" id="async-upload" />
  2101 		<input type="file" name="async-upload" id="async-upload" />
  1959 		<?php submit_button( __( 'Upload' ), 'primary', 'html-upload', false ); ?>
  2102 		<?php submit_button( __( 'Upload' ), 'primary', 'html-upload', false ); ?>
  1960 		<a href="#" onclick="try{top.tb_remove();}catch(e){}; return false;"><?php _e('Cancel'); ?></a>
  2103 		<a href="#" onclick="try{top.tb_remove();}catch(e){}; return false;"><?php _e( 'Cancel' ); ?></a>
  1961 	</p>
  2104 	</p>
  1962 	<div class="clear"></div>
  2105 	<div class="clear"></div>
  1963 <?php
  2106 	<?php
  1964 /**
  2107 	/**
  1965  * Fires after the upload button in the media upload interface.
  2108 	 * Fires after the upload button in the media upload interface.
  1966  *
  2109 	 *
  1967  * @since 2.6.0
  2110 	 * @since 2.6.0
  1968  */
  2111 	 */
  1969 do_action( 'post-html-upload-ui' );
  2112 	do_action( 'post-html-upload-ui' );
  1970 ?>
  2113 	?>
  1971 </div>
  2114 </div>
  1972 
  2115 
  1973 <p class="max-upload-size"><?php printf( __( 'Maximum upload file size: %s.' ), esc_html( size_format( $max_upload_size ) ) ); ?></p>
  2116 <p class="max-upload-size"><?php printf( __( 'Maximum upload file size: %s.' ), esc_html( size_format( $max_upload_size ) ) ); ?></p>
  1974 <?php
  2117 	<?php
  1975 
  2118 
  1976 	/**
  2119 	/**
  1977 	 * Fires on the post upload UI screen.
  2120 	 * Fires on the post upload UI screen.
  1978 	 *
  2121 	 *
  1979 	 * Legacy (pre-3.5.0) media workflow hook.
  2122 	 * Legacy (pre-3.5.0) media workflow hook.
  1990  *
  2133  *
  1991  * @param string $type
  2134  * @param string $type
  1992  * @param object $errors
  2135  * @param object $errors
  1993  * @param integer $id
  2136  * @param integer $id
  1994  */
  2137  */
  1995 function media_upload_type_form($type = 'file', $errors = null, $id = null) {
  2138 function media_upload_type_form( $type = 'file', $errors = null, $id = null ) {
  1996 
  2139 
  1997 	media_upload_header();
  2140 	media_upload_header();
  1998 
  2141 
  1999 	$post_id = isset( $_REQUEST['post_id'] )? intval( $_REQUEST['post_id'] ) : 0;
  2142 	$post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0;
  2000 
  2143 
  2001 	$form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id");
  2144 	$form_action_url = admin_url( "media-upload.php?type=$type&tab=type&post_id=$post_id" );
  2002 
  2145 
  2003 	/**
  2146 	/**
  2004 	 * Filters the media upload form action URL.
  2147 	 * Filters the media upload form action URL.
  2005 	 *
  2148 	 *
  2006 	 * @since 2.6.0
  2149 	 * @since 2.6.0
  2007 	 *
  2150 	 *
  2008 	 * @param string $form_action_url The media upload form action URL.
  2151 	 * @param string $form_action_url The media upload form action URL.
  2009 	 * @param string $type            The type of media. Default 'file'.
  2152 	 * @param string $type            The type of media. Default 'file'.
  2010 	 */
  2153 	 */
  2011 	$form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type );
  2154 	$form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type );
  2012 	$form_class = 'media-upload-form type-form validate';
  2155 	$form_class      = 'media-upload-form type-form validate';
  2013 
  2156 
  2014 	if ( get_user_setting('uploader') )
  2157 	if ( get_user_setting( 'uploader' ) ) {
  2015 		$form_class .= ' html-uploader';
  2158 		$form_class .= ' html-uploader';
  2016 ?>
  2159 	}
       
  2160 	?>
  2017 
  2161 
  2018 <form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="<?php echo $type; ?>-form">
  2162 <form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="<?php echo $type; ?>-form">
  2019 <?php submit_button( '', 'hidden', 'save', false ); ?>
  2163 	<?php submit_button( '', 'hidden', 'save', false ); ?>
  2020 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
  2164 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
  2021 <?php wp_nonce_field('media-form'); ?>
  2165 	<?php wp_nonce_field( 'media-form' ); ?>
  2022 
  2166 
  2023 <h3 class="media-title"><?php _e('Add media files from your computer'); ?></h3>
  2167 <h3 class="media-title"><?php _e( 'Add media files from your computer' ); ?></h3>
  2024 
  2168 
  2025 <?php media_upload_form( $errors ); ?>
  2169 	<?php media_upload_form( $errors ); ?>
  2026 
  2170 
  2027 <script type="text/javascript">
  2171 <script type="text/javascript">
  2028 jQuery(function($){
  2172 jQuery(function($){
  2029 	var preloaded = $(".media-item.preloaded");
  2173 	var preloaded = $(".media-item.preloaded");
  2030 	if ( preloaded.length > 0 ) {
  2174 	if ( preloaded.length > 0 ) {
  2031 		preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
  2175 		preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
  2032 	}
  2176 	}
  2033 	updateMediaForm();
  2177 	updateMediaForm();
  2034 });
  2178 });
  2035 </script>
  2179 </script>
  2036 <div id="media-items"><?php
  2180 <div id="media-items">
  2037 
  2181 	<?php
  2038 if ( $id ) {
  2182 
  2039 	if ( !is_wp_error($id) ) {
  2183 	if ( $id ) {
  2040 		add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2);
  2184 		if ( ! is_wp_error( $id ) ) {
  2041 		echo get_media_items( $id, $errors );
  2185 			add_filter( 'attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2 );
  2042 	} else {
  2186 			echo get_media_items( $id, $errors );
  2043 		echo '<div id="media-upload-error">'.esc_html($id->get_error_message()).'</div></div>';
  2187 		} else {
  2044 		exit;
  2188 			echo '<div id="media-upload-error">' . esc_html( $id->get_error_message() ) . '</div></div>';
  2045 	}
  2189 			exit;
  2046 }
  2190 		}
  2047 ?></div>
  2191 	}
       
  2192 	?>
       
  2193 </div>
  2048 
  2194 
  2049 <p class="savebutton ml-submit">
  2195 <p class="savebutton ml-submit">
  2050 <?php submit_button( __( 'Save all changes' ), '', 'save', false ); ?>
  2196 	<?php submit_button( __( 'Save all changes' ), '', 'save', false ); ?>
  2051 </p>
  2197 </p>
  2052 </form>
  2198 </form>
  2053 <?php
  2199 	<?php
  2054 }
  2200 }
  2055 
  2201 
  2056 /**
  2202 /**
  2057  * Outputs the legacy media upload form for external media.
  2203  * Outputs the legacy media upload form for external media.
  2058  *
  2204  *
  2060  *
  2206  *
  2061  * @param string $type
  2207  * @param string $type
  2062  * @param object $errors
  2208  * @param object $errors
  2063  * @param integer $id
  2209  * @param integer $id
  2064  */
  2210  */
  2065 function media_upload_type_url_form($type = null, $errors = null, $id = null) {
  2211 function media_upload_type_url_form( $type = null, $errors = null, $id = null ) {
  2066 	if ( null === $type )
  2212 	if ( null === $type ) {
  2067 		$type = 'image';
  2213 		$type = 'image';
       
  2214 	}
  2068 
  2215 
  2069 	media_upload_header();
  2216 	media_upload_header();
  2070 
  2217 
  2071 	$post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0;
  2218 	$post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0;
  2072 
  2219 
  2073 	$form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id");
  2220 	$form_action_url = admin_url( "media-upload.php?type=$type&tab=type&post_id=$post_id" );
  2074 	/** This filter is documented in wp-admin/includes/media.php */
  2221 	/** This filter is documented in wp-admin/includes/media.php */
  2075 	$form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type );
  2222 	$form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type );
  2076 	$form_class = 'media-upload-form type-form validate';
  2223 	$form_class      = 'media-upload-form type-form validate';
  2077 
  2224 
  2078 	if ( get_user_setting('uploader') )
  2225 	if ( get_user_setting( 'uploader' ) ) {
  2079 		$form_class .= ' html-uploader';
  2226 		$form_class .= ' html-uploader';
  2080 ?>
  2227 	}
       
  2228 	?>
  2081 
  2229 
  2082 <form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="<?php echo $type; ?>-form">
  2230 <form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="<?php echo $type; ?>-form">
  2083 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
  2231 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
  2084 <?php wp_nonce_field('media-form'); ?>
  2232 	<?php wp_nonce_field( 'media-form' ); ?>
  2085 
  2233 
  2086 <h3 class="media-title"><?php _e('Insert media from another website'); ?></h3>
  2234 <h3 class="media-title"><?php _e( 'Insert media from another website' ); ?></h3>
  2087 
  2235 
  2088 <script type="text/javascript">
  2236 <script type="text/javascript">
  2089 var addExtImage = {
  2237 var addExtImage = {
  2090 
  2238 
  2091 	width : '',
  2239 	width : '',
  2099 			return false;
  2247 			return false;
  2100 
  2248 
  2101 		if ( f.alt.value )
  2249 		if ( f.alt.value )
  2102 			alt = f.alt.value.replace(/'/g, '&#039;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
  2250 			alt = f.alt.value.replace(/'/g, '&#039;').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
  2103 
  2251 
  2104 <?php
  2252 	<?php
  2105 	/** This filter is documented in wp-admin/includes/media.php */
  2253 	/** This filter is documented in wp-admin/includes/media.php */
  2106 	if ( ! apply_filters( 'disable_captions', '' ) ) {
  2254 	if ( ! apply_filters( 'disable_captions', '' ) ) {
  2107 		?>
  2255 		?>
  2108 		if ( f.caption.value ) {
  2256 	if ( f.caption.value ) {
  2109 			caption = f.caption.value.replace(/\r\n|\r/g, '\n');
  2257 		caption = f.caption.value.replace(/\r\n|\r/g, '\n');
  2110 			caption = caption.replace(/<[a-zA-Z0-9]+( [^<>]+)?>/g, function(a){
  2258 		caption = caption.replace(/<[a-zA-Z0-9]+( [^<>]+)?>/g, function(a){
  2111 				return a.replace(/[\r\n\t]+/, ' ');
  2259 			return a.replace(/[\r\n\t]+/, ' ');
  2112 			});
  2260 		});
  2113 
  2261 
  2114 			caption = caption.replace(/\s*\n\s*/g, '<br />');
  2262 		caption = caption.replace(/\s*\n\s*/g, '<br />');
  2115 		}
  2263 	}
  2116 <?php } ?>
  2264 	<?php } ?>
  2117 
  2265 
  2118 		cls = caption ? '' : ' class="'+t.align+'"';
  2266 		cls = caption ? '' : ' class="'+t.align+'"';
  2119 
  2267 
  2120 		html = '<img alt="'+alt+'" src="'+f.src.value+'"'+cls+' width="'+t.width+'" height="'+t.height+'" />';
  2268 		html = '<img alt="'+alt+'" src="'+f.src.value+'"'+cls+' width="'+t.width+'" height="'+t.height+'" />';
  2121 
  2269 
  2177 });
  2325 });
  2178 </script>
  2326 </script>
  2179 
  2327 
  2180 <div id="media-items">
  2328 <div id="media-items">
  2181 <div class="media-item media-blank">
  2329 <div class="media-item media-blank">
  2182 <?php
  2330 	<?php
  2183 /**
  2331 	/**
  2184  * Filters the insert media from URL form HTML.
  2332 	 * Filters the insert media from URL form HTML.
  2185  *
  2333 	 *
  2186  * @since 3.3.0
  2334 	 * @since 3.3.0
  2187  *
  2335 	 *
  2188  * @param string $form_html The insert from URL form HTML.
  2336 	 * @param string $form_html The insert from URL form HTML.
  2189  */
  2337 	 */
  2190 echo apply_filters( 'type_url_form_media', wp_media_insert_url_form( $type ) );
  2338 	echo apply_filters( 'type_url_form_media', wp_media_insert_url_form( $type ) );
  2191 ?>
  2339 	?>
  2192 </div>
  2340 </div>
  2193 </div>
  2341 </div>
  2194 </form>
  2342 </form>
  2195 <?php
  2343 	<?php
  2196 }
  2344 }
  2197 
  2345 
  2198 /**
  2346 /**
  2199  * Adds gallery form to upload iframe
  2347  * Adds gallery form to upload iframe
  2200  *
  2348  *
  2204  * @global string $type
  2352  * @global string $type
  2205  * @global string $tab
  2353  * @global string $tab
  2206  *
  2354  *
  2207  * @param array $errors
  2355  * @param array $errors
  2208  */
  2356  */
  2209 function media_upload_gallery_form($errors) {
  2357 function media_upload_gallery_form( $errors ) {
  2210 	global $redir_tab, $type;
  2358 	global $redir_tab, $type;
  2211 
  2359 
  2212 	$redir_tab = 'gallery';
  2360 	$redir_tab = 'gallery';
  2213 	media_upload_header();
  2361 	media_upload_header();
  2214 
  2362 
  2215 	$post_id = intval($_REQUEST['post_id']);
  2363 	$post_id         = intval( $_REQUEST['post_id'] );
  2216 	$form_action_url = admin_url("media-upload.php?type=$type&tab=gallery&post_id=$post_id");
  2364 	$form_action_url = admin_url( "media-upload.php?type=$type&tab=gallery&post_id=$post_id" );
  2217 	/** This filter is documented in wp-admin/includes/media.php */
  2365 	/** This filter is documented in wp-admin/includes/media.php */
  2218 	$form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type );
  2366 	$form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type );
  2219 	$form_class = 'media-upload-form validate';
  2367 	$form_class      = 'media-upload-form validate';
  2220 
  2368 
  2221 	if ( get_user_setting('uploader') )
  2369 	if ( get_user_setting( 'uploader' ) ) {
  2222 		$form_class .= ' html-uploader';
  2370 		$form_class .= ' html-uploader';
  2223 ?>
  2371 	}
       
  2372 	?>
  2224 
  2373 
  2225 <script type="text/javascript">
  2374 <script type="text/javascript">
  2226 jQuery(function($){
  2375 jQuery(function($){
  2227 	var preloaded = $(".media-item.preloaded");
  2376 	var preloaded = $(".media-item.preloaded");
  2228 	if ( preloaded.length > 0 ) {
  2377 	if ( preloaded.length > 0 ) {
  2231 	}
  2380 	}
  2232 });
  2381 });
  2233 </script>
  2382 </script>
  2234 <div id="sort-buttons" class="hide-if-no-js">
  2383 <div id="sort-buttons" class="hide-if-no-js">
  2235 <span>
  2384 <span>
  2236 <?php _e('All Tabs:'); ?>
  2385 	<?php _e( 'All Tabs:' ); ?>
  2237 <a href="#" id="showall"><?php _e('Show'); ?></a>
  2386 <a href="#" id="showall"><?php _e( 'Show' ); ?></a>
  2238 <a href="#" id="hideall" style="display:none;"><?php _e('Hide'); ?></a>
  2387 <a href="#" id="hideall" style="display:none;"><?php _e( 'Hide' ); ?></a>
  2239 </span>
  2388 </span>
  2240 <?php _e('Sort Order:'); ?>
  2389 	<?php _e( 'Sort Order:' ); ?>
  2241 <a href="#" id="asc"><?php _e('Ascending'); ?></a> |
  2390 <a href="#" id="asc"><?php _e( 'Ascending' ); ?></a> |
  2242 <a href="#" id="desc"><?php _e('Descending'); ?></a> |
  2391 <a href="#" id="desc"><?php _e( 'Descending' ); ?></a> |
  2243 <a href="#" id="clear"><?php _ex('Clear', 'verb'); ?></a>
  2392 <a href="#" id="clear"><?php _ex( 'Clear', 'verb' ); ?></a>
  2244 </div>
  2393 </div>
  2245 <form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="gallery-form">
  2394 <form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="gallery-form">
  2246 <?php wp_nonce_field('media-form'); ?>
  2395 	<?php wp_nonce_field( 'media-form' ); ?>
  2247 <?php //media_upload_form( $errors ); ?>
  2396 	<?php //media_upload_form( $errors ); ?>
  2248 <table class="widefat">
  2397 <table class="widefat">
  2249 <thead><tr>
  2398 <thead><tr>
  2250 <th><?php _e('Media'); ?></th>
  2399 <th><?php _e( 'Media' ); ?></th>
  2251 <th class="order-head"><?php _e('Order'); ?></th>
  2400 <th class="order-head"><?php _e( 'Order' ); ?></th>
  2252 <th class="actions-head"><?php _e('Actions'); ?></th>
  2401 <th class="actions-head"><?php _e( 'Actions' ); ?></th>
  2253 </tr></thead>
  2402 </tr></thead>
  2254 </table>
  2403 </table>
  2255 <div id="media-items">
  2404 <div id="media-items">
  2256 <?php add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); ?>
  2405 	<?php add_filter( 'attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2 ); ?>
  2257 <?php echo get_media_items($post_id, $errors); ?>
  2406 	<?php echo get_media_items( $post_id, $errors ); ?>
  2258 </div>
  2407 </div>
  2259 
  2408 
  2260 <p class="ml-submit">
  2409 <p class="ml-submit">
  2261 <?php submit_button( __( 'Save all changes' ), 'savebutton', 'save', false, array( 'id' => 'save-all', 'style' => 'display: none;' ) ); ?>
  2410 	<?php
       
  2411 	submit_button(
       
  2412 		__( 'Save all changes' ),
       
  2413 		'savebutton',
       
  2414 		'save',
       
  2415 		false,
       
  2416 		array(
       
  2417 			'id'    => 'save-all',
       
  2418 			'style' => 'display: none;',
       
  2419 		)
       
  2420 	);
       
  2421 	?>
  2262 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
  2422 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
  2263 <input type="hidden" name="type" value="<?php echo esc_attr( $GLOBALS['type'] ); ?>" />
  2423 <input type="hidden" name="type" value="<?php echo esc_attr( $GLOBALS['type'] ); ?>" />
  2264 <input type="hidden" name="tab" value="<?php echo esc_attr( $GLOBALS['tab'] ); ?>" />
  2424 <input type="hidden" name="tab" value="<?php echo esc_attr( $GLOBALS['tab'] ); ?>" />
  2265 </p>
  2425 </p>
  2266 
  2426 
  2267 <div id="gallery-settings" style="display:none;">
  2427 <div id="gallery-settings" style="display:none;">
  2268 <div class="title"><?php _e('Gallery Settings'); ?></div>
  2428 <div class="title"><?php _e( 'Gallery Settings' ); ?></div>
  2269 <table id="basic" class="describe"><tbody>
  2429 <table id="basic" class="describe"><tbody>
  2270 	<tr>
  2430 	<tr>
  2271 	<th scope="row" class="label">
  2431 	<th scope="row" class="label">
  2272 		<label>
  2432 		<label>
  2273 		<span class="alignleft"><?php _e('Link thumbnails to:'); ?></span>
  2433 		<span class="alignleft"><?php _e( 'Link thumbnails to:' ); ?></span>
  2274 		</label>
  2434 		</label>
  2275 	</th>
  2435 	</th>
  2276 	<td class="field">
  2436 	<td class="field">
  2277 		<input type="radio" name="linkto" id="linkto-file" value="file" />
  2437 		<input type="radio" name="linkto" id="linkto-file" value="file" />
  2278 		<label for="linkto-file" class="radio"><?php _e('Image File'); ?></label>
  2438 		<label for="linkto-file" class="radio"><?php _e( 'Image File' ); ?></label>
  2279 
  2439 
  2280 		<input type="radio" checked="checked" name="linkto" id="linkto-post" value="post" />
  2440 		<input type="radio" checked="checked" name="linkto" id="linkto-post" value="post" />
  2281 		<label for="linkto-post" class="radio"><?php _e('Attachment Page'); ?></label>
  2441 		<label for="linkto-post" class="radio"><?php _e( 'Attachment Page' ); ?></label>
  2282 	</td>
  2442 	</td>
  2283 	</tr>
  2443 	</tr>
  2284 
  2444 
  2285 	<tr>
  2445 	<tr>
  2286 	<th scope="row" class="label">
  2446 	<th scope="row" class="label">
  2287 		<label>
  2447 		<label>
  2288 		<span class="alignleft"><?php _e('Order images by:'); ?></span>
  2448 		<span class="alignleft"><?php _e( 'Order images by:' ); ?></span>
  2289 		</label>
  2449 		</label>
  2290 	</th>
  2450 	</th>
  2291 	<td class="field">
  2451 	<td class="field">
  2292 		<select id="orderby" name="orderby">
  2452 		<select id="orderby" name="orderby">
  2293 			<option value="menu_order" selected="selected"><?php _e('Menu order'); ?></option>
  2453 			<option value="menu_order" selected="selected"><?php _e( 'Menu order' ); ?></option>
  2294 			<option value="title"><?php _e('Title'); ?></option>
  2454 			<option value="title"><?php _e( 'Title' ); ?></option>
  2295 			<option value="post_date"><?php _e('Date/Time'); ?></option>
  2455 			<option value="post_date"><?php _e( 'Date/Time' ); ?></option>
  2296 			<option value="rand"><?php _e('Random'); ?></option>
  2456 			<option value="rand"><?php _e( 'Random' ); ?></option>
  2297 		</select>
  2457 		</select>
  2298 	</td>
  2458 	</td>
  2299 	</tr>
  2459 	</tr>
  2300 
  2460 
  2301 	<tr>
  2461 	<tr>
  2302 	<th scope="row" class="label">
  2462 	<th scope="row" class="label">
  2303 		<label>
  2463 		<label>
  2304 		<span class="alignleft"><?php _e('Order:'); ?></span>
  2464 		<span class="alignleft"><?php _e( 'Order:' ); ?></span>
  2305 		</label>
  2465 		</label>
  2306 	</th>
  2466 	</th>
  2307 	<td class="field">
  2467 	<td class="field">
  2308 		<input type="radio" checked="checked" name="order" id="order-asc" value="asc" />
  2468 		<input type="radio" checked="checked" name="order" id="order-asc" value="asc" />
  2309 		<label for="order-asc" class="radio"><?php _e('Ascending'); ?></label>
  2469 		<label for="order-asc" class="radio"><?php _e( 'Ascending' ); ?></label>
  2310 
  2470 
  2311 		<input type="radio" name="order" id="order-desc" value="desc" />
  2471 		<input type="radio" name="order" id="order-desc" value="desc" />
  2312 		<label for="order-desc" class="radio"><?php _e('Descending'); ?></label>
  2472 		<label for="order-desc" class="radio"><?php _e( 'Descending' ); ?></label>
  2313 	</td>
  2473 	</td>
  2314 	</tr>
  2474 	</tr>
  2315 
  2475 
  2316 	<tr>
  2476 	<tr>
  2317 	<th scope="row" class="label">
  2477 	<th scope="row" class="label">
  2318 		<label>
  2478 		<label>
  2319 		<span class="alignleft"><?php _e('Gallery columns:'); ?></span>
  2479 		<span class="alignleft"><?php _e( 'Gallery columns:' ); ?></span>
  2320 		</label>
  2480 		</label>
  2321 	</th>
  2481 	</th>
  2322 	<td class="field">
  2482 	<td class="field">
  2323 		<select id="columns" name="columns">
  2483 		<select id="columns" name="columns">
  2324 			<option value="1">1</option>
  2484 			<option value="1">1</option>
  2339 <input type="button" class="button" style="display:none;" onMouseDown="wpgallery.update();" name="insert-gallery" id="insert-gallery" value="<?php esc_attr_e( 'Insert gallery' ); ?>" />
  2499 <input type="button" class="button" style="display:none;" onMouseDown="wpgallery.update();" name="insert-gallery" id="insert-gallery" value="<?php esc_attr_e( 'Insert gallery' ); ?>" />
  2340 <input type="button" class="button" style="display:none;" onMouseDown="wpgallery.update();" name="update-gallery" id="update-gallery" value="<?php esc_attr_e( 'Update gallery settings' ); ?>" />
  2500 <input type="button" class="button" style="display:none;" onMouseDown="wpgallery.update();" name="update-gallery" id="update-gallery" value="<?php esc_attr_e( 'Update gallery settings' ); ?>" />
  2341 </p>
  2501 </p>
  2342 </div>
  2502 </div>
  2343 </form>
  2503 </form>
  2344 <?php
  2504 	<?php
  2345 }
  2505 }
  2346 
  2506 
  2347 /**
  2507 /**
  2348  * Outputs the legacy media upload form for the media library.
  2508  * Outputs the legacy media upload form for the media library.
  2349  *
  2509  *
  2356  * @global string    $tab
  2516  * @global string    $tab
  2357  * @global array     $post_mime_types
  2517  * @global array     $post_mime_types
  2358  *
  2518  *
  2359  * @param array $errors
  2519  * @param array $errors
  2360  */
  2520  */
  2361 function media_upload_library_form($errors) {
  2521 function media_upload_library_form( $errors ) {
  2362 	global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types;
  2522 	global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types;
  2363 
  2523 
  2364 	media_upload_header();
  2524 	media_upload_header();
  2365 
  2525 
  2366 	$post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0;
  2526 	$post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0;
  2367 
  2527 
  2368 	$form_action_url = admin_url("media-upload.php?type=$type&tab=library&post_id=$post_id");
  2528 	$form_action_url = admin_url( "media-upload.php?type=$type&tab=library&post_id=$post_id" );
  2369 	/** This filter is documented in wp-admin/includes/media.php */
  2529 	/** This filter is documented in wp-admin/includes/media.php */
  2370 	$form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type );
  2530 	$form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type );
  2371 	$form_class = 'media-upload-form validate';
  2531 	$form_class      = 'media-upload-form validate';
  2372 
  2532 
  2373 	if ( get_user_setting('uploader') )
  2533 	if ( get_user_setting( 'uploader' ) ) {
  2374 		$form_class .= ' html-uploader';
  2534 		$form_class .= ' html-uploader';
  2375 
  2535 	}
  2376 	$q = $_GET;
  2536 
       
  2537 	$q                   = $_GET;
  2377 	$q['posts_per_page'] = 10;
  2538 	$q['posts_per_page'] = 10;
  2378 	$q['paged'] = isset( $q['paged'] ) ? intval( $q['paged'] ) : 0;
  2539 	$q['paged']          = isset( $q['paged'] ) ? intval( $q['paged'] ) : 0;
  2379 	if ( $q['paged'] < 1 ) {
  2540 	if ( $q['paged'] < 1 ) {
  2380 		$q['paged'] = 1;
  2541 		$q['paged'] = 1;
  2381 	}
  2542 	}
  2382 	$q['offset'] = ( $q['paged'] - 1 ) * 10;
  2543 	$q['offset'] = ( $q['paged'] - 1 ) * 10;
  2383 	if ( $q['offset'] < 1 ) {
  2544 	if ( $q['offset'] < 1 ) {
  2384 		$q['offset'] = 0;
  2545 		$q['offset'] = 0;
  2385 	}
  2546 	}
  2386 
  2547 
  2387 	list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query( $q );
  2548 	list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query( $q );
  2388 
  2549 
  2389 ?>
  2550 	?>
  2390 
  2551 
  2391 <form id="filter" method="get">
  2552 <form id="filter" method="get">
  2392 <input type="hidden" name="type" value="<?php echo esc_attr( $type ); ?>" />
  2553 <input type="hidden" name="type" value="<?php echo esc_attr( $type ); ?>" />
  2393 <input type="hidden" name="tab" value="<?php echo esc_attr( $tab ); ?>" />
  2554 <input type="hidden" name="tab" value="<?php echo esc_attr( $tab ); ?>" />
  2394 <input type="hidden" name="post_id" value="<?php echo (int) $post_id; ?>" />
  2555 <input type="hidden" name="post_id" value="<?php echo (int) $post_id; ?>" />
  2395 <input type="hidden" name="post_mime_type" value="<?php echo isset( $_GET['post_mime_type'] ) ? esc_attr( $_GET['post_mime_type'] ) : ''; ?>" />
  2556 <input type="hidden" name="post_mime_type" value="<?php echo isset( $_GET['post_mime_type'] ) ? esc_attr( $_GET['post_mime_type'] ) : ''; ?>" />
  2396 <input type="hidden" name="context" value="<?php echo isset( $_GET['context'] ) ? esc_attr( $_GET['context'] ) : ''; ?>" />
  2557 <input type="hidden" name="context" value="<?php echo isset( $_GET['context'] ) ? esc_attr( $_GET['context'] ) : ''; ?>" />
  2397 
  2558 
  2398 <p id="media-search" class="search-box">
  2559 <p id="media-search" class="search-box">
  2399 	<label class="screen-reader-text" for="media-search-input"><?php _e('Search Media');?>:</label>
  2560 	<label class="screen-reader-text" for="media-search-input"><?php _e( 'Search Media' ); ?>:</label>
  2400 	<input type="search" id="media-search-input" name="s" value="<?php the_search_query(); ?>" />
  2561 	<input type="search" id="media-search-input" name="s" value="<?php the_search_query(); ?>" />
  2401 	<?php submit_button( __( 'Search Media' ), '', '', false ); ?>
  2562 	<?php submit_button( __( 'Search Media' ), '', '', false ); ?>
  2402 </p>
  2563 </p>
  2403 
  2564 
  2404 <ul class="subsubsub">
  2565 <ul class="subsubsub">
  2405 <?php
  2566 	<?php
  2406 $type_links = array();
  2567 	$type_links = array();
  2407 $_num_posts = (array) wp_count_attachments();
  2568 	$_num_posts = (array) wp_count_attachments();
  2408 $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts));
  2569 	$matches    = wp_match_mime_types( array_keys( $post_mime_types ), array_keys( $_num_posts ) );
  2409 foreach ( $matches as $_type => $reals )
  2570 	foreach ( $matches as $_type => $reals ) {
  2410 	foreach ( $reals as $real )
  2571 		foreach ( $reals as $real ) {
  2411 		if ( isset($num_posts[$_type]) )
  2572 			if ( isset( $num_posts[ $_type ] ) ) {
  2412 			$num_posts[$_type] += $_num_posts[$real];
  2573 				$num_posts[ $_type ] += $_num_posts[ $real ];
  2413 		else
  2574 			} else {
  2414 			$num_posts[$_type] = $_num_posts[$real];
  2575 				$num_posts[ $_type ] = $_num_posts[ $real ];
  2415 // If available type specified by media button clicked, filter by that type
  2576 			}
  2416 if ( empty($_GET['post_mime_type']) && !empty($num_posts[$type]) ) {
  2577 		}
  2417 	$_GET['post_mime_type'] = $type;
  2578 	}
  2418 	list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
  2579 	// If available type specified by media button clicked, filter by that type
  2419 }
  2580 	if ( empty( $_GET['post_mime_type'] ) && ! empty( $num_posts[ $type ] ) ) {
  2420 if ( empty($_GET['post_mime_type']) || $_GET['post_mime_type'] == 'all' )
  2581 		$_GET['post_mime_type']                        = $type;
  2421 	$class = ' class="current"';
  2582 		list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
  2422 else
  2583 	}
  2423 	$class = '';
  2584 	if ( empty( $_GET['post_mime_type'] ) || $_GET['post_mime_type'] == 'all' ) {
  2424 $type_links[] = '<li><a href="' . esc_url(add_query_arg(array('post_mime_type'=>'all', 'paged'=>false, 'm'=>false))) . '"' . $class . '>' . __('All Types') . '</a>';
       
  2425 foreach ( $post_mime_types as $mime_type => $label ) {
       
  2426 	$class = '';
       
  2427 
       
  2428 	if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) )
       
  2429 		continue;
       
  2430 
       
  2431 	if ( isset($_GET['post_mime_type']) && wp_match_mime_types($mime_type, $_GET['post_mime_type']) )
       
  2432 		$class = ' class="current"';
  2585 		$class = ' class="current"';
  2433 
  2586 	} else {
  2434 	$type_links[] = '<li><a href="' . esc_url(add_query_arg(array('post_mime_type'=>$mime_type, 'paged'=>false))) . '"' . $class . '>' . sprintf( translate_nooped_plural( $label[2], $num_posts[$mime_type] ), '<span id="' . $mime_type . '-counter">' . number_format_i18n( $num_posts[$mime_type] ) . '</span>') . '</a>';
  2587 		$class = '';
  2435 }
  2588 	}
  2436 /**
  2589 	$type_links[] = '<li><a href="' . esc_url(
  2437  * Filters the media upload mime type list items.
  2590 		add_query_arg(
  2438  *
  2591 			array(
  2439  * Returned values should begin with an `<li>` tag.
  2592 				'post_mime_type' => 'all',
  2440  *
  2593 				'paged'          => false,
  2441  * @since 3.1.0
  2594 				'm'              => false,
  2442  *
  2595 			)
  2443  * @param array $type_links An array of list items containing mime type link HTML.
  2596 		)
  2444  */
  2597 	) . '"' . $class . '>' . __( 'All Types' ) . '</a>';
  2445 echo implode(' | </li>', apply_filters( 'media_upload_mime_type_links', $type_links ) ) . '</li>';
  2598 	foreach ( $post_mime_types as $mime_type => $label ) {
  2446 unset($type_links);
  2599 		$class = '';
  2447 ?>
  2600 
       
  2601 		if ( ! wp_match_mime_types( $mime_type, $avail_post_mime_types ) ) {
       
  2602 			continue;
       
  2603 		}
       
  2604 
       
  2605 		if ( isset( $_GET['post_mime_type'] ) && wp_match_mime_types( $mime_type, $_GET['post_mime_type'] ) ) {
       
  2606 			$class = ' class="current"';
       
  2607 		}
       
  2608 
       
  2609 		$type_links[] = '<li><a href="' . esc_url(
       
  2610 			add_query_arg(
       
  2611 				array(
       
  2612 					'post_mime_type' => $mime_type,
       
  2613 					'paged'          => false,
       
  2614 				)
       
  2615 			)
       
  2616 		) . '"' . $class . '>' . sprintf( translate_nooped_plural( $label[2], $num_posts[ $mime_type ] ), '<span id="' . $mime_type . '-counter">' . number_format_i18n( $num_posts[ $mime_type ] ) . '</span>' ) . '</a>';
       
  2617 	}
       
  2618 	/**
       
  2619 	 * Filters the media upload mime type list items.
       
  2620 	 *
       
  2621 	 * Returned values should begin with an `<li>` tag.
       
  2622 	 *
       
  2623 	 * @since 3.1.0
       
  2624 	 *
       
  2625 	 * @param string[] $type_links An array of list items containing mime type link HTML.
       
  2626 	 */
       
  2627 	echo implode( ' | </li>', apply_filters( 'media_upload_mime_type_links', $type_links ) ) . '</li>';
       
  2628 	unset( $type_links );
       
  2629 	?>
  2448 </ul>
  2630 </ul>
  2449 
  2631 
  2450 <div class="tablenav">
  2632 <div class="tablenav">
  2451 
  2633 
  2452 <?php
  2634 	<?php
  2453 $page_links = paginate_links( array(
  2635 	$page_links = paginate_links(
  2454 	'base' => add_query_arg( 'paged', '%#%' ),
  2636 		array(
  2455 	'format' => '',
  2637 			'base'      => add_query_arg( 'paged', '%#%' ),
  2456 	'prev_text' => __('&laquo;'),
  2638 			'format'    => '',
  2457 	'next_text' => __('&raquo;'),
  2639 			'prev_text' => __( '&laquo;' ),
  2458 	'total' => ceil($wp_query->found_posts / 10),
  2640 			'next_text' => __( '&raquo;' ),
  2459 	'current' => $q['paged'],
  2641 			'total'     => ceil( $wp_query->found_posts / 10 ),
  2460 ));
  2642 			'current'   => $q['paged'],
  2461 
  2643 		)
  2462 if ( $page_links )
  2644 	);
  2463 	echo "<div class='tablenav-pages'>$page_links</div>";
  2645 
  2464 ?>
  2646 	if ( $page_links ) {
       
  2647 		echo "<div class='tablenav-pages'>$page_links</div>";
       
  2648 	}
       
  2649 	?>
  2465 
  2650 
  2466 <div class="alignleft actions">
  2651 <div class="alignleft actions">
  2467 <?php
  2652 	<?php
  2468 
  2653 
  2469 $arc_query = "SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM $wpdb->posts WHERE post_type = 'attachment' ORDER BY post_date DESC";
  2654 	$arc_query = "SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM $wpdb->posts WHERE post_type = 'attachment' ORDER BY post_date DESC";
  2470 
  2655 
  2471 $arc_result = $wpdb->get_results( $arc_query );
  2656 	$arc_result = $wpdb->get_results( $arc_query );
  2472 
  2657 
  2473 $month_count = count($arc_result);
  2658 	$month_count    = count( $arc_result );
  2474 $selected_month = isset( $_GET['m'] ) ? $_GET['m'] : 0;
  2659 	$selected_month = isset( $_GET['m'] ) ? $_GET['m'] : 0;
  2475 
  2660 
  2476 if ( $month_count && !( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) { ?>
  2661 	if ( $month_count && ! ( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) {
       
  2662 		?>
  2477 <select name='m'>
  2663 <select name='m'>
  2478 <option<?php selected( $selected_month, 0 ); ?> value='0'><?php _e( 'All dates' ); ?></option>
  2664 <option<?php selected( $selected_month, 0 ); ?> value='0'><?php _e( 'All dates' ); ?></option>
  2479 <?php
  2665 		<?php
  2480 foreach ($arc_result as $arc_row) {
  2666 		foreach ( $arc_result as $arc_row ) {
  2481 	if ( $arc_row->yyear == 0 )
  2667 			if ( $arc_row->yyear == 0 ) {
  2482 		continue;
  2668 				continue;
  2483 	$arc_row->mmonth = zeroise( $arc_row->mmonth, 2 );
  2669 			}
  2484 
  2670 			$arc_row->mmonth = zeroise( $arc_row->mmonth, 2 );
  2485 	if ( $arc_row->yyear . $arc_row->mmonth == $selected_month )
  2671 
  2486 		$default = ' selected="selected"';
  2672 			if ( $arc_row->yyear . $arc_row->mmonth == $selected_month ) {
  2487 	else
  2673 				$default = ' selected="selected"';
  2488 		$default = '';
  2674 			} else {
  2489 
  2675 				$default = '';
  2490 	echo "<option$default value='" . esc_attr( $arc_row->yyear . $arc_row->mmonth ) . "'>";
  2676 			}
  2491 	echo esc_html( $wp_locale->get_month($arc_row->mmonth) . " $arc_row->yyear" );
  2677 
  2492 	echo "</option>\n";
  2678 			echo "<option$default value='" . esc_attr( $arc_row->yyear . $arc_row->mmonth ) . "'>";
  2493 }
  2679 			echo esc_html( $wp_locale->get_month( $arc_row->mmonth ) . " $arc_row->yyear" );
  2494 ?>
  2680 			echo "</option>\n";
       
  2681 		}
       
  2682 		?>
  2495 </select>
  2683 </select>
  2496 <?php } ?>
  2684 	<?php } ?>
  2497 
  2685 
  2498 <?php submit_button( __( 'Filter &#187;' ), '', 'post-query-submit', false ); ?>
  2686 	<?php submit_button( __( 'Filter &#187;' ), '', 'post-query-submit', false ); ?>
  2499 
  2687 
  2500 </div>
  2688 </div>
  2501 
  2689 
  2502 <br class="clear" />
  2690 <br class="clear" />
  2503 </div>
  2691 </div>
  2504 </form>
  2692 </form>
  2505 
  2693 
  2506 <form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="library-form">
  2694 <form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="library-form">
  2507 
  2695 
  2508 <?php wp_nonce_field('media-form'); ?>
  2696 	<?php wp_nonce_field( 'media-form' ); ?>
  2509 <?php //media_upload_form( $errors ); ?>
  2697 	<?php //media_upload_form( $errors ); ?>
  2510 
  2698 
  2511 <script type="text/javascript">
  2699 <script type="text/javascript">
  2512 <!--
  2700 <!--
  2513 jQuery(function($){
  2701 jQuery(function($){
  2514 	var preloaded = $(".media-item.preloaded");
  2702 	var preloaded = $(".media-item.preloaded");
  2519 });
  2707 });
  2520 -->
  2708 -->
  2521 </script>
  2709 </script>
  2522 
  2710 
  2523 <div id="media-items">
  2711 <div id="media-items">
  2524 <?php add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); ?>
  2712 	<?php add_filter( 'attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2 ); ?>
  2525 <?php echo get_media_items(null, $errors); ?>
  2713 	<?php echo get_media_items( null, $errors ); ?>
  2526 </div>
  2714 </div>
  2527 <p class="ml-submit">
  2715 <p class="ml-submit">
  2528 <?php submit_button( __( 'Save all changes' ), 'savebutton', 'save', false ); ?>
  2716 	<?php submit_button( __( 'Save all changes' ), 'savebutton', 'save', false ); ?>
  2529 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
  2717 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
  2530 </p>
  2718 </p>
  2531 </form>
  2719 </form>
  2532 <?php
  2720 	<?php
  2533 }
  2721 }
  2534 
  2722 
  2535 /**
  2723 /**
  2536  * Creates the form for external url
  2724  * Creates the form for external url
  2537  *
  2725  *
  2544 	/** This filter is documented in wp-admin/includes/media.php */
  2732 	/** This filter is documented in wp-admin/includes/media.php */
  2545 	if ( ! apply_filters( 'disable_captions', '' ) ) {
  2733 	if ( ! apply_filters( 'disable_captions', '' ) ) {
  2546 		$caption = '
  2734 		$caption = '
  2547 		<tr class="image-only">
  2735 		<tr class="image-only">
  2548 			<th scope="row" class="label">
  2736 			<th scope="row" class="label">
  2549 				<label for="caption"><span class="alignleft">' . __('Image Caption') . '</span></label>
  2737 				<label for="caption"><span class="alignleft">' . __( 'Image Caption' ) . '</span></label>
  2550 			</th>
  2738 			</th>
  2551 			<td class="field"><textarea id="caption" name="caption"></textarea></td>
  2739 			<td class="field"><textarea id="caption" name="caption"></textarea></td>
  2552 		</tr>
  2740 		</tr>
  2553 ';
  2741 ';
  2554 	} else {
  2742 	} else {
  2555 		$caption = '';
  2743 		$caption = '';
  2556 	}
  2744 	}
  2557 
  2745 
  2558 	$default_align = get_option('image_default_align');
  2746 	$default_align = get_option( 'image_default_align' );
  2559 	if ( empty($default_align) )
  2747 	if ( empty( $default_align ) ) {
  2560 		$default_align = 'none';
  2748 		$default_align = 'none';
       
  2749 	}
  2561 
  2750 
  2562 	if ( 'image' == $default_view ) {
  2751 	if ( 'image' == $default_view ) {
  2563 		$view = 'image-only';
  2752 		$view        = 'image-only';
  2564 		$table_class = '';
  2753 		$table_class = '';
  2565 	} else {
  2754 	} else {
  2566 		$view = $table_class = 'not-image';
  2755 		$view = $table_class = 'not-image';
  2567 	}
  2756 	}
  2568 
  2757 
  2573 		<tr>
  2762 		<tr>
  2574 			<th scope="row" class="label" style="width:130px;">
  2763 			<th scope="row" class="label" style="width:130px;">
  2575 				<label for="src"><span class="alignleft">' . __( 'URL' ) . '</span> <span class="required">*</span></label>
  2764 				<label for="src"><span class="alignleft">' . __( 'URL' ) . '</span> <span class="required">*</span></label>
  2576 				<span class="alignright" id="status_img"></span>
  2765 				<span class="alignright" id="status_img"></span>
  2577 			</th>
  2766 			</th>
  2578 			<td class="field"><input id="src" name="src" value="" type="text" required aria-required="true" onblur="addExtImage.getImageData()" /></td>
  2767 			<td class="field"><input id="src" name="src" value="" type="text" required onblur="addExtImage.getImageData()" /></td>
  2579 		</tr>
  2768 		</tr>
  2580 
  2769 
  2581 		<tr>
  2770 		<tr>
  2582 			<th scope="row" class="label">
  2771 			<th scope="row" class="label">
  2583 				<label for="title"><span class="alignleft">' . __( 'Title' ) . '</span> <span class="required">*</span></label>
  2772 				<label for="title"><span class="alignleft">' . __( 'Title' ) . '</span> <span class="required">*</span></label>
  2584 			</th>
  2773 			</th>
  2585 			<td class="field"><input id="title" name="title" value="" type="text" required aria-required="true" /></td>
  2774 			<td class="field"><input id="title" name="title" value="" type="text" required /></td>
  2586 		</tr>
  2775 		</tr>
  2587 
  2776 
  2588 		<tr class="not-image"><td></td><td><p class="help">' . __('Link text, e.g. &#8220;Ransom Demands (PDF)&#8221;') . '</p></td></tr>
  2777 		<tr class="not-image"><td></td><td><p class="help">' . __( 'Link text, e.g. &#8220;Ransom Demands (PDF)&#8221;' ) . '</p></td></tr>
  2589 
  2778 
  2590 		<tr class="image-only">
  2779 		<tr class="image-only">
  2591 			<th scope="row" class="label">
  2780 			<th scope="row" class="label">
  2592 				<label for="alt"><span class="alignleft">' . __('Alternative Text') . '</span></label>
  2781 				<label for="alt"><span class="alignleft">' . __( 'Alternative Text' ) . '</span></label>
  2593 			</th>
  2782 			</th>
  2594 			<td class="field"><input id="alt" name="alt" value="" type="text" aria-required="true" />
  2783 			<td class="field"><input id="alt" name="alt" value="" type="text" required />
  2595 			<p class="help">' . __('Alt text for the image, e.g. &#8220;The Mona Lisa&#8221;') . '</p></td>
  2784 			<p class="help">' . __( 'Alt text for the image, e.g. &#8220;The Mona Lisa&#8221;' ) . '</p></td>
  2596 		</tr>
  2785 		</tr>
  2597 		' . $caption . '
  2786 		' . $caption . '
  2598 		<tr class="align image-only">
  2787 		<tr class="align image-only">
  2599 			<th scope="row" class="label"><p><label for="align">' . __('Alignment') . '</label></p></th>
  2788 			<th scope="row" class="label"><p><label for="align">' . __( 'Alignment' ) . '</label></p></th>
  2600 			<td class="field">
  2789 			<td class="field">
  2601 				<input name="align" id="align-none" value="none" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'none' ? ' checked="checked"' : '').' />
  2790 				<input name="align" id="align-none" value="none" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ( $default_align == 'none' ? ' checked="checked"' : '' ) . ' />
  2602 				<label for="align-none" class="align image-align-none-label">' . __('None') . '</label>
  2791 				<label for="align-none" class="align image-align-none-label">' . __( 'None' ) . '</label>
  2603 				<input name="align" id="align-left" value="left" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'left' ? ' checked="checked"' : '').' />
  2792 				<input name="align" id="align-left" value="left" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ( $default_align == 'left' ? ' checked="checked"' : '' ) . ' />
  2604 				<label for="align-left" class="align image-align-left-label">' . __('Left') . '</label>
  2793 				<label for="align-left" class="align image-align-left-label">' . __( 'Left' ) . '</label>
  2605 				<input name="align" id="align-center" value="center" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'center' ? ' checked="checked"' : '').' />
  2794 				<input name="align" id="align-center" value="center" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ( $default_align == 'center' ? ' checked="checked"' : '' ) . ' />
  2606 				<label for="align-center" class="align image-align-center-label">' . __('Center') . '</label>
  2795 				<label for="align-center" class="align image-align-center-label">' . __( 'Center' ) . '</label>
  2607 				<input name="align" id="align-right" value="right" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'right' ? ' checked="checked"' : '').' />
  2796 				<input name="align" id="align-right" value="right" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ( $default_align == 'right' ? ' checked="checked"' : '' ) . ' />
  2608 				<label for="align-right" class="align image-align-right-label">' . __('Right') . '</label>
  2797 				<label for="align-right" class="align image-align-right-label">' . __( 'Right' ) . '</label>
  2609 			</td>
  2798 			</td>
  2610 		</tr>
  2799 		</tr>
  2611 
  2800 
  2612 		<tr class="image-only">
  2801 		<tr class="image-only">
  2613 			<th scope="row" class="label">
  2802 			<th scope="row" class="label">
  2614 				<label for="url"><span class="alignleft">' . __('Link Image To:') . '</span></label>
  2803 				<label for="url"><span class="alignleft">' . __( 'Link Image To:' ) . '</span></label>
  2615 			</th>
  2804 			</th>
  2616 			<td class="field"><input id="url" name="url" value="" type="text" /><br />
  2805 			<td class="field"><input id="url" name="url" value="" type="text" /><br />
  2617 
  2806 
  2618 			<button type="button" class="button" value="" onclick="document.forms[0].url.value=null">' . __('None') . '</button>
  2807 			<button type="button" class="button" value="" onclick="document.forms[0].url.value=null">' . __( 'None' ) . '</button>
  2619 			<button type="button" class="button" value="" onclick="document.forms[0].url.value=document.forms[0].src.value">' . __('Link to image') . '</button>
  2808 			<button type="button" class="button" value="" onclick="document.forms[0].url.value=document.forms[0].src.value">' . __( 'Link to image' ) . '</button>
  2620 			<p class="help">' . __('Enter a link URL or click above for presets.') . '</p></td>
  2809 			<p class="help">' . __( 'Enter a link URL or click above for presets.' ) . '</p></td>
  2621 		</tr>
  2810 		</tr>
  2622 		<tr class="image-only">
  2811 		<tr class="image-only">
  2623 			<td></td>
  2812 			<td></td>
  2624 			<td>
  2813 			<td>
  2625 				<input type="button" class="button" id="go_button" style="color:#bbb;" onclick="addExtImage.insert()" value="' . esc_attr__('Insert into Post') . '" />
  2814 				<input type="button" class="button" id="go_button" style="color:#bbb;" onclick="addExtImage.insert()" value="' . esc_attr__( 'Insert into Post' ) . '" />
  2626 			</td>
  2815 			</td>
  2627 		</tr>
  2816 		</tr>
  2628 		<tr class="not-image">
  2817 		<tr class="not-image">
  2629 			<td></td>
  2818 			<td></td>
  2630 			<td>
  2819 			<td>
  2644  * @global int $post_ID
  2833  * @global int $post_ID
  2645  */
  2834  */
  2646 function media_upload_flash_bypass() {
  2835 function media_upload_flash_bypass() {
  2647 	$browser_uploader = admin_url( 'media-new.php?browser-uploader' );
  2836 	$browser_uploader = admin_url( 'media-new.php?browser-uploader' );
  2648 
  2837 
  2649 	if ( $post = get_post() )
  2838 	if ( $post = get_post() ) {
  2650 		$browser_uploader .= '&amp;post_id=' . intval( $post->ID );
  2839 		$browser_uploader .= '&amp;post_id=' . intval( $post->ID );
  2651 	elseif ( ! empty( $GLOBALS['post_ID'] ) )
  2840 	} elseif ( ! empty( $GLOBALS['post_ID'] ) ) {
  2652 		$browser_uploader .= '&amp;post_id=' . intval( $GLOBALS['post_ID'] );
  2841 		$browser_uploader .= '&amp;post_id=' . intval( $GLOBALS['post_ID'] );
       
  2842 	}
  2653 
  2843 
  2654 	?>
  2844 	?>
  2655 	<p class="upload-flash-bypass">
  2845 	<p class="upload-flash-bypass">
  2656 	<?php printf( __( 'You are using the multi-file uploader. Problems? Try the <a href="%1$s" target="%2$s">browser uploader</a> instead.' ), $browser_uploader, '_blank' ); ?>
  2846 	<?php printf( __( 'You are using the multi-file uploader. Problems? Try the <a href="%1$s" target="%2$s">browser uploader</a> instead.' ), $browser_uploader, '_blank' ); ?>
  2657 	</p>
  2847 	</p>
  2664  * @since 2.6.0
  2854  * @since 2.6.0
  2665  */
  2855  */
  2666 function media_upload_html_bypass() {
  2856 function media_upload_html_bypass() {
  2667 	?>
  2857 	?>
  2668 	<p class="upload-html-bypass hide-if-no-js">
  2858 	<p class="upload-html-bypass hide-if-no-js">
  2669 	   <?php _e('You are using the browser&#8217;s built-in file uploader. The WordPress uploader includes multiple file selection and drag and drop capability. <a href="#">Switch to the multi-file uploader</a>.'); ?>
  2859 		<?php _e( 'You are using the browser&#8217;s built-in file uploader. The WordPress uploader includes multiple file selection and drag and drop capability. <a href="#">Switch to the multi-file uploader</a>.' ); ?>
  2670 	</p>
  2860 	</p>
  2671 	<?php
  2861 	<?php
  2672 }
  2862 }
  2673 
  2863 
  2674 /**
  2864 /**
  2682  * Displays the checkbox to scale images.
  2872  * Displays the checkbox to scale images.
  2683  *
  2873  *
  2684  * @since 3.3.0
  2874  * @since 3.3.0
  2685  */
  2875  */
  2686 function media_upload_max_image_resize() {
  2876 function media_upload_max_image_resize() {
  2687 	$checked = get_user_setting('upload_resize') ? ' checked="true"' : '';
  2877 	$checked = get_user_setting( 'upload_resize' ) ? ' checked="true"' : '';
  2688 	$a = $end = '';
  2878 	$a       = $end = '';
  2689 
  2879 
  2690 	if ( current_user_can( 'manage_options' ) ) {
  2880 	if ( current_user_can( 'manage_options' ) ) {
  2691 		$a = '<a href="' . esc_url( admin_url( 'options-media.php' ) ) . '" target="_blank">';
  2881 		$a   = '<a href="' . esc_url( admin_url( 'options-media.php' ) ) . '" target="_blank">';
  2692 		$end = '</a>';
  2882 		$end = '</a>';
  2693 	}
  2883 	}
  2694 ?>
  2884 	?>
  2695 <p class="hide-if-no-js"><label>
  2885 <p class="hide-if-no-js"><label>
  2696 <input name="image_resize" type="checkbox" id="image_resize" value="true"<?php echo $checked; ?> />
  2886 <input name="image_resize" type="checkbox" id="image_resize" value="true"<?php echo $checked; ?> />
  2697 <?php
  2887 	<?php
  2698 	/* translators: %1$s is link start tag, %2$s is link end tag, %3$d is width, %4$d is height*/
  2888 	/* translators: 1: link start tag, 2: link end tag, 3: width, 4: height */
  2699 	printf( __( 'Scale images to match the large size selected in %1$simage options%2$s (%3$d &times; %4$d).' ), $a, $end, (int) get_option( 'large_size_w', '1024' ), (int) get_option( 'large_size_h', '1024' ) );
  2889 	printf( __( 'Scale images to match the large size selected in %1$simage options%2$s (%3$d &times; %4$d).' ), $a, $end, (int) get_option( 'large_size_w', '1024' ), (int) get_option( 'large_size_h', '1024' ) );
  2700 ?>
  2890 	?>
  2701 </label></p>
  2891 </label></p>
  2702 <?php
  2892 	<?php
  2703 }
  2893 }
  2704 
  2894 
  2705 /**
  2895 /**
  2706  * Displays the out of storage quota message in Multisite.
  2896  * Displays the out of storage quota message in Multisite.
  2707  *
  2897  *
  2708  * @since 3.5.0
  2898  * @since 3.5.0
  2709  */
  2899  */
  2710 function multisite_over_quota_message() {
  2900 function multisite_over_quota_message() {
  2711 	echo '<p>' . sprintf( __( 'Sorry, you have used all of your storage quota of %s MB.' ), get_space_allowed() ) . '</p>';
  2901 	echo '<p>' . sprintf(
       
  2902 		/* translators: %s: allowed space allocation */
       
  2903 		__( 'Sorry, you have used your space allocation of %s. Please delete some files to upload more files.' ),
       
  2904 		size_format( get_space_allowed() * MB_IN_BYTES )
       
  2905 	) . '</p>';
  2712 }
  2906 }
  2713 
  2907 
  2714 /**
  2908 /**
  2715  * Displays the image and editor in the post editor
  2909  * Displays the image and editor in the post editor
  2716  *
  2910  *
  2718  *
  2912  *
  2719  * @param WP_Post $post A post object.
  2913  * @param WP_Post $post A post object.
  2720  */
  2914  */
  2721 function edit_form_image_editor( $post ) {
  2915 function edit_form_image_editor( $post ) {
  2722 	$open = isset( $_GET['image-editor'] );
  2916 	$open = isset( $_GET['image-editor'] );
  2723 	if ( $open )
  2917 	if ( $open ) {
  2724 		require_once ABSPATH . 'wp-admin/includes/image-edit.php';
  2918 		require_once ABSPATH . 'wp-admin/includes/image-edit.php';
       
  2919 	}
  2725 
  2920 
  2726 	$thumb_url = false;
  2921 	$thumb_url = false;
  2727 	if ( $attachment_id = intval( $post->ID ) )
  2922 	if ( $attachment_id = intval( $post->ID ) ) {
  2728 		$thumb_url = wp_get_attachment_image_src( $attachment_id, array( 900, 450 ), true );
  2923 		$thumb_url = wp_get_attachment_image_src( $attachment_id, array( 900, 450 ), true );
       
  2924 	}
  2729 
  2925 
  2730 	$alt_text = get_post_meta( $post->ID, '_wp_attachment_image_alt', true );
  2926 	$alt_text = get_post_meta( $post->ID, '_wp_attachment_image_alt', true );
  2731 
  2927 
  2732 	$att_url = wp_get_attachment_url( $post->ID ); ?>
  2928 	$att_url = wp_get_attachment_url( $post->ID );
       
  2929 	?>
  2733 	<div class="wp_attachment_holder wp-clearfix">
  2930 	<div class="wp_attachment_holder wp-clearfix">
  2734 	<?php
  2931 	<?php
  2735 	if ( wp_attachment_is_image( $post->ID ) ) :
  2932 	if ( wp_attachment_is_image( $post->ID ) ) :
  2736 		$image_edit_button = '';
  2933 		$image_edit_button = '';
  2737 		if ( wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) {
  2934 		if ( wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) {
  2738 			$nonce = wp_create_nonce( "image_editor-$post->ID" );
  2935 			$nonce             = wp_create_nonce( "image_editor-$post->ID" );
  2739 			$image_edit_button = "<input type='button' id='imgedit-open-btn-$post->ID' onclick='imageEdit.open( $post->ID, \"$nonce\" )' class='button' value='" . esc_attr__( 'Edit Image' ) . "' /> <span class='spinner'></span>";
  2936 			$image_edit_button = "<input type='button' id='imgedit-open-btn-$post->ID' onclick='imageEdit.open( $post->ID, \"$nonce\" )' class='button' value='" . esc_attr__( 'Edit Image' ) . "' /> <span class='spinner'></span>";
  2740 		}
  2937 		}
  2741 	?>
  2938 
       
  2939 		$open_style = $not_open_style = '';
       
  2940 		if ( $open ) {
       
  2941 			$open_style = ' style="display:none"';
       
  2942 		} else {
       
  2943 			$not_open_style = ' style="display:none"';
       
  2944 		}
       
  2945 		?>
  2742 
  2946 
  2743 		<div class="imgedit-response" id="imgedit-response-<?php echo $attachment_id; ?>"></div>
  2947 		<div class="imgedit-response" id="imgedit-response-<?php echo $attachment_id; ?>"></div>
  2744 
  2948 
  2745 		<div<?php if ( $open ) echo ' style="display:none"'; ?> class="wp_attachment_image wp-clearfix" id="media-head-<?php echo $attachment_id; ?>">
  2949 		<div<?php echo $open_style; ?> class="wp_attachment_image wp-clearfix" id="media-head-<?php echo $attachment_id; ?>">
  2746 			<p id="thumbnail-head-<?php echo $attachment_id; ?>"><img class="thumbnail" src="<?php echo set_url_scheme( $thumb_url[0] ); ?>" style="max-width:100%" alt="" /></p>
  2950 			<p id="thumbnail-head-<?php echo $attachment_id; ?>"><img class="thumbnail" src="<?php echo set_url_scheme( $thumb_url[0] ); ?>" style="max-width:100%" alt="" /></p>
  2747 			<p><?php echo $image_edit_button; ?></p>
  2951 			<p><?php echo $image_edit_button; ?></p>
  2748 		</div>
  2952 		</div>
  2749 		<div<?php if ( ! $open ) echo ' style="display:none"'; ?> class="image-editor" id="image-editor-<?php echo $attachment_id; ?>">
  2953 		<div<?php echo $not_open_style; ?> class="image-editor" id="image-editor-<?php echo $attachment_id; ?>">
  2750 			<?php if ( $open ) wp_image_editor( $attachment_id ); ?>
  2954 			<?php
       
  2955 			if ( $open ) {
       
  2956 				wp_image_editor( $attachment_id );}
       
  2957 			?>
  2751 		</div>
  2958 		</div>
  2752 	<?php
  2959 		<?php
  2753 	elseif ( $attachment_id && wp_attachment_is( 'audio', $post ) ):
  2960 	elseif ( $attachment_id && wp_attachment_is( 'audio', $post ) ) :
  2754 
  2961 
  2755 		wp_maybe_generate_attachment_metadata( $post );
  2962 		wp_maybe_generate_attachment_metadata( $post );
  2756 
  2963 
  2757 		echo wp_audio_shortcode( array( 'src' => $att_url ) );
  2964 		echo wp_audio_shortcode( array( 'src' => $att_url ) );
  2758 
  2965 
  2759 	elseif ( $attachment_id && wp_attachment_is( 'video', $post ) ):
  2966 	elseif ( $attachment_id && wp_attachment_is( 'video', $post ) ) :
  2760 
  2967 
  2761 		wp_maybe_generate_attachment_metadata( $post );
  2968 		wp_maybe_generate_attachment_metadata( $post );
  2762 
  2969 
  2763 		$meta = wp_get_attachment_metadata( $attachment_id );
  2970 		$meta = wp_get_attachment_metadata( $attachment_id );
  2764 		$w = ! empty( $meta['width'] ) ? min( $meta['width'], 640 ) : 0;
  2971 		$w    = ! empty( $meta['width'] ) ? min( $meta['width'], 640 ) : 0;
  2765 		$h = ! empty( $meta['height'] ) ? $meta['height'] : 0;
  2972 		$h    = ! empty( $meta['height'] ) ? $meta['height'] : 0;
  2766 		if ( $h && $w < $meta['width'] ) {
  2973 		if ( $h && $w < $meta['width'] ) {
  2767 			$h = round( ( $meta['height'] * $w ) / $meta['width'] );
  2974 			$h = round( ( $meta['height'] * $w ) / $meta['width'] );
  2768 		}
  2975 		}
  2769 
  2976 
  2770 		$attr = array( 'src' => $att_url );
  2977 		$attr = array( 'src' => $att_url );
  2771 		if ( ! empty( $w ) && ! empty( $h ) ) {
  2978 		if ( ! empty( $w ) && ! empty( $h ) ) {
  2772 			$attr['width'] = $w;
  2979 			$attr['width']  = $w;
  2773 			$attr['height'] = $h;
  2980 			$attr['height'] = $h;
  2774 		}
  2981 		}
  2775 
  2982 
  2776 		$thumb_id = get_post_thumbnail_id( $attachment_id );
  2983 		$thumb_id = get_post_thumbnail_id( $attachment_id );
  2777 		if ( ! empty( $thumb_id ) ) {
  2984 		if ( ! empty( $thumb_id ) ) {
  2778 			$attr['poster'] = wp_get_attachment_url( $thumb_id );
  2985 			$attr['poster'] = wp_get_attachment_url( $thumb_id );
  2779 		}
  2986 		}
  2780 
  2987 
  2781 		echo wp_video_shortcode( $attr );
  2988 		echo wp_video_shortcode( $attr );
  2782 
  2989 
  2783 	elseif ( isset( $thumb_url[0] ) ):
  2990 	elseif ( isset( $thumb_url[0] ) ) :
  2784 
  2991 
  2785 		?>
  2992 		?>
  2786 		<div class="wp_attachment_image wp-clearfix" id="media-head-<?php echo $attachment_id; ?>">
  2993 		<div class="wp_attachment_image wp-clearfix" id="media-head-<?php echo $attachment_id; ?>">
  2787 			<p id="thumbnail-head-<?php echo $attachment_id; ?>">
  2994 			<p id="thumbnail-head-<?php echo $attachment_id; ?>">
  2788 				<img class="thumbnail" src="<?php echo set_url_scheme( $thumb_url[0] ); ?>" style="max-width:100%" alt="" />
  2995 				<img class="thumbnail" src="<?php echo set_url_scheme( $thumb_url[0] ); ?>" style="max-width:100%" alt="" />
  2789 			</p>
  2996 			</p>
  2790 		</div>
  2997 		</div>
  2791 		<?php
  2998 		<?php
  2792 
  2999 
  2793 	else:
  3000 	else :
  2794 
  3001 
  2795 		/**
  3002 		/**
  2796 		 * Fires when an attachment type can't be rendered in the edit form.
  3003 		 * Fires when an attachment type can't be rendered in the edit form.
  2797 		 *
  3004 		 *
  2798 		 * @since 4.6.0
  3005 		 * @since 4.6.0
  2799 		 *
  3006 		 *
  2800 		 * @param WP_Post $post A post object.
  3007 		 * @param WP_Post $post A post object.
  2801 		 */
  3008 		 */
  2802 		do_action( 'wp_edit_form_attachment_display', $post );
  3009 		do_action( 'wp_edit_form_attachment_display', $post );
  2803 
  3010 
  2804 	endif; ?>
  3011 	endif;
       
  3012 	?>
  2805 	</div>
  3013 	</div>
  2806 	<div class="wp_attachment_details edit-form-section">
  3014 	<div class="wp_attachment_details edit-form-section">
       
  3015 	<?php if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) : ?>
       
  3016 		<p class="attachment-alt-text">
       
  3017 			<label for="attachment_alt"><strong><?php _e( 'Alternative Text' ); ?></strong></label><br />
       
  3018 			<input type="text" class="widefat" name="_wp_attachment_image_alt" id="attachment_alt" aria-describedby="alt-text-description" value="<?php echo esc_attr( $alt_text ); ?>" />
       
  3019 		</p>
       
  3020 		<p class="attachment-alt-text-description" id="alt-text-description">
       
  3021 			<?php
       
  3022 			printf(
       
  3023 				/* translators: 1: link to tutorial, 2: additional link attributes, 3: accessibility text */
       
  3024 				__( '<a href="%1$s" %2$s>Describe the purpose of the image%3$s</a>. Leave empty if the image is purely decorative.' ),
       
  3025 				esc_url( 'https://www.w3.org/WAI/tutorials/images/decision-tree' ),
       
  3026 				'target="_blank" rel="noopener noreferrer"',
       
  3027 				sprintf(
       
  3028 					'<span class="screen-reader-text"> %s</span>',
       
  3029 					/* translators: accessibility text */
       
  3030 					__( '(opens in a new tab)' )
       
  3031 				)
       
  3032 			);
       
  3033 			?>
       
  3034 		</p>
       
  3035 	<?php endif; ?>
       
  3036 
  2807 		<p>
  3037 		<p>
  2808 			<label for="attachment_caption"><strong><?php _e( 'Caption' ); ?></strong></label><br />
  3038 			<label for="attachment_caption"><strong><?php _e( 'Caption' ); ?></strong></label><br />
  2809 			<textarea class="widefat" name="excerpt" id="attachment_caption"><?php echo $post->post_excerpt; ?></textarea>
  3039 			<textarea class="widefat" name="excerpt" id="attachment_caption"><?php echo $post->post_excerpt; ?></textarea>
  2810 		</p>
  3040 		</p>
  2811 
  3041 
  2812 
       
  2813 	<?php if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) : ?>
       
  2814 		<p>
       
  2815 			<label for="attachment_alt"><strong><?php _e( 'Alternative Text' ); ?></strong></label><br />
       
  2816 			<input type="text" class="widefat" name="_wp_attachment_image_alt" id="attachment_alt" value="<?php echo esc_attr( $alt_text ); ?>" />
       
  2817 		</p>
       
  2818 	<?php endif; ?>
       
  2819 
       
  2820 	<?php
  3042 	<?php
  2821 		$quicktags_settings = array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,close' );
  3043 		$quicktags_settings = array( 'buttons' => 'strong,em,link,block,del,ins,img,ul,ol,li,code,close' );
  2822 		$editor_args = array(
  3044 		$editor_args        = array(
  2823 			'textarea_name' => 'content',
  3045 			'textarea_name' => 'content',
  2824 			'textarea_rows' => 5,
  3046 			'textarea_rows' => 5,
  2825 			'media_buttons' => false,
  3047 			'media_buttons' => false,
  2826 			'tinymce' => false,
  3048 			'tinymce'       => false,
  2827 			'quicktags' => $quicktags_settings,
  3049 			'quicktags'     => $quicktags_settings,
  2828 		);
  3050 		);
  2829 	?>
  3051 	?>
  2830 
  3052 
  2831 	<label for="attachment_content"><strong><?php _e( 'Description' ); ?></strong><?php
  3053 	<label for="attachment_content"><strong><?php _e( 'Description' ); ?></strong>
  2832 	if ( preg_match( '#^(audio|video)/#', $post->post_mime_type ) ) {
  3054 		<?php
  2833 		echo ': ' . __( 'Displayed on attachment pages.' );
  3055 		if ( preg_match( '#^(audio|video)/#', $post->post_mime_type ) ) {
  2834 	} ?></label>
  3056 			echo ': ' . __( 'Displayed on attachment pages.' );
       
  3057 		}
       
  3058 		?>
       
  3059 	</label>
  2835 	<?php wp_editor( $post->post_content, 'attachment_content', $editor_args ); ?>
  3060 	<?php wp_editor( $post->post_content, 'attachment_content', $editor_args ); ?>
  2836 
  3061 
  2837 	</div>
  3062 	</div>
  2838 	<?php
  3063 	<?php
  2839 	$extras = get_compat_media_markup( $post->ID );
  3064 	$extras = get_compat_media_markup( $post->ID );
  2847  * @since 3.5.0
  3072  * @since 3.5.0
  2848  */
  3073  */
  2849 function attachment_submitbox_metadata() {
  3074 function attachment_submitbox_metadata() {
  2850 	$post = get_post();
  3075 	$post = get_post();
  2851 
  3076 
  2852 	$file = get_attached_file( $post->ID );
  3077 	$file     = get_attached_file( $post->ID );
  2853 	$filename = esc_html( wp_basename( $file ) );
  3078 	$filename = esc_html( wp_basename( $file ) );
  2854 
  3079 
  2855 	$media_dims = '';
  3080 	$media_dims = '';
  2856 	$meta = wp_get_attachment_metadata( $post->ID );
  3081 	$meta       = wp_get_attachment_metadata( $post->ID );
  2857 	if ( isset( $meta['width'], $meta['height'] ) )
  3082 	if ( isset( $meta['width'], $meta['height'] ) ) {
  2858 		$media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']}&nbsp;&times;&nbsp;{$meta['height']}</span> ";
  3083 		$media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']}&nbsp;&times;&nbsp;{$meta['height']}</span> ";
       
  3084 	}
  2859 	/** This filter is documented in wp-admin/includes/media.php */
  3085 	/** This filter is documented in wp-admin/includes/media.php */
  2860 	$media_dims = apply_filters( 'media_meta', $media_dims, $post );
  3086 	$media_dims = apply_filters( 'media_meta', $media_dims, $post );
  2861 
  3087 
  2862 	$att_url = wp_get_attachment_url( $post->ID );
  3088 	$att_url = wp_get_attachment_url( $post->ID );
  2863 ?>
  3089 	?>
  2864 	<div class="misc-pub-section misc-pub-attachment">
  3090 	<div class="misc-pub-section misc-pub-attachment">
  2865 		<label for="attachment_url"><?php _e( 'File URL:' ); ?></label>
  3091 		<label for="attachment_url"><?php _e( 'File URL:' ); ?></label>
  2866 		<input type="text" class="widefat urlfield" readonly="readonly" name="attachment_url" id="attachment_url" value="<?php echo esc_attr( $att_url ); ?>" />
  3092 		<input type="text" class="widefat urlfield" readonly="readonly" name="attachment_url" id="attachment_url" value="<?php echo esc_attr( $att_url ); ?>" />
  2867 	</div>
  3093 	</div>
  2868 	<div class="misc-pub-section misc-pub-filename">
  3094 	<div class="misc-pub-section misc-pub-filename">
  2869 		<?php _e( 'File name:' ); ?> <strong><?php echo $filename; ?></strong>
  3095 		<?php _e( 'File name:' ); ?> <strong><?php echo $filename; ?></strong>
  2870 	</div>
  3096 	</div>
  2871 	<div class="misc-pub-section misc-pub-filetype">
  3097 	<div class="misc-pub-section misc-pub-filetype">
  2872 		<?php _e( 'File type:' ); ?> <strong><?php
  3098 		<?php _e( 'File type:' ); ?> <strong>
  2873 			if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $post->ID ), $matches ) ) {
  3099 					<?php
  2874 				echo esc_html( strtoupper( $matches[1] ) );
  3100 					if ( preg_match( '/^.*?\.(\w+)$/', get_attached_file( $post->ID ), $matches ) ) {
  2875 				list( $mime_type ) = explode( '/', $post->post_mime_type );
  3101 						echo esc_html( strtoupper( $matches[1] ) );
  2876 				if ( $mime_type !== 'image' && ! empty( $meta['mime_type'] ) ) {
  3102 						list( $mime_type ) = explode( '/', $post->post_mime_type );
  2877 					if ( $meta['mime_type'] !== "$mime_type/" . strtolower( $matches[1] ) ) {
  3103 						if ( $mime_type !== 'image' && ! empty( $meta['mime_type'] ) ) {
  2878 						echo ' (' . $meta['mime_type'] . ')';
  3104 							if ( $meta['mime_type'] !== "$mime_type/" . strtolower( $matches[1] ) ) {
       
  3105 								echo ' (' . $meta['mime_type'] . ')';
       
  3106 							}
       
  3107 						}
       
  3108 					} else {
       
  3109 						echo strtoupper( str_replace( 'image/', '', $post->post_mime_type ) );
  2879 					}
  3110 					}
  2880 				}
  3111 					?>
  2881 			} else {
  3112 		</strong>
  2882 				echo strtoupper( str_replace( 'image/', '', $post->post_mime_type ) );
       
  2883 			}
       
  2884 		?></strong>
       
  2885 	</div>
  3113 	</div>
  2886 
  3114 
  2887 	<?php
  3115 	<?php
  2888 		$file_size = false;
  3116 		$file_size = false;
  2889 
  3117 
  2890 		if ( isset( $meta['filesize'] ) )
  3118 	if ( isset( $meta['filesize'] ) ) {
  2891 			$file_size = $meta['filesize'];
  3119 		$file_size = $meta['filesize'];
  2892 		elseif ( file_exists( $file ) )
  3120 	} elseif ( file_exists( $file ) ) {
  2893 			$file_size = filesize( $file );
  3121 		$file_size = filesize( $file );
  2894 
  3122 	}
  2895 		if ( ! empty( $file_size ) ) : ?>
  3123 
       
  3124 	if ( ! empty( $file_size ) ) :
       
  3125 		?>
  2896 			<div class="misc-pub-section misc-pub-filesize">
  3126 			<div class="misc-pub-section misc-pub-filesize">
  2897 				<?php _e( 'File size:' ); ?> <strong><?php echo size_format( $file_size ); ?></strong>
  3127 				<?php _e( 'File size:' ); ?> <strong><?php echo size_format( $file_size ); ?></strong>
  2898 			</div>
  3128 			</div>
  2899 			<?php
  3129 			<?php
  2900 		endif;
  3130 		endif;
  2921 
  3151 
  2922 		foreach ( $fields as $key => $label ) {
  3152 		foreach ( $fields as $key => $label ) {
  2923 			if ( empty( $meta[ $key ] ) ) {
  3153 			if ( empty( $meta[ $key ] ) ) {
  2924 				continue;
  3154 				continue;
  2925 			}
  3155 			}
  2926 	?>
  3156 			?>
  2927 		<div class="misc-pub-section misc-pub-mime-meta misc-pub-<?php echo sanitize_html_class( $key ); ?>">
  3157 		<div class="misc-pub-section misc-pub-mime-meta misc-pub-<?php echo sanitize_html_class( $key ); ?>">
  2928 			<?php echo $label ?> <strong><?php
  3158 			<?php echo $label; ?> <strong>
  2929 				switch ( $key ) {
  3159 						<?php
  2930 					case 'bitrate' :
  3160 						switch ( $key ) {
  2931 						echo round( $meta['bitrate'] / 1000 ) . 'kb/s';
  3161 							case 'bitrate':
  2932 						if ( ! empty( $meta['bitrate_mode'] ) ) {
  3162 								echo round( $meta['bitrate'] / 1000 ) . 'kb/s';
  2933 							echo ' ' . strtoupper( esc_html( $meta['bitrate_mode'] ) );
  3163 								if ( ! empty( $meta['bitrate_mode'] ) ) {
       
  3164 									echo ' ' . strtoupper( esc_html( $meta['bitrate_mode'] ) );
       
  3165 								}
       
  3166 								break;
       
  3167 							default:
       
  3168 								echo esc_html( $meta[ $key ] );
       
  3169 								break;
  2934 						}
  3170 						}
  2935 						break;
  3171 						?>
  2936 					default:
  3172 			</strong>
  2937 						echo esc_html( $meta[ $key ] );
       
  2938 						break;
       
  2939 				}
       
  2940 			?></strong>
       
  2941 		</div>
  3173 		</div>
  2942 	<?php
  3174 			<?php
  2943 		}
  3175 		}
  2944 
  3176 
  2945 		$fields = array(
  3177 		$fields = array(
  2946 			'dataformat' => __( 'Audio Format:' ),
  3178 			'dataformat' => __( 'Audio Format:' ),
  2947 			'codec'      => __( 'Audio Codec:' )
  3179 			'codec'      => __( 'Audio Codec:' ),
  2948 		);
  3180 		);
  2949 
  3181 
  2950 		/**
  3182 		/**
  2951 		 * Filters the audio attachment metadata fields to be shown in the publish meta box.
  3183 		 * Filters the audio attachment metadata fields to be shown in the publish meta box.
  2952 		 *
  3184 		 *
  2963 
  3195 
  2964 		foreach ( $audio_fields as $key => $label ) {
  3196 		foreach ( $audio_fields as $key => $label ) {
  2965 			if ( empty( $meta['audio'][ $key ] ) ) {
  3197 			if ( empty( $meta['audio'][ $key ] ) ) {
  2966 				continue;
  3198 				continue;
  2967 			}
  3199 			}
  2968 	?>
  3200 			?>
  2969 		<div class="misc-pub-section misc-pub-audio misc-pub-<?php echo sanitize_html_class( $key ); ?>">
  3201 		<div class="misc-pub-section misc-pub-audio misc-pub-<?php echo sanitize_html_class( $key ); ?>">
  2970 			<?php echo $label; ?> <strong><?php echo esc_html( $meta['audio'][$key] ); ?></strong>
  3202 			<?php echo $label; ?> <strong><?php echo esc_html( $meta['audio'][ $key ] ); ?></strong>
  2971 		</div>
  3203 		</div>
  2972 	<?php
  3204 			<?php
  2973 		}
  3205 		}
  2974 
  3206 	}
  2975 	}
  3207 
  2976 
  3208 	if ( $media_dims ) :
  2977 	if ( $media_dims ) : ?>
  3209 		?>
  2978 	<div class="misc-pub-section misc-pub-dimensions">
  3210 	<div class="misc-pub-section misc-pub-dimensions">
  2979 		<?php _e( 'Dimensions:' ); ?> <strong><?php echo $media_dims; ?></strong>
  3211 		<?php _e( 'Dimensions:' ); ?> <strong><?php echo $media_dims; ?></strong>
  2980 	</div>
  3212 	</div>
  2981 <?php
  3213 		<?php
  2982 	endif;
  3214 	endif;
  2983 }
  3215 }
  2984 
  3216 
  2985 /**
  3217 /**
  2986  * Parse ID3v2, ID3v1, and getID3 comments to extract usable data
  3218  * Parse ID3v2, ID3v1, and getID3 comments to extract usable data
  2990  * @param array $metadata An existing array with data
  3222  * @param array $metadata An existing array with data
  2991  * @param array $data Data supplied by ID3 tags
  3223  * @param array $data Data supplied by ID3 tags
  2992  */
  3224  */
  2993 function wp_add_id3_tag_data( &$metadata, $data ) {
  3225 function wp_add_id3_tag_data( &$metadata, $data ) {
  2994 	foreach ( array( 'id3v2', 'id3v1' ) as $version ) {
  3226 	foreach ( array( 'id3v2', 'id3v1' ) as $version ) {
  2995 		if ( ! empty( $data[$version]['comments'] ) ) {
  3227 		if ( ! empty( $data[ $version ]['comments'] ) ) {
  2996 			foreach ( $data[$version]['comments'] as $key => $list ) {
  3228 			foreach ( $data[ $version ]['comments'] as $key => $list ) {
  2997 				if ( 'length' !== $key && ! empty( $list ) ) {
  3229 				if ( 'length' !== $key && ! empty( $list ) ) {
  2998 					$metadata[$key] = wp_kses_post( reset( $list ) );
  3230 					$metadata[ $key ] = wp_kses_post( reset( $list ) );
  2999 					// Fix bug in byte stream analysis.
  3231 					// Fix bug in byte stream analysis.
  3000 					if ( 'terms_of_use' === $key && 0 === strpos( $metadata[$key], 'yright notice.' ) )
  3232 					if ( 'terms_of_use' === $key && 0 === strpos( $metadata[ $key ], 'yright notice.' ) ) {
  3001 						$metadata[$key] = 'Cop' . $metadata[$key];
  3233 						$metadata[ $key ] = 'Cop' . $metadata[ $key ];
       
  3234 					}
  3002 				}
  3235 				}
  3003 			}
  3236 			}
  3004 			break;
  3237 			break;
  3005 		}
  3238 		}
  3006 	}
  3239 	}
  3007 
  3240 
  3008 	if ( ! empty( $data['id3v2']['APIC'] ) ) {
  3241 	if ( ! empty( $data['id3v2']['APIC'] ) ) {
  3009 		$image = reset( $data['id3v2']['APIC']);
  3242 		$image = reset( $data['id3v2']['APIC'] );
  3010 		if ( ! empty( $image['data'] ) ) {
  3243 		if ( ! empty( $image['data'] ) ) {
  3011 			$metadata['image'] = array(
  3244 			$metadata['image'] = array(
  3012 				'data' => $image['data'],
  3245 				'data'   => $image['data'],
  3013 				'mime' => $image['image_mime'],
  3246 				'mime'   => $image['image_mime'],
  3014 				'width' => $image['image_width'],
  3247 				'width'  => $image['image_width'],
  3015 				'height' => $image['image_height']
  3248 				'height' => $image['image_height'],
  3016 			);
  3249 			);
  3017 		}
  3250 		}
  3018 	} elseif ( ! empty( $data['comments']['picture'] ) ) {
  3251 	} elseif ( ! empty( $data['comments']['picture'] ) ) {
  3019 		$image = reset( $data['comments']['picture'] );
  3252 		$image = reset( $data['comments']['picture'] );
  3020 		if ( ! empty( $image['data'] ) ) {
  3253 		if ( ! empty( $image['data'] ) ) {
  3021 			$metadata['image'] = array(
  3254 			$metadata['image'] = array(
  3022 				'data' => $image['data'],
  3255 				'data' => $image['data'],
  3023 				'mime' => $image['image_mime']
  3256 				'mime' => $image['image_mime'],
  3024 			);
  3257 			);
  3025 		}
  3258 		}
  3026 	}
  3259 	}
  3027 }
  3260 }
  3028 
  3261 
  3046 	}
  3279 	}
  3047 
  3280 
  3048 	if ( ! class_exists( 'getID3', false ) ) {
  3281 	if ( ! class_exists( 'getID3', false ) ) {
  3049 		require( ABSPATH . WPINC . '/ID3/getid3.php' );
  3282 		require( ABSPATH . WPINC . '/ID3/getid3.php' );
  3050 	}
  3283 	}
  3051 	$id3 = new getID3();
  3284 	$id3  = new getID3();
  3052 	$data = $id3->analyze( $file );
  3285 	$data = $id3->analyze( $file );
  3053 
  3286 
  3054 	if ( isset( $data['video']['lossless'] ) )
  3287 	if ( isset( $data['video']['lossless'] ) ) {
  3055 		$metadata['lossless'] = $data['video']['lossless'];
  3288 		$metadata['lossless'] = $data['video']['lossless'];
  3056 	if ( ! empty( $data['video']['bitrate'] ) )
  3289 	}
       
  3290 	if ( ! empty( $data['video']['bitrate'] ) ) {
  3057 		$metadata['bitrate'] = (int) $data['video']['bitrate'];
  3291 		$metadata['bitrate'] = (int) $data['video']['bitrate'];
  3058 	if ( ! empty( $data['video']['bitrate_mode'] ) )
  3292 	}
       
  3293 	if ( ! empty( $data['video']['bitrate_mode'] ) ) {
  3059 		$metadata['bitrate_mode'] = $data['video']['bitrate_mode'];
  3294 		$metadata['bitrate_mode'] = $data['video']['bitrate_mode'];
  3060 	if ( ! empty( $data['filesize'] ) )
  3295 	}
       
  3296 	if ( ! empty( $data['filesize'] ) ) {
  3061 		$metadata['filesize'] = (int) $data['filesize'];
  3297 		$metadata['filesize'] = (int) $data['filesize'];
  3062 	if ( ! empty( $data['mime_type'] ) )
  3298 	}
       
  3299 	if ( ! empty( $data['mime_type'] ) ) {
  3063 		$metadata['mime_type'] = $data['mime_type'];
  3300 		$metadata['mime_type'] = $data['mime_type'];
  3064 	if ( ! empty( $data['playtime_seconds'] ) )
  3301 	}
       
  3302 	if ( ! empty( $data['playtime_seconds'] ) ) {
  3065 		$metadata['length'] = (int) round( $data['playtime_seconds'] );
  3303 		$metadata['length'] = (int) round( $data['playtime_seconds'] );
  3066 	if ( ! empty( $data['playtime_string'] ) )
  3304 	}
       
  3305 	if ( ! empty( $data['playtime_string'] ) ) {
  3067 		$metadata['length_formatted'] = $data['playtime_string'];
  3306 		$metadata['length_formatted'] = $data['playtime_string'];
  3068 	if ( ! empty( $data['video']['resolution_x'] ) )
  3307 	}
       
  3308 	if ( ! empty( $data['video']['resolution_x'] ) ) {
  3069 		$metadata['width'] = (int) $data['video']['resolution_x'];
  3309 		$metadata['width'] = (int) $data['video']['resolution_x'];
  3070 	if ( ! empty( $data['video']['resolution_y'] ) )
  3310 	}
       
  3311 	if ( ! empty( $data['video']['resolution_y'] ) ) {
  3071 		$metadata['height'] = (int) $data['video']['resolution_y'];
  3312 		$metadata['height'] = (int) $data['video']['resolution_y'];
  3072 	if ( ! empty( $data['fileformat'] ) )
  3313 	}
       
  3314 	if ( ! empty( $data['fileformat'] ) ) {
  3073 		$metadata['fileformat'] = $data['fileformat'];
  3315 		$metadata['fileformat'] = $data['fileformat'];
  3074 	if ( ! empty( $data['video']['dataformat'] ) )
  3316 	}
       
  3317 	if ( ! empty( $data['video']['dataformat'] ) ) {
  3075 		$metadata['dataformat'] = $data['video']['dataformat'];
  3318 		$metadata['dataformat'] = $data['video']['dataformat'];
  3076 	if ( ! empty( $data['video']['encoder'] ) )
  3319 	}
       
  3320 	if ( ! empty( $data['video']['encoder'] ) ) {
  3077 		$metadata['encoder'] = $data['video']['encoder'];
  3321 		$metadata['encoder'] = $data['video']['encoder'];
  3078 	if ( ! empty( $data['video']['codec'] ) )
  3322 	}
       
  3323 	if ( ! empty( $data['video']['codec'] ) ) {
  3079 		$metadata['codec'] = $data['video']['codec'];
  3324 		$metadata['codec'] = $data['video']['codec'];
       
  3325 	}
  3080 
  3326 
  3081 	if ( ! empty( $data['audio'] ) ) {
  3327 	if ( ! empty( $data['audio'] ) ) {
  3082 		unset( $data['audio']['streams'] );
  3328 		unset( $data['audio']['streams'] );
  3083 		$metadata['audio'] = $data['audio'];
  3329 		$metadata['audio'] = $data['audio'];
  3084 	}
  3330 	}
  3110 	 */
  3356 	 */
  3111 	return apply_filters( 'wp_read_video_metadata', $metadata, $file, $file_format, $data );
  3357 	return apply_filters( 'wp_read_video_metadata', $metadata, $file, $file_format, $data );
  3112 }
  3358 }
  3113 
  3359 
  3114 /**
  3360 /**
  3115  * Retrieve metadata from a audio file's ID3 tags
  3361  * Retrieve metadata from an audio file's ID3 tags.
  3116  *
  3362  *
  3117  * @since 3.6.0
  3363  * @since 3.6.0
  3118  *
  3364  *
  3119  * @param string $file Path to file.
  3365  * @param string $file Path to file.
  3120  * @return array|bool Returns array of metadata, if found.
  3366  * @return array|bool Returns array of metadata, if found.
  3130 	}
  3376 	}
  3131 
  3377 
  3132 	if ( ! class_exists( 'getID3', false ) ) {
  3378 	if ( ! class_exists( 'getID3', false ) ) {
  3133 		require( ABSPATH . WPINC . '/ID3/getid3.php' );
  3379 		require( ABSPATH . WPINC . '/ID3/getid3.php' );
  3134 	}
  3380 	}
  3135 	$id3 = new getID3();
  3381 	$id3  = new getID3();
  3136 	$data = $id3->analyze( $file );
  3382 	$data = $id3->analyze( $file );
  3137 
  3383 
  3138 	if ( ! empty( $data['audio'] ) ) {
  3384 	if ( ! empty( $data['audio'] ) ) {
  3139 		unset( $data['audio']['streams'] );
  3385 		unset( $data['audio']['streams'] );
  3140 		$metadata = $data['audio'];
  3386 		$metadata = $data['audio'];
  3141 	}
  3387 	}
  3142 
  3388 
  3143 	if ( ! empty( $data['fileformat'] ) )
  3389 	if ( ! empty( $data['fileformat'] ) ) {
  3144 		$metadata['fileformat'] = $data['fileformat'];
  3390 		$metadata['fileformat'] = $data['fileformat'];
  3145 	if ( ! empty( $data['filesize'] ) )
  3391 	}
       
  3392 	if ( ! empty( $data['filesize'] ) ) {
  3146 		$metadata['filesize'] = (int) $data['filesize'];
  3393 		$metadata['filesize'] = (int) $data['filesize'];
  3147 	if ( ! empty( $data['mime_type'] ) )
  3394 	}
       
  3395 	if ( ! empty( $data['mime_type'] ) ) {
  3148 		$metadata['mime_type'] = $data['mime_type'];
  3396 		$metadata['mime_type'] = $data['mime_type'];
  3149 	if ( ! empty( $data['playtime_seconds'] ) )
  3397 	}
       
  3398 	if ( ! empty( $data['playtime_seconds'] ) ) {
  3150 		$metadata['length'] = (int) round( $data['playtime_seconds'] );
  3399 		$metadata['length'] = (int) round( $data['playtime_seconds'] );
  3151 	if ( ! empty( $data['playtime_string'] ) )
  3400 	}
       
  3401 	if ( ! empty( $data['playtime_string'] ) ) {
  3152 		$metadata['length_formatted'] = $data['playtime_string'];
  3402 		$metadata['length_formatted'] = $data['playtime_string'];
       
  3403 	}
       
  3404 
       
  3405 	if ( empty( $metadata['created_timestamp'] ) ) {
       
  3406 		$created_timestamp = wp_get_media_creation_timestamp( $data );
       
  3407 
       
  3408 		if ( false !== $created_timestamp ) {
       
  3409 			$metadata['created_timestamp'] = $created_timestamp;
       
  3410 		}
       
  3411 	}
  3153 
  3412 
  3154 	wp_add_id3_tag_data( $metadata, $data );
  3413 	wp_add_id3_tag_data( $metadata, $data );
  3155 
  3414 
  3156 	return $metadata;
  3415 	return $metadata;
  3157 }
  3416 }
  3186 
  3445 
  3187 		case 'matroska':
  3446 		case 'matroska':
  3188 		case 'webm':
  3447 		case 'webm':
  3189 			if ( isset( $metadata['matroska']['comments']['creation_time']['0'] ) ) {
  3448 			if ( isset( $metadata['matroska']['comments']['creation_time']['0'] ) ) {
  3190 				$creation_date = strtotime( $metadata['matroska']['comments']['creation_time']['0'] );
  3449 				$creation_date = strtotime( $metadata['matroska']['comments']['creation_time']['0'] );
  3191 			}
  3450 			} elseif ( isset( $metadata['matroska']['info']['0']['DateUTC_unix'] ) ) {
  3192 			elseif ( isset( $metadata['matroska']['info']['0']['DateUTC_unix'] ) ) {
       
  3193 				$creation_date = (int) $metadata['matroska']['info']['0']['DateUTC_unix'];
  3451 				$creation_date = (int) $metadata['matroska']['info']['0']['DateUTC_unix'];
  3194 			}
  3452 			}
  3195 			break;
  3453 			break;
  3196 
  3454 
  3197 		case 'quicktime':
  3455 		case 'quicktime':
  3256 			if ( false !== strpos( $referer, 'upload.php' ) ) {
  3514 			if ( false !== strpos( $referer, 'upload.php' ) ) {
  3257 				$location = remove_query_arg( array( 'attached', 'detach' ), $referer );
  3515 				$location = remove_query_arg( array( 'attached', 'detach' ), $referer );
  3258 			}
  3516 			}
  3259 		}
  3517 		}
  3260 
  3518 
  3261 		$key = 'attach' === $action ? 'attached' : 'detach';
  3519 		$key      = 'attach' === $action ? 'attached' : 'detach';
  3262 		$location = add_query_arg( array( $key => $result ), $location );
  3520 		$location = add_query_arg( array( $key => $result ), $location );
  3263 		wp_redirect( $location );
  3521 		wp_redirect( $location );
  3264 		exit;
  3522 		exit;
  3265 	}
  3523 	}
  3266 }
  3524 }