3 * WordPress API for media display.
10 * Scale down the default size of an image.
12 * This is so that the image is a better fit for the editor and theme.
14 * The $size parameter accepts either an array or a string. The supported string
15 * values are 'thumb' or 'thumbnail' for the given thumbnail size or defaults at
16 * 128 width and 96 height in pixels. Also supported for the string value is
17 * 'medium' and 'full'. The 'full' isn't actually supported, but any value other
18 * than the supported will result in the content_width size or 500 if that is
21 * Finally, there is a filter named 'editor_max_image_size', that will be called
22 * on the calculated array for width and height, respectively. The second
23 * parameter will be the value that was in the $size parameter. The returned
24 * type for the hook is an array with the width as the first element and the
25 * height as the second element.
28 * @uses wp_constrain_dimensions() This function passes the widths and the heights.
30 * @param int $width Width of the image
31 * @param int $height Height of the image
32 * @param string|array $size Size of what the result image should be.
33 * @param context Could be 'display' (like in a theme) or 'edit' (like inserting into an editor)
34 * @return array Width and height of what the result image should resize to.
36 function image_constrain_size_for_editor($width, $height, $size = 'medium', $context = null ) {
37 global $content_width, $_wp_additional_image_sizes;
40 $context = is_admin() ? 'edit' : 'display';
42 if ( is_array($size) ) {
43 $max_width = $size[0];
44 $max_height = $size[1];
46 elseif ( $size == 'thumb' || $size == 'thumbnail' ) {
47 $max_width = intval(get_option('thumbnail_size_w'));
48 $max_height = intval(get_option('thumbnail_size_h'));
49 // last chance thumbnail size defaults
50 if ( !$max_width && !$max_height ) {
55 elseif ( $size == 'medium' ) {
56 $max_width = intval(get_option('medium_size_w'));
57 $max_height = intval(get_option('medium_size_h'));
58 // if no width is set, default to the theme content width if available
60 elseif ( $size == 'large' ) {
61 // We're inserting a large size image into the editor. If it's a really
62 // big image we'll scale it down to fit reasonably within the editor
63 // itself, and within the theme's content width if it's known. The user
64 // can resize it in the editor if they wish.
65 $max_width = intval(get_option('large_size_w'));
66 $max_height = intval(get_option('large_size_h'));
67 if ( intval($content_width) > 0 )
68 $max_width = min( intval($content_width), $max_width );
69 } elseif ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) && in_array( $size, array_keys( $_wp_additional_image_sizes ) ) ) {
70 $max_width = intval( $_wp_additional_image_sizes[$size]['width'] );
71 $max_height = intval( $_wp_additional_image_sizes[$size]['height'] );
72 if ( intval($content_width) > 0 && 'edit' == $context ) // Only in admin. Assume that theme authors know what they're doing.
73 $max_width = min( intval($content_width), $max_width );
75 // $size == 'full' has no constraint
78 $max_height = $height;
81 list( $max_width, $max_height ) = apply_filters( 'editor_max_image_size', array( $max_width, $max_height ), $size, $context );
83 return wp_constrain_dimensions( $width, $height, $max_width, $max_height );
87 * Retrieve width and height attributes using given width and height values.
89 * Both attributes are required in the sense that both parameters must have a
90 * value, but are optional in that if you set them to false or null, then they
91 * will not be added to the returned string.
93 * You can set the value using a string, but it will only take numeric values.
94 * If you wish to put 'px' after the numbers, then it will be stripped out of
99 * @param int|string $width Optional. Width attribute value.
100 * @param int|string $height Optional. Height attribute value.
101 * @return string HTML attributes for width and, or height.
103 function image_hwstring($width, $height) {
106 $out .= 'width="'.intval($width).'" ';
108 $out .= 'height="'.intval($height).'" ';
113 * Scale an image to fit a particular size (such as 'thumb' or 'medium').
115 * Array with image url, width, height, and whether is intermediate size, in
116 * that order is returned on success is returned. $is_intermediate is true if
117 * $url is a resized image, false if it is the original.
119 * The URL might be the original image, or it might be a resized version. This
120 * function won't create a new resized copy, it will just return an already
121 * resized one if it exists.
123 * A plugin may use the 'image_downsize' filter to hook into and offer image
124 * resizing services for images. The hook must return an array with the same
125 * elements that are returned in the function. The first element being the URL
126 * to the new image that was resized.
129 * @uses apply_filters() Calls 'image_downsize' on $id and $size to provide
132 * @param int $id Attachment ID for image.
133 * @param array|string $size Optional, default is 'medium'. Size of image, either array or string.
134 * @return bool|array False on failure, array on success.
136 function image_downsize($id, $size = 'medium') {
138 if ( !wp_attachment_is_image($id) )
141 $img_url = wp_get_attachment_url($id);
142 $meta = wp_get_attachment_metadata($id);
143 $width = $height = 0;
144 $is_intermediate = false;
145 $img_url_basename = wp_basename($img_url);
147 // plugins can use this to provide resize services
148 if ( $out = apply_filters('image_downsize', false, $id, $size) )
151 // try for a new style intermediate size
152 if ( $intermediate = image_get_intermediate_size($id, $size) ) {
153 $img_url = str_replace($img_url_basename, $intermediate['file'], $img_url);
154 $width = $intermediate['width'];
155 $height = $intermediate['height'];
156 $is_intermediate = true;
158 elseif ( $size == 'thumbnail' ) {
159 // fall back to the old thumbnail
160 if ( ($thumb_file = wp_get_attachment_thumb_file($id)) && $info = getimagesize($thumb_file) ) {
161 $img_url = str_replace($img_url_basename, wp_basename($thumb_file), $img_url);
164 $is_intermediate = true;
167 if ( !$width && !$height && isset($meta['width'], $meta['height']) ) {
168 // any other type: use the real image
169 $width = $meta['width'];
170 $height = $meta['height'];
174 // we have the actual image size, but might need to further constrain it if content_width is narrower
175 list( $width, $height ) = image_constrain_size_for_editor( $width, $height, $size );
177 return array( $img_url, $width, $height, $is_intermediate );
184 * Registers a new image size
188 function add_image_size( $name, $width = 0, $height = 0, $crop = false ) {
189 global $_wp_additional_image_sizes;
190 $_wp_additional_image_sizes[$name] = array( 'width' => absint( $width ), 'height' => absint( $height ), 'crop' => (bool) $crop );
194 * Registers an image size for the post thumbnail
198 function set_post_thumbnail_size( $width = 0, $height = 0, $crop = false ) {
199 add_image_size( 'post-thumbnail', $width, $height, $crop );
203 * An <img src /> tag for an image attachment, scaling it down if requested.
205 * The filter 'get_image_tag_class' allows for changing the class name for the
206 * image without having to use regular expressions on the HTML content. The
207 * parameters are: what WordPress will use for the class, the Attachment ID,
208 * image align value, and the size the image should be.
210 * The second filter 'get_image_tag' has the HTML content, which can then be
211 * further manipulated by a plugin to change all attribute values and even HTML
216 * @uses apply_filters() The 'get_image_tag_class' filter is the IMG element
218 * @uses apply_filters() The 'get_image_tag' filter is the full IMG element with
221 * @param int $id Attachment ID.
222 * @param string $alt Image Description for the alt attribute.
223 * @param string $title Image Description for the title attribute.
224 * @param string $align Part of the class name for aligning the image.
225 * @param string $size Optional. Default is 'medium'.
226 * @return string HTML IMG element for given image attachment
228 function get_image_tag($id, $alt, $title, $align, $size='medium') {
230 list( $img_src, $width, $height ) = image_downsize($id, $size);
231 $hwstring = image_hwstring($width, $height);
233 $title = $title ? 'title="' . esc_attr( $title ) . '" ' : '';
235 $class = 'align' . esc_attr($align) .' size-' . esc_attr($size) . ' wp-image-' . $id;
236 $class = apply_filters('get_image_tag_class', $class, $id, $align, $size);
238 $html = '<img src="' . esc_attr($img_src) . '" alt="' . esc_attr($alt) . '" ' . $title . $hwstring . 'class="' . $class . '" />';
240 $html = apply_filters( 'get_image_tag', $html, $id, $alt, $title, $align, $size );
246 * Calculates the new dimensions for a downsampled image.
248 * If either width or height are empty, no constraint is applied on
253 * @param int $current_width Current width of the image.
254 * @param int $current_height Current height of the image.
255 * @param int $max_width Optional. Maximum wanted width.
256 * @param int $max_height Optional. Maximum wanted height.
257 * @return array First item is the width, the second item is the height.
259 function wp_constrain_dimensions( $current_width, $current_height, $max_width=0, $max_height=0 ) {
260 if ( !$max_width and !$max_height )
261 return array( $current_width, $current_height );
263 $width_ratio = $height_ratio = 1.0;
264 $did_width = $did_height = false;
266 if ( $max_width > 0 && $current_width > 0 && $current_width > $max_width ) {
267 $width_ratio = $max_width / $current_width;
271 if ( $max_height > 0 && $current_height > 0 && $current_height > $max_height ) {
272 $height_ratio = $max_height / $current_height;
276 // Calculate the larger/smaller ratios
277 $smaller_ratio = min( $width_ratio, $height_ratio );
278 $larger_ratio = max( $width_ratio, $height_ratio );
280 if ( intval( $current_width * $larger_ratio ) > $max_width || intval( $current_height * $larger_ratio ) > $max_height )
281 // The larger ratio is too big. It would result in an overflow.
282 $ratio = $smaller_ratio;
284 // The larger ratio fits, and is likely to be a more "snug" fit.
285 $ratio = $larger_ratio;
287 $w = intval( $current_width * $ratio );
288 $h = intval( $current_height * $ratio );
290 // Sometimes, due to rounding, we'll end up with a result like this: 465x700 in a 177x177 box is 117x176... a pixel short
291 // We also have issues with recursive calls resulting in an ever-changing result. Constraining to the result of a constraint should yield the original result.
292 // Thus we look for dimensions that are one pixel shy of the max value and bump them up
293 if ( $did_width && $w == $max_width - 1 )
294 $w = $max_width; // Round it up
295 if ( $did_height && $h == $max_height - 1 )
296 $h = $max_height; // Round it up
298 return array( $w, $h );
302 * Retrieve calculated resized dimensions for use in WP_Image_Editor.
304 * Calculate dimensions and coordinates for a resized image that fits within a
305 * specified width and height. If $crop is true, the largest matching central
306 * portion of the image will be cropped out and resized to the required size.
309 * @uses apply_filters() Calls 'image_resize_dimensions' on $orig_w, $orig_h, $dest_w, $dest_h and
310 * $crop to provide custom resize dimensions.
312 * @param int $orig_w Original width.
313 * @param int $orig_h Original height.
314 * @param int $dest_w New width.
315 * @param int $dest_h New height.
316 * @param bool $crop Optional, default is false. Whether to crop image or resize.
317 * @return bool|array False on failure. Returned array matches parameters for imagecopyresampled() PHP function.
319 function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = false) {
321 if ($orig_w <= 0 || $orig_h <= 0)
323 // at least one of dest_w or dest_h must be specific
324 if ($dest_w <= 0 && $dest_h <= 0)
327 // plugins can use this to provide custom resize dimensions
328 $output = apply_filters( 'image_resize_dimensions', null, $orig_w, $orig_h, $dest_w, $dest_h, $crop );
329 if ( null !== $output )
333 // crop the largest possible portion of the original image that we can size to $dest_w x $dest_h
334 $aspect_ratio = $orig_w / $orig_h;
335 $new_w = min($dest_w, $orig_w);
336 $new_h = min($dest_h, $orig_h);
339 $new_w = intval($new_h * $aspect_ratio);
343 $new_h = intval($new_w / $aspect_ratio);
346 $size_ratio = max($new_w / $orig_w, $new_h / $orig_h);
348 $crop_w = round($new_w / $size_ratio);
349 $crop_h = round($new_h / $size_ratio);
351 $s_x = floor( ($orig_w - $crop_w) / 2 );
352 $s_y = floor( ($orig_h - $crop_h) / 2 );
354 // don't crop, just resize using $dest_w x $dest_h as a maximum bounding box
361 list( $new_w, $new_h ) = wp_constrain_dimensions( $orig_w, $orig_h, $dest_w, $dest_h );
364 // if the resulting image would be the same size or larger we don't want to resize it
365 if ( $new_w >= $orig_w && $new_h >= $orig_h )
368 // the return array matches the parameters to imagecopyresampled()
369 // int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h
370 return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h );
375 * Resize an image to make a thumbnail or intermediate size.
377 * The returned array has the file size, the image width, and image height. The
378 * filter 'image_make_intermediate_size' can be used to hook in and change the
379 * values of the returned array. The only parameter is the resized file path.
383 * @param string $file File path.
384 * @param int $width Image width.
385 * @param int $height Image height.
386 * @param bool $crop Optional, default is false. Whether to crop image to specified height and width or resize.
387 * @return bool|array False, if no image was created. Metadata array on success.
389 function image_make_intermediate_size( $file, $width, $height, $crop = false ) {
390 if ( $width || $height ) {
391 $editor = wp_get_image_editor( $file );
393 if ( is_wp_error( $editor ) || is_wp_error( $editor->resize( $width, $height, $crop ) ) )
396 $resized_file = $editor->save();
398 if ( ! is_wp_error( $resized_file ) && $resized_file ) {
399 unset( $resized_file['path'] );
400 return $resized_file;
407 * Retrieve the image's intermediate size (resized) path, width, and height.
409 * The $size parameter can be an array with the width and height respectively.
410 * If the size matches the 'sizes' metadata array for width and height, then it
411 * will be used. If there is no direct match, then the nearest image size larger
412 * than the specified size will be used. If nothing is found, then the function
413 * will break out and return false.
415 * The metadata 'sizes' is used for compatible sizes that can be used for the
416 * parameter $size value.
418 * The url path will be given, when the $size parameter is a string.
420 * If you are passing an array for the $size, you should consider using
421 * add_image_size() so that a cropped version is generated. It's much more
422 * efficient than having to find the closest-sized image and then having the
423 * browser scale down the image.
426 * @see add_image_size()
428 * @param int $post_id Attachment ID for image.
429 * @param array|string $size Optional, default is 'thumbnail'. Size of image, either array or string.
430 * @return bool|array False on failure or array of file path, width, and height on success.
432 function image_get_intermediate_size($post_id, $size='thumbnail') {
433 if ( !is_array( $imagedata = wp_get_attachment_metadata( $post_id ) ) )
436 // get the best one for a specified set of dimensions
437 if ( is_array($size) && !empty($imagedata['sizes']) ) {
438 foreach ( $imagedata['sizes'] as $_size => $data ) {
439 // already cropped to width or height; so use this size
440 if ( ( $data['width'] == $size[0] && $data['height'] <= $size[1] ) || ( $data['height'] == $size[1] && $data['width'] <= $size[0] ) ) {
441 $file = $data['file'];
442 list($width, $height) = image_constrain_size_for_editor( $data['width'], $data['height'], $size );
443 return compact( 'file', 'width', 'height' );
445 // add to lookup table: area => size
446 $areas[$data['width'] * $data['height']] = $_size;
448 if ( !$size || !empty($areas) ) {
449 // find for the smallest image not smaller than the desired size
451 foreach ( $areas as $_size ) {
452 $data = $imagedata['sizes'][$_size];
453 if ( $data['width'] >= $size[0] || $data['height'] >= $size[1] ) {
454 // Skip images with unexpectedly divergent aspect ratios (crops)
455 // First, we calculate what size the original image would be if constrained to a box the size of the current image in the loop
456 $maybe_cropped = image_resize_dimensions($imagedata['width'], $imagedata['height'], $data['width'], $data['height'], false );
457 // If the size doesn't match within one pixel, then it is of a different aspect ratio, so we skip it, unless it's the thumbnail size
458 if ( 'thumbnail' != $_size && ( !$maybe_cropped || ( $maybe_cropped[4] != $data['width'] && $maybe_cropped[4] + 1 != $data['width'] ) || ( $maybe_cropped[5] != $data['height'] && $maybe_cropped[5] + 1 != $data['height'] ) ) )
460 // If we're still here, then we're going to use this size
461 $file = $data['file'];
462 list($width, $height) = image_constrain_size_for_editor( $data['width'], $data['height'], $size );
463 return compact( 'file', 'width', 'height' );
469 if ( is_array($size) || empty($size) || empty($imagedata['sizes'][$size]) )
472 $data = $imagedata['sizes'][$size];
473 // include the full filesystem path of the intermediate file
474 if ( empty($data['path']) && !empty($data['file']) ) {
475 $file_url = wp_get_attachment_url($post_id);
476 $data['path'] = path_join( dirname($imagedata['file']), $data['file'] );
477 $data['url'] = path_join( dirname($file_url), $data['file'] );
483 * Get the available image sizes
485 * @return array Returns a filtered array of image size strings
487 function get_intermediate_image_sizes() {
488 global $_wp_additional_image_sizes;
489 $image_sizes = array('thumbnail', 'medium', 'large'); // Standard sizes
490 if ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) )
491 $image_sizes = array_merge( $image_sizes, array_keys( $_wp_additional_image_sizes ) );
493 return apply_filters( 'intermediate_image_sizes', $image_sizes );
497 * Retrieve an image to represent an attachment.
499 * A mime icon for files, thumbnail or intermediate size for images.
503 * @param int $attachment_id Image attachment ID.
504 * @param string $size Optional, default is 'thumbnail'.
505 * @param bool $icon Optional, default is false. Whether it is an icon.
506 * @return bool|array Returns an array (url, width, height), or false, if no image is available.
508 function wp_get_attachment_image_src($attachment_id, $size='thumbnail', $icon = false) {
510 // get a thumbnail or intermediate image if there is one
511 if ( $image = image_downsize($attachment_id, $size) )
516 if ( $icon && $src = wp_mime_type_icon($attachment_id) ) {
517 $icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/crystal' );
518 $src_file = $icon_dir . '/' . wp_basename($src);
519 @list($width, $height) = getimagesize($src_file);
521 if ( $src && $width && $height )
522 return array( $src, $width, $height );
527 * Get an HTML img element representing an image attachment
529 * While $size will accept an array, it is better to register a size with
530 * add_image_size() so that a cropped version is generated. It's much more
531 * efficient than having to find the closest-sized image and then having the
532 * browser scale down the image.
534 * @see add_image_size()
535 * @uses apply_filters() Calls 'wp_get_attachment_image_attributes' hook on attributes array
536 * @uses wp_get_attachment_image_src() Gets attachment file URL and dimensions
539 * @param int $attachment_id Image attachment ID.
540 * @param string $size Optional, default is 'thumbnail'.
541 * @param bool $icon Optional, default is false. Whether it is an icon.
542 * @return string HTML img element or empty string on failure.
544 function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = false, $attr = '') {
547 $image = wp_get_attachment_image_src($attachment_id, $size, $icon);
549 list($src, $width, $height) = $image;
550 $hwstring = image_hwstring($width, $height);
551 if ( is_array($size) )
552 $size = join('x', $size);
553 $attachment = get_post($attachment_id);
554 $default_attr = array(
556 'class' => "attachment-$size",
557 'alt' => trim(strip_tags( get_post_meta($attachment_id, '_wp_attachment_image_alt', true) )), // Use Alt field first
559 if ( empty($default_attr['alt']) )
560 $default_attr['alt'] = trim(strip_tags( $attachment->post_excerpt )); // If not, Use the Caption
561 if ( empty($default_attr['alt']) )
562 $default_attr['alt'] = trim(strip_tags( $attachment->post_title )); // Finally, use the title
564 $attr = wp_parse_args($attr, $default_attr);
565 $attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment );
566 $attr = array_map( 'esc_attr', $attr );
567 $html = rtrim("<img $hwstring");
568 foreach ( $attr as $name => $value ) {
569 $html .= " $name=" . '"' . $value . '"';
578 * Adds a 'wp-post-image' class to post thumbnails
579 * Uses the begin_fetch_post_thumbnail_html and end_fetch_post_thumbnail_html action hooks to
580 * dynamically add/remove itself so as to only filter post thumbnails
583 * @param array $attr Attributes including src, class, alt, title
586 function _wp_post_thumbnail_class_filter( $attr ) {
587 $attr['class'] .= ' wp-post-image';
592 * Adds _wp_post_thumbnail_class_filter to the wp_get_attachment_image_attributes filter
596 function _wp_post_thumbnail_class_filter_add( $attr ) {
597 add_filter( 'wp_get_attachment_image_attributes', '_wp_post_thumbnail_class_filter' );
601 * Removes _wp_post_thumbnail_class_filter from the wp_get_attachment_image_attributes filter
605 function _wp_post_thumbnail_class_filter_remove( $attr ) {
606 remove_filter( 'wp_get_attachment_image_attributes', '_wp_post_thumbnail_class_filter' );
609 add_shortcode('wp_caption', 'img_caption_shortcode');
610 add_shortcode('caption', 'img_caption_shortcode');
613 * The Caption shortcode.
615 * Allows a plugin to replace the content that would otherwise be returned. The
616 * filter is 'img_caption_shortcode' and passes an empty string, the attr
617 * parameter and the content parameter values.
619 * The supported attributes for the shortcode are 'id', 'align', 'width', and
624 * @param array $attr Attributes attributed to the shortcode.
625 * @param string $content Optional. Shortcode content.
628 function img_caption_shortcode($attr, $content = null) {
629 // New-style shortcode with the caption inside the shortcode with the link and image tags.
630 if ( ! isset( $attr['caption'] ) ) {
631 if ( preg_match( '#((?:<a [^>]+>\s*)?<img [^>]+>(?:\s*</a>)?)(.*)#is', $content, $matches ) ) {
632 $content = $matches[1];
633 $attr['caption'] = trim( $matches[2] );
637 // Allow plugins/themes to override the default caption template.
638 $output = apply_filters('img_caption_shortcode', '', $attr, $content);
642 extract(shortcode_atts(array(
644 'align' => 'alignnone',
649 if ( 1 > (int) $width || empty($caption) )
652 if ( $id ) $id = 'id="' . esc_attr($id) . '" ';
654 return '<div ' . $id . 'class="wp-caption ' . esc_attr($align) . '" style="width: ' . (10 + (int) $width) . 'px">'
655 . do_shortcode( $content ) . '<p class="wp-caption-text">' . $caption . '</p></div>';
658 add_shortcode('gallery', 'gallery_shortcode');
661 * The Gallery shortcode.
663 * This implements the functionality of the Gallery Shortcode for displaying
664 * WordPress images on a post.
668 * @param array $attr Attributes of the shortcode.
669 * @return string HTML content to display gallery.
671 function gallery_shortcode($attr) {
674 static $instance = 0;
677 if ( ! empty( $attr['ids'] ) ) {
678 // 'ids' is explicitly ordered, unless you specify otherwise.
679 if ( empty( $attr['orderby'] ) )
680 $attr['orderby'] = 'post__in';
681 $attr['include'] = $attr['ids'];
684 // Allow plugins/themes to override the default gallery template.
685 $output = apply_filters('post_gallery', '', $attr);
689 // We're trusting author input, so let's at least make sure it looks like a valid orderby statement
690 if ( isset( $attr['orderby'] ) ) {
691 $attr['orderby'] = sanitize_sql_orderby( $attr['orderby'] );
692 if ( !$attr['orderby'] )
693 unset( $attr['orderby'] );
696 extract(shortcode_atts(array(
698 'orderby' => 'menu_order ID',
702 'captiontag' => 'dd',
704 'size' => 'thumbnail',
710 if ( 'RAND' == $order )
713 if ( !empty($include) ) {
714 $_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
716 $attachments = array();
717 foreach ( $_attachments as $key => $val ) {
718 $attachments[$val->ID] = $_attachments[$key];
720 } elseif ( !empty($exclude) ) {
721 $attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
723 $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
726 if ( empty($attachments) )
731 foreach ( $attachments as $att_id => $attachment )
732 $output .= wp_get_attachment_link($att_id, $size, true) . "\n";
736 $itemtag = tag_escape($itemtag);
737 $captiontag = tag_escape($captiontag);
738 $icontag = tag_escape($icontag);
739 $valid_tags = wp_kses_allowed_html( 'post' );
740 if ( ! isset( $valid_tags[ $itemtag ] ) )
742 if ( ! isset( $valid_tags[ $captiontag ] ) )
744 if ( ! isset( $valid_tags[ $icontag ] ) )
747 $columns = intval($columns);
748 $itemwidth = $columns > 0 ? floor(100/$columns) : 100;
749 $float = is_rtl() ? 'right' : 'left';
751 $selector = "gallery-{$instance}";
753 $gallery_style = $gallery_div = '';
754 if ( apply_filters( 'use_default_gallery_style', true ) )
756 <style type='text/css'>
760 #{$selector} .gallery-item {
764 width: {$itemwidth}%;
767 border: 2px solid #cfcfcf;
769 #{$selector} .gallery-caption {
773 <!-- see gallery_shortcode() in wp-includes/media.php -->";
774 $size_class = sanitize_html_class( $size );
775 $gallery_div = "<div id='$selector' class='gallery galleryid-{$id} gallery-columns-{$columns} gallery-size-{$size_class}'>";
776 $output = apply_filters( 'gallery_style', $gallery_style . "\n\t\t" . $gallery_div );
779 foreach ( $attachments as $id => $attachment ) {
780 $link = isset($attr['link']) && 'file' == $attr['link'] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false);
782 $output .= "<{$itemtag} class='gallery-item'>";
784 <{$icontag} class='gallery-icon'>
787 if ( $captiontag && trim($attachment->post_excerpt) ) {
789 <{$captiontag} class='wp-caption-text gallery-caption'>
790 " . wptexturize($attachment->post_excerpt) . "
793 $output .= "</{$itemtag}>";
794 if ( $columns > 0 && ++$i % $columns == 0 )
795 $output .= '<br style="clear: both" />';
799 <br style='clear: both;' />
806 * Display previous image link that has the same post parent.
809 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string. 0 or 'none' will default to post_title or $text;
810 * @param string $text Optional, default is false. If included, link will reflect $text variable.
811 * @return string HTML content.
813 function previous_image_link($size = 'thumbnail', $text = false) {
814 adjacent_image_link(true, $size, $text);
818 * Display next image link that has the same post parent.
821 * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string. 0 or 'none' will default to post_title or $text;
822 * @param string $text Optional, default is false. If included, link will reflect $text variable.
823 * @return string HTML content.
825 function next_image_link($size = 'thumbnail', $text = false) {
826 adjacent_image_link(false, $size, $text);
830 * Display next or previous image link that has the same post parent.
832 * Retrieves the current attachment object from the $post global.
836 * @param bool $prev Optional. Default is true to display previous link, false for next.
838 function adjacent_image_link($prev = true, $size = 'thumbnail', $text = false) {
840 $attachments = array_values( get_children( array( 'post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID' ) ) );
842 foreach ( $attachments as $k => $attachment )
843 if ( $attachment->ID == $post->ID )
846 $k = $prev ? $k - 1 : $k + 1;
848 $output = $attachment_id = null;
849 if ( isset( $attachments[ $k ] ) ) {
850 $attachment_id = $attachments[ $k ]->ID;
851 $output = wp_get_attachment_link( $attachment_id, $size, true, false, $text );
854 $adjacent = $prev ? 'previous' : 'next';
855 echo apply_filters( "{$adjacent}_image_link", $output, $attachment_id, $size, $text );
859 * Retrieve taxonomies attached to the attachment.
863 * @param int|array|object $attachment Attachment ID, Attachment data array, or Attachment data object.
864 * @return array Empty array on failure. List of taxonomies on success.
866 function get_attachment_taxonomies($attachment) {
867 if ( is_int( $attachment ) )
868 $attachment = get_post($attachment);
869 else if ( is_array($attachment) )
870 $attachment = (object) $attachment;
872 if ( ! is_object($attachment) )
875 $filename = basename($attachment->guid);
877 $objects = array('attachment');
879 if ( false !== strpos($filename, '.') )
880 $objects[] = 'attachment:' . substr($filename, strrpos($filename, '.') + 1);
881 if ( !empty($attachment->post_mime_type) ) {
882 $objects[] = 'attachment:' . $attachment->post_mime_type;
883 if ( false !== strpos($attachment->post_mime_type, '/') )
884 foreach ( explode('/', $attachment->post_mime_type) as $token )
885 if ( !empty($token) )
886 $objects[] = "attachment:$token";
889 $taxonomies = array();
890 foreach ( $objects as $object )
891 if ( $taxes = get_object_taxonomies($object) )
892 $taxonomies = array_merge($taxonomies, $taxes);
894 return array_unique($taxonomies);
898 * Return all of the taxonomy names that are registered for attachments.
900 * Handles mime-type-specific taxonomies such as attachment:image and attachment:video.
903 * @see get_attachment_taxonomies()
904 * @uses get_taxonomies()
906 * @param string $output The type of output to return, either taxonomy 'names' or 'objects'. 'names' is the default.
907 * @return array The names of all taxonomy of $object_type.
909 function get_taxonomies_for_attachments( $output = 'names' ) {
910 $taxonomies = array();
911 foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy ) {
912 foreach ( $taxonomy->object_type as $object_type ) {
913 if ( 'attachment' == $object_type || 0 === strpos( $object_type, 'attachment:' ) ) {
914 if ( 'names' == $output )
915 $taxonomies[] = $taxonomy->name;
917 $taxonomies[ $taxonomy->name ] = $taxonomy;
927 * Create new GD image resource with transparency support
928 * @TODO: Deprecate if possible.
932 * @param int $width Image width
933 * @param int $height Image height
934 * @return image resource
936 function wp_imagecreatetruecolor($width, $height) {
937 $img = imagecreatetruecolor($width, $height);
938 if ( is_resource($img) && function_exists('imagealphablending') && function_exists('imagesavealpha') ) {
939 imagealphablending($img, false);
940 imagesavealpha($img, true);
946 * Register an embed handler. This function should probably only be used for sites that do not support oEmbed.
949 * @see WP_Embed::register_handler()
951 function wp_embed_register_handler( $id, $regex, $callback, $priority = 10 ) {
953 $wp_embed->register_handler( $id, $regex, $callback, $priority );
957 * Unregister a previously registered embed handler.
960 * @see WP_Embed::unregister_handler()
962 function wp_embed_unregister_handler( $id, $priority = 10 ) {
964 $wp_embed->unregister_handler( $id, $priority );
968 * Create default array of embed parameters.
970 * The width defaults to the content width as specified by the theme. If the
971 * theme does not specify a content width, then 500px is used.
973 * The default height is 1.5 times the width, or 1000px, whichever is smaller.
975 * The 'embed_defaults' filter can be used to adjust either of these values.
979 * @return array Default embed parameters.
981 function wp_embed_defaults() {
982 if ( ! empty( $GLOBALS['content_width'] ) )
983 $width = (int) $GLOBALS['content_width'];
985 if ( empty( $width ) )
988 $height = min( ceil( $width * 1.5 ), 1000 );
990 return apply_filters( 'embed_defaults', compact( 'width', 'height' ) );
994 * Based on a supplied width/height example, return the biggest possible dimensions based on the max width/height.
997 * @uses wp_constrain_dimensions() This function passes the widths and the heights.
999 * @param int $example_width The width of an example embed.
1000 * @param int $example_height The height of an example embed.
1001 * @param int $max_width The maximum allowed width.
1002 * @param int $max_height The maximum allowed height.
1003 * @return array The maximum possible width and height based on the example ratio.
1005 function wp_expand_dimensions( $example_width, $example_height, $max_width, $max_height ) {
1006 $example_width = (int) $example_width;
1007 $example_height = (int) $example_height;
1008 $max_width = (int) $max_width;
1009 $max_height = (int) $max_height;
1011 return wp_constrain_dimensions( $example_width * 1000000, $example_height * 1000000, $max_width, $max_height );
1015 * Attempts to fetch the embed HTML for a provided URL using oEmbed.
1020 * @uses _wp_oembed_get_object()
1021 * @uses WP_oEmbed::get_html()
1023 * @param string $url The URL that should be embedded.
1024 * @param array $args Additional arguments and parameters.
1025 * @return bool|string False on failure or the embed HTML on success.
1027 function wp_oembed_get( $url, $args = '' ) {
1028 require_once( ABSPATH . WPINC . '/class-oembed.php' );
1029 $oembed = _wp_oembed_get_object();
1030 return $oembed->get_html( $url, $args );
1034 * Adds a URL format and oEmbed provider URL pair.
1039 * @uses _wp_oembed_get_object()
1041 * @param string $format The format of URL that this provider can handle. You can use asterisks as wildcards.
1042 * @param string $provider The URL to the oEmbed provider.
1043 * @param boolean $regex Whether the $format parameter is in a regex format.
1045 function wp_oembed_add_provider( $format, $provider, $regex = false ) {
1046 require_once( ABSPATH . WPINC . '/class-oembed.php' );
1047 $oembed = _wp_oembed_get_object();
1048 $oembed->providers[$format] = array( $provider, $regex );
1052 * Removes an oEmbed provider.
1057 * @uses _wp_oembed_get_object()
1059 * @param string $format The URL format for the oEmbed provider to remove.
1061 function wp_oembed_remove_provider( $format ) {
1062 require_once( ABSPATH . WPINC . '/class-oembed.php' );
1064 $oembed = _wp_oembed_get_object();
1066 if ( isset( $oembed->providers[ $format ] ) ) {
1067 unset( $oembed->providers[ $format ] );
1075 * Determines if default embed handlers should be loaded.
1077 * Checks to make sure that the embeds library hasn't already been loaded. If
1078 * it hasn't, then it will load the embeds library.
1082 function wp_maybe_load_embeds() {
1083 if ( ! apply_filters( 'load_default_embeds', true ) )
1085 wp_embed_register_handler( 'googlevideo', '#http://video\.google\.([A-Za-z.]{2,5})/videoplay\?docid=([\d-]+)(.*?)#i', 'wp_embed_handler_googlevideo' );
1089 * The Google Video embed handler callback. Google Video does not support oEmbed.
1091 * @see WP_Embed::register_handler()
1092 * @see WP_Embed::shortcode()
1094 * @param array $matches The regex matches from the provided regex when calling {@link wp_embed_register_handler()}.
1095 * @param array $attr Embed attributes.
1096 * @param string $url The original URL that was matched by the regex.
1097 * @param array $rawattr The original unmodified attributes.
1098 * @return string The embed HTML.
1100 function wp_embed_handler_googlevideo( $matches, $attr, $url, $rawattr ) {
1101 // If the user supplied a fixed width AND height, use it
1102 if ( !empty($rawattr['width']) && !empty($rawattr['height']) ) {
1103 $width = (int) $rawattr['width'];
1104 $height = (int) $rawattr['height'];
1106 list( $width, $height ) = wp_expand_dimensions( 425, 344, $attr['width'], $attr['height'] );
1109 return apply_filters( 'embed_googlevideo', '<embed type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docid=' . esc_attr($matches[2]) . '&hl=en&fs=true" style="width:' . esc_attr($width) . 'px;height:' . esc_attr($height) . 'px" allowFullScreen="true" allowScriptAccess="always" />', $matches, $attr, $url, $rawattr );
1113 * {@internal Missing Short Description}}
1117 * @param unknown_type $size
1120 function wp_convert_hr_to_bytes( $size ) {
1121 $size = strtolower( $size );
1122 $bytes = (int) $size;
1123 if ( strpos( $size, 'k' ) !== false )
1124 $bytes = intval( $size ) * 1024;
1125 elseif ( strpos( $size, 'm' ) !== false )
1126 $bytes = intval($size) * 1024 * 1024;
1127 elseif ( strpos( $size, 'g' ) !== false )
1128 $bytes = intval( $size ) * 1024 * 1024 * 1024;
1133 * {@internal Missing Short Description}}
1137 * @param unknown_type $bytes
1140 function wp_convert_bytes_to_hr( $bytes ) {
1141 $units = array( 0 => 'B', 1 => 'kB', 2 => 'MB', 3 => 'GB' );
1142 $log = log( $bytes, 1024 );
1143 $power = (int) $log;
1144 $size = pow( 1024, $log - $power );
1145 return $size . $units[$power];
1149 * {@internal Missing Short Description}}
1155 function wp_max_upload_size() {
1156 $u_bytes = wp_convert_hr_to_bytes( ini_get( 'upload_max_filesize' ) );
1157 $p_bytes = wp_convert_hr_to_bytes( ini_get( 'post_max_size' ) );
1158 $bytes = apply_filters( 'upload_size_limit', min( $u_bytes, $p_bytes ), $u_bytes, $p_bytes );
1163 * Returns a WP_Image_Editor instance and loads file into it.
1168 * @param string $path Path to file to load
1169 * @param array $args Additional data. Accepts { 'mime_type'=>string, 'methods'=>{string, string, ...} }
1170 * @return WP_Image_Editor|WP_Error
1172 function wp_get_image_editor( $path, $args = array() ) {
1173 $args['path'] = $path;
1175 if ( ! isset( $args['mime_type'] ) ) {
1176 $file_info = wp_check_filetype( $args['path'] );
1178 // If $file_info['type'] is false, then we let the editor attempt to
1179 // figure out the file type, rather than forcing a failure based on extension.
1180 if ( isset( $file_info ) && $file_info['type'] )
1181 $args['mime_type'] = $file_info['type'];
1184 $implementation = _wp_image_editor_choose( $args );
1186 if ( $implementation ) {
1187 $editor = new $implementation( $path );
1188 $loaded = $editor->load();
1190 if ( is_wp_error( $loaded ) )
1196 return new WP_Error( 'image_no_editor', __('No editor could be selected.') );
1200 * Tests whether there is an editor that supports a given mime type or methods.
1205 * @param string|array $args Array of requirements. Accepts { 'mime_type'=>string, 'methods'=>{string, string, ...} }
1206 * @return boolean true if an eligible editor is found; false otherwise
1208 function wp_image_editor_supports( $args = array() ) {
1209 return (bool) _wp_image_editor_choose( $args );
1213 * Tests which editors are capable of supporting the request.
1218 * @param array $args Additional data. Accepts { 'mime_type'=>string, 'methods'=>{string, string, ...} }
1219 * @return string|bool Class name for the first editor that claims to support the request. False if no editor claims to support the request.
1221 function _wp_image_editor_choose( $args = array() ) {
1222 require_once ABSPATH . WPINC . '/class-wp-image-editor.php';
1223 require_once ABSPATH . WPINC . '/class-wp-image-editor-gd.php';
1224 require_once ABSPATH . WPINC . '/class-wp-image-editor-imagick.php';
1226 $implementations = apply_filters( 'wp_image_editors',
1227 array( 'WP_Image_Editor_Imagick', 'WP_Image_Editor_GD' ) );
1229 foreach ( $implementations as $implementation ) {
1230 if ( ! call_user_func( array( $implementation, 'test' ), $args ) )
1233 if ( isset( $args['mime_type'] ) &&
1235 array( $implementation, 'supports_mime_type' ),
1236 $args['mime_type'] ) ) {
1240 if ( isset( $args['methods'] ) &&
1241 array_diff( $args['methods'], get_class_methods( $implementation ) ) ) {
1245 return $implementation;
1252 * Prints default plupload arguments.
1256 function wp_plupload_default_settings() {
1259 $data = $wp_scripts->get_data( 'wp-plupload', 'data' );
1260 if ( $data && false !== strpos( $data, '_wpPluploadSettings' ) )
1263 $max_upload_size = wp_max_upload_size();
1266 'runtimes' => 'html5,silverlight,flash,html4',
1267 'file_data_name' => 'async-upload', // key passed to $_FILE.
1268 'multiple_queues' => true,
1269 'max_file_size' => $max_upload_size . 'b',
1270 'url' => admin_url( 'async-upload.php', 'relative' ),
1271 'flash_swf_url' => includes_url( 'js/plupload/plupload.flash.swf' ),
1272 'silverlight_xap_url' => includes_url( 'js/plupload/plupload.silverlight.xap' ),
1273 'filters' => array( array( 'title' => __( 'Allowed Files' ), 'extensions' => '*') ),
1274 'multipart' => true,
1275 'urlstream_upload' => true,
1278 // Multi-file uploading doesn't currently work in iOS Safari,
1279 // single-file allows the built-in camera to be used as source for images
1280 if ( wp_is_mobile() )
1281 $defaults['multi_selection'] = false;
1283 $defaults = apply_filters( 'plupload_default_settings', $defaults );
1286 'action' => 'upload-attachment',
1289 $params = apply_filters( 'plupload_default_params', $params );
1290 $params['_wpnonce'] = wp_create_nonce( 'media-form' );
1291 $defaults['multipart_params'] = $params;
1294 'defaults' => $defaults,
1296 'mobile' => wp_is_mobile(),
1297 'supported' => _device_can_upload(),
1299 'limitExceeded' => is_multisite() && ! is_upload_space_available()
1302 $script = 'var _wpPluploadSettings = ' . json_encode( $settings ) . ';';
1305 $script = "$data\n$script";
1307 $wp_scripts->add_data( 'wp-plupload', 'data', $script );
1309 add_action( 'customize_controls_enqueue_scripts', 'wp_plupload_default_settings' );
1312 * Prepares an attachment post object for JS, where it is expected
1313 * to be JSON-encoded and fit into an Attachment model.
1317 * @param mixed $attachment Attachment ID or object.
1318 * @return array Array of attachment details.
1320 function wp_prepare_attachment_for_js( $attachment ) {
1321 if ( ! $attachment = get_post( $attachment ) )
1324 if ( 'attachment' != $attachment->post_type )
1327 $meta = wp_get_attachment_metadata( $attachment->ID );
1328 if ( false !== strpos( $attachment->post_mime_type, '/' ) )
1329 list( $type, $subtype ) = explode( '/', $attachment->post_mime_type );
1331 list( $type, $subtype ) = array( $attachment->post_mime_type, '' );
1333 $attachment_url = wp_get_attachment_url( $attachment->ID );
1336 'id' => $attachment->ID,
1337 'title' => $attachment->post_title,
1338 'filename' => basename( $attachment->guid ),
1339 'url' => $attachment_url,
1340 'link' => get_attachment_link( $attachment->ID ),
1341 'alt' => get_post_meta( $attachment->ID, '_wp_attachment_image_alt', true ),
1342 'author' => $attachment->post_author,
1343 'description' => $attachment->post_content,
1344 'caption' => $attachment->post_excerpt,
1345 'name' => $attachment->post_name,
1346 'status' => $attachment->post_status,
1347 'uploadedTo' => $attachment->post_parent,
1348 'date' => strtotime( $attachment->post_date_gmt ) * 1000,
1349 'modified' => strtotime( $attachment->post_modified_gmt ) * 1000,
1350 'menuOrder' => $attachment->menu_order,
1351 'mime' => $attachment->post_mime_type,
1353 'subtype' => $subtype,
1354 'icon' => wp_mime_type_icon( $attachment->ID ),
1355 'dateFormatted' => mysql2date( get_option('date_format'), $attachment->post_date ),
1360 'editLink' => false,
1363 if ( current_user_can( 'edit_post', $attachment->ID ) ) {
1364 $response['nonces']['update'] = wp_create_nonce( 'update-post_' . $attachment->ID );
1365 $response['editLink'] = get_edit_post_link( $attachment->ID, 'raw' );
1368 if ( current_user_can( 'delete_post', $attachment->ID ) )
1369 $response['nonces']['delete'] = wp_create_nonce( 'delete-post_' . $attachment->ID );
1371 if ( $meta && 'image' === $type ) {
1373 $possible_sizes = apply_filters( 'image_size_names_choose', array(
1374 'thumbnail' => __('Thumbnail'),
1375 'medium' => __('Medium'),
1376 'large' => __('Large'),
1377 'full' => __('Full Size'),
1379 unset( $possible_sizes['full'] );
1381 // Loop through all potential sizes that may be chosen. Try to do this with some efficiency.
1382 // First: run the image_downsize filter. If it returns something, we can use its data.
1383 // If the filter does not return something, then image_downsize() is just an expensive
1384 // way to check the image metadata, which we do second.
1385 foreach ( $possible_sizes as $size => $label ) {
1386 if ( $downsize = apply_filters( 'image_downsize', false, $attachment->ID, $size ) ) {
1387 if ( ! $downsize[3] )
1389 $sizes[ $size ] = array(
1390 'height' => $downsize[2],
1391 'width' => $downsize[1],
1392 'url' => $downsize[0],
1393 'orientation' => $downsize[2] > $downsize[1] ? 'portrait' : 'landscape',
1395 } elseif ( isset( $meta['sizes'][ $size ] ) ) {
1396 if ( ! isset( $base_url ) )
1397 $base_url = str_replace( wp_basename( $attachment_url ), '', $attachment_url );
1399 // Nothing from the filter, so consult image metadata if we have it.
1400 $size_meta = $meta['sizes'][ $size ];
1402 // We have the actual image size, but might need to further constrain it if content_width is narrower.
1403 // Thumbnail, medium, and full sizes are also checked against the site's height/width options.
1404 list( $width, $height ) = image_constrain_size_for_editor( $size_meta['width'], $size_meta['height'], $size, 'edit' );
1406 $sizes[ $size ] = array(
1407 'height' => $height,
1409 'url' => $base_url . $size_meta['file'],
1410 'orientation' => $height > $width ? 'portrait' : 'landscape',
1415 $sizes['full'] = array(
1416 'height' => $meta['height'],
1417 'width' => $meta['width'],
1418 'url' => $attachment_url,
1419 'orientation' => $meta['height'] > $meta['width'] ? 'portrait' : 'landscape',
1422 $response = array_merge( $response, array( 'sizes' => $sizes ), $sizes['full'] );
1425 if ( function_exists('get_compat_media_markup') )
1426 $response['compat'] = get_compat_media_markup( $attachment->ID, array( 'in_modal' => true ) );
1428 return apply_filters( 'wp_prepare_attachment_for_js', $response, $attachment, $meta );
1432 * Enqueues all scripts, styles, settings, and templates necessary to use
1433 * all media JS APIs.
1437 function wp_enqueue_media( $args = array() ) {
1439 // Enqueue me just once per page, please.
1440 if ( did_action( 'wp_enqueue_media' ) )
1446 $args = wp_parse_args( $args, $defaults );
1448 // We're going to pass the old thickbox media tabs to `media_upload_tabs`
1449 // to ensure plugins will work. We will then unset those tabs.
1451 // handler action suffix => tab label
1458 $tabs = apply_filters( 'media_upload_tabs', $tabs );
1459 unset( $tabs['type'], $tabs['type_url'], $tabs['gallery'], $tabs['library'] );
1462 'link' => get_option( 'image_default_link_type' ), // db default is 'file'
1463 'align' => get_option( 'image_default_align' ), // empty default
1464 'size' => get_option( 'image_default_size' ), // empty default
1469 'tabUrl' => add_query_arg( array( 'chromeless' => true ), admin_url('media-upload.php') ),
1470 'mimeTypes' => wp_list_pluck( get_post_mime_types(), 0 ),
1471 'captions' => ! apply_filters( 'disable_captions', '' ),
1473 'sendToEditor' => wp_create_nonce( 'media-send-to-editor' ),
1478 'defaultProps' => $props,
1482 if ( isset( $args['post'] ) ) {
1483 $post = get_post( $args['post'] );
1484 $settings['post'] = array(
1486 'nonce' => wp_create_nonce( 'update-post_' . $post->ID ),
1489 if ( current_theme_supports( 'post-thumbnails', $post->post_type ) && post_type_supports( $post->post_type, 'thumbnail' ) ) {
1490 $featured_image_id = get_post_meta( $post->ID, '_thumbnail_id', true );
1491 $settings['post']['featuredImageId'] = $featured_image_id ? $featured_image_id : -1;
1495 $hier = $post && is_post_type_hierarchical( $post->post_type );
1499 'url' => __( 'URL' ),
1500 'addMedia' => __( 'Add Media' ),
1501 'search' => __( 'Search' ),
1502 'select' => __( 'Select' ),
1503 'cancel' => __( 'Cancel' ),
1504 /* translators: This is a would-be plural string used in the media manager.
1505 If there is not a word you can use in your language to avoid issues with the
1506 lack of plural support here, turn it into "selected: %d" then translate it.
1508 'selected' => __( '%d selected' ),
1509 'dragInfo' => __( 'Drag and drop to reorder images.' ),
1512 'uploadFilesTitle' => __( 'Upload Files' ),
1513 'uploadImagesTitle' => __( 'Upload Images' ),
1516 'mediaLibraryTitle' => __( 'Media Library' ),
1517 'insertMediaTitle' => __( 'Insert Media' ),
1518 'createNewGallery' => __( 'Create a new gallery' ),
1519 'returnToLibrary' => __( '← Return to library' ),
1520 'allMediaItems' => __( 'All media items' ),
1521 'noItemsFound' => __( 'No items found.' ),
1522 'insertIntoPost' => $hier ? __( 'Insert into page' ) : __( 'Insert into post' ),
1523 'uploadedToThisPost' => $hier ? __( 'Uploaded to this page' ) : __( 'Uploaded to this post' ),
1524 'warnDelete' => __( "You are about to permanently delete this item.\n 'Cancel' to stop, 'OK' to delete." ),
1527 'insertFromUrlTitle' => __( 'Insert from URL' ),
1530 'setFeaturedImageTitle' => __( 'Set Featured Image' ),
1531 'setFeaturedImage' => __( 'Set featured image' ),
1534 'createGalleryTitle' => __( 'Create Gallery' ),
1535 'editGalleryTitle' => __( 'Edit Gallery' ),
1536 'cancelGalleryTitle' => __( '← Cancel Gallery' ),
1537 'insertGallery' => __( 'Insert gallery' ),
1538 'updateGallery' => __( 'Update gallery' ),
1539 'addToGallery' => __( 'Add to gallery' ),
1540 'addToGalleryTitle' => __( 'Add to Gallery' ),
1541 'reverseOrder' => __( 'Reverse order' ),
1544 $settings = apply_filters( 'media_view_settings', $settings, $post );
1545 $strings = apply_filters( 'media_view_strings', $strings, $post );
1547 $strings['settings'] = $settings;
1549 wp_localize_script( 'media-views', '_wpMediaViewsL10n', $strings );
1551 wp_enqueue_script( 'media-editor' );
1552 wp_enqueue_style( 'media-views' );
1553 wp_plupload_default_settings();
1555 require_once ABSPATH . WPINC . '/media-template.php';
1556 add_action( 'admin_footer', 'wp_print_media_templates' );
1557 add_action( 'wp_footer', 'wp_print_media_templates' );
1559 do_action( 'wp_enqueue_media' );