diff --git a/src/wp-includes/media.php b/src/wp-includes/media.php
index 323ffd9f5e..012654ff3c 100644
--- a/src/wp-includes/media.php
+++ b/src/wp-includes/media.php
@@ -78,6 +78,18 @@ function image_constrain_size_for_editor($width, $height, $size = 'medium', $con
$max_height = $height;
}
+ /**
+ * Filter the maximum image size dimensions for the editor.
+ *
+ * @since 2.5.0
+ *
+ * @param array $max_image_size An array with the width as the first element,
+ * and the height as the second element.
+ * @param string|array $size Size of what the result image should be.
+ * @param string $context The context the image is being resized for.
+ * Possible values are 'display' (like in a theme)
+ * or 'edit' (like inserting into an editor).
+ */
list( $max_width, $max_height ) = apply_filters( 'editor_max_image_size', array( $max_width, $max_height ), $size, $context );
return wp_constrain_dimensions( $width, $height, $max_width, $max_height );
@@ -126,8 +138,6 @@ function image_hwstring($width, $height) {
* to the new image that was resized.
*
* @since 2.5.0
- * @uses apply_filters() Calls 'image_downsize' on $id and $size to provide
- * resize services.
*
* @param int $id Attachment ID for image.
* @param array|string $size Optional, default is 'medium'. Size of image, either array or string.
@@ -138,9 +148,21 @@ function image_downsize($id, $size = 'medium') {
if ( !wp_attachment_is_image($id) )
return false;
- // plugins can use this to provide resize services
- if ( $out = apply_filters( 'image_downsize', false, $id, $size ) )
+ /**
+ * Filter whether to preempt the output of image_downsize().
+ *
+ * Passing a truthy value to the filter will effectively short-circuit
+ * down-sizing the image, returning that value as output instead.
+ *
+ * @since 2.5.0
+ *
+ * @param bool $downsize Whether to short-circuit the image downsize. Default false.
+ * @param int $id Attachment ID for image.
+ * @param array|string $size Size of image, either array or string. Default 'medium'.
+ */
+ if ( $out = apply_filters( 'image_downsize', false, $id, $size ) ) {
return $out;
+ }
$img_url = wp_get_attachment_url($id);
$meta = wp_get_attachment_metadata($id);
@@ -273,11 +295,6 @@ function set_post_thumbnail_size( $width = 0, $height = 0, $crop = false ) {
*
* @since 2.5.0
*
- * @uses apply_filters() The 'get_image_tag_class' filter is the IMG element
- * class attribute.
- * @uses apply_filters() The 'get_image_tag' filter is the full IMG element with
- * all attributes.
- *
* @param int $id Attachment ID.
* @param string $alt Image Description for the alt attribute.
* @param string $title Image Description for the title attribute.
@@ -293,10 +310,33 @@ function get_image_tag($id, $alt, $title, $align, $size='medium') {
$title = $title ? 'title="' . esc_attr( $title ) . '" ' : '';
$class = 'align' . esc_attr($align) .' size-' . esc_attr($size) . ' wp-image-' . $id;
- $class = apply_filters('get_image_tag_class', $class, $id, $align, $size);
+
+ /**
+ * Filter the value of the attachment's image tag class attribute.
+ *
+ * @since 2.6.0
+ *
+ * @param string $class CSS class name or space-separated list of classes.
+ * @param int $id Attachment ID.
+ * @param string $align Part of the class name for aligning the image.
+ * @param string $size Optional. Default is 'medium'.
+ */
+ $class = apply_filters( 'get_image_tag_class', $class, $id, $align, $size );
$html = '';
+ /**
+ * Filter the HTML content for the image tag.
+ *
+ * @since 2.6.0
+ *
+ * @param string $html HTML content for the image.
+ * @param int $id Attachment ID.
+ * @param string $alt Alternate text.
+ * @param string $title Attachment title.
+ * @param string $align Part of the class name for aligning the image.
+ * @param string $size Optional. Default is 'medium'.
+ */
$html = apply_filters( 'get_image_tag', $html, $id, $alt, $title, $align, $size );
return $html;
@@ -374,8 +414,6 @@ function wp_constrain_dimensions( $current_width, $current_height, $max_width=0,
* 3. If true, images will be cropped to the specified dimensions using center positions.
*
* @since 2.5.0
- * @uses apply_filters() Calls 'image_resize_dimensions' on $orig_w, $orig_h, $dest_w,
- * $dest_h and $crop to provide custom resize dimensions.
*
* @param int $orig_w Original width in pixels.
* @param int $orig_h Original height in pixels.
@@ -393,7 +431,22 @@ function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = fal
if ($dest_w <= 0 && $dest_h <= 0)
return false;
- // plugins can use this to provide custom resize dimensions
+ /**
+ * Filter whether to preempt calculating the image resize dimensions.
+ *
+ * Passing a non-null value to the filter will effectively short-circuit
+ * image_resize_dimensions(), returning that value instead.
+ *
+ * @since 3.4.0
+ *
+ * @param null|mixed $null Whether to preempt output of the resize dimensions.
+ * @param int $orig_w Original width in pixels.
+ * @param int $orig_h Original height in pixels.
+ * @param int $dest_w New width in pixels.
+ * @param int $dest_h New height in pixels.
+ * @param bool|array $crop Whether to crop image to specified height and width or resize.
+ * An array can specify positioning of the crop area. Default false.
+ */
$output = apply_filters( 'image_resize_dimensions', null, $orig_w, $orig_h, $dest_w, $dest_h, $crop );
if ( null !== $output )
return $output;
@@ -578,6 +631,14 @@ function get_intermediate_image_sizes() {
if ( isset( $_wp_additional_image_sizes ) && count( $_wp_additional_image_sizes ) )
$image_sizes = array_merge( $image_sizes, array_keys( $_wp_additional_image_sizes ) );
+ /**
+ * Filter the list of intermediate image sizes.
+ *
+ * @since 2.5.0
+ *
+ * @param array $image_sizes An array of intermediate image sizes. Defaults
+ * are 'thumbnail', 'medium', 'large'.
+ */
return apply_filters( 'intermediate_image_sizes', $image_sizes );
}
@@ -602,6 +663,7 @@ function wp_get_attachment_image_src($attachment_id, $size='thumbnail', $icon =
$src = false;
if ( $icon && $src = wp_mime_type_icon($attachment_id) ) {
+ /** This filter is documented in wp-includes/post.php */
$icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/media' );
$src_file = $icon_dir . '/' . wp_basename($src);
@list($width, $height) = getimagesize($src_file);
@@ -619,11 +681,11 @@ function wp_get_attachment_image_src($attachment_id, $size='thumbnail', $icon =
* efficient than having to find the closest-sized image and then having the
* browser scale down the image.
*
- * @see add_image_size()
- * @uses apply_filters() Calls 'wp_get_attachment_image_attributes' hook on attributes array
- * @uses wp_get_attachment_image_src() Gets attachment file URL and dimensions
* @since 2.5.0
*
+ * @see add_image_size()
+ * @uses wp_get_attachment_image_src() Gets attachment file URL and dimensions
+ *
* @param int $attachment_id Image attachment ID.
* @param string $size Optional, default is 'thumbnail'.
* @param bool $icon Optional, default is false. Whether it is an icon.
@@ -651,6 +713,15 @@ function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = fa
$default_attr['alt'] = trim(strip_tags( $attachment->post_title )); // Finally, use the title
$attr = wp_parse_args($attr, $default_attr);
+
+ /**
+ * Filter the list of attachment image attributes.
+ *
+ * @since 2.8.0
+ *
+ * @param mixed $attr Attributes for the image markup.
+ * @param int $attachment_id Image attachment ID.
+ */
$attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment );
$attr = array_map( 'esc_attr', $attr );
$html = rtrim("
";
+
+ /**
+ * Filter the default gallery shortcode CSS styles.
+ *
+ * @since 2.5.0
+ *
+ * @param string $gallery_style Default gallery shortcode CSS styles.
+ * @param string $gallery_div Opening HTML div container for the gallery shortcode output.
+ */
$output = apply_filters( 'gallery_style', $gallery_style . $gallery_div );
$i = 0;
@@ -1098,8 +1178,7 @@ function wp_playlist_shortcode( $attr ) {
* @since 3.9.0
*
* @param string $output Playlist output. Default empty.
- * @param array $attr Array of shortcode attributes.
- * @param string $type Type of playlist to generate output for.
+ * @param array $attr An array of shortcode attributes.
*/
$output = apply_filters( 'post_playlist', '', $attr );
if ( $output != '' ) {
@@ -1256,7 +1335,7 @@ function wp_playlist_shortcode( $attr ) {
if ( 1 === $instance ) {
/**
- * Hook to print and enqueue playlist scripts, styles, and JavaScript templates.
+ * Print and enqueue playlist scripts, styles, and JavaScript templates.
*
* @since 3.9.0
*
@@ -1299,16 +1378,32 @@ add_shortcode( 'playlist', 'wp_playlist_shortcode' );
* @return string Fallback HTML
*/
function wp_mediaelement_fallback( $url ) {
+ /**
+ * Filter the Mediaelement fallback output for no-JS.
+ *
+ * @since 3.6.0
+ *
+ * @param string $output Fallback output for no-JS.
+ * @param string $url Media file URL.
+ */
return apply_filters( 'wp_mediaelement_fallback', sprintf( '%1$s', esc_url( $url ) ), $url );
}
/**
- * Return a filtered list of WP-supported audio formats
+ * Return a filtered list of WP-supported audio formats.
*
* @since 3.6.0
* @return array
*/
function wp_get_audio_extensions() {
+ /**
+ * Filter the list of supported audio formats.
+ *
+ * @since 3.6.0
+ *
+ * @param array $extensions An array of support audio formats. Defaults are
+ * 'mp3', 'ogg', 'wma', 'm4a', 'wav'.
+ */
return apply_filters( 'wp_audio_extensions', array( 'mp3', 'ogg', 'wma', 'm4a', 'wav' ) );
}
@@ -1334,12 +1429,13 @@ function wp_get_attachment_id3_keys( $attachment, $context = 'display' ) {
}
/**
- * Filter the editable list of keys to lookup data from an attachment's metadata.
+ * Filter the editable list of keys to look up data from an attachment's metadata.
*
* @since 3.9.0
*
* @param array $fields Key/value pairs of field keys to labels.
* @param WP_Post $attachment Attachment object.
+ * @param string $context The context. Accepts 'edit', 'display'. Default 'display'.
*/
return apply_filters( 'wp_get_attachment_id3_keys', $fields, $attachment, $context );
}
@@ -1383,8 +1479,7 @@ function wp_audio_shortcode( $attr, $content = '' ) {
* @param string $content Shortcode content.
* @param int $instances Unique numeric ID of this audio shortcode instance.
*/
- $html = '';
- $html = apply_filters( 'wp_audio_shortcode_override', $html, $attr, $content, $instances );
+ $html = apply_filters( 'wp_audio_shortcode_override', '', $attr, $content, $instances );
if ( '' !== $html )
return $html;
@@ -1433,12 +1528,26 @@ function wp_audio_shortcode( $attr, $content = '' ) {
array_unshift( $default_types, 'src' );
}
+ /**
+ * Filter the media library used for the audio shortcode.
+ *
+ * @since 3.6.0
+ *
+ * @param string $library Media library used for the audio shortcode.
+ */
$library = apply_filters( 'wp_audio_shortcode_library', 'mediaelement' );
if ( 'mediaelement' === $library && did_action( 'init' ) ) {
wp_enqueue_style( 'wp-mediaelement' );
wp_enqueue_script( 'wp-mediaelement' );
}
+ /**
+ * Filter the class attribute for the audio shortcode output container.
+ *
+ * @since 3.6.0
+ *
+ * @param string $class CSS class or list of space-separated classes.
+ */
$atts = array(
'class' => apply_filters( 'wp_audio_shortcode_class', 'wp-audio-shortcode' ),
'id' => sprintf( 'audio-%d-%d', $post_id, $instances ),
@@ -1480,6 +1589,17 @@ function wp_audio_shortcode( $attr, $content = '' ) {
$html .= wp_mediaelement_fallback( $fileurl );
$html .= '';
+ /**
+ * Filter the audio shortcode output.
+ *
+ * @since 3.6.0
+ *
+ * @param string $html Audio shortcode HTML output.
+ * @param array $atts Array of audio shortcode attributes.
+ * @param string $audio Audio file.
+ * @param int $post_id Post ID.
+ * @param string $library Media library used for the audio shortcode.
+ */
return apply_filters( 'wp_audio_shortcode', $html, $atts, $audio, $post_id, $library );
}
add_shortcode( 'audio', 'wp_audio_shortcode' );
@@ -1491,6 +1611,14 @@ add_shortcode( 'audio', 'wp_audio_shortcode' );
* @return array
*/
function wp_get_video_extensions() {
+ /**
+ * Filter the list of supported video formats.
+ *
+ * @since 3.6.0
+ *
+ * @param array $extensions An array of support video formats. Defaults are
+ * 'mp4', 'm4v', 'webm', 'ogv', 'wmv', 'flv'.
+ */
return apply_filters( 'wp_video_extensions', array( 'mp4', 'm4v', 'webm', 'ogv', 'wmv', 'flv' ) );
}
@@ -1615,12 +1743,26 @@ function wp_video_shortcode( $attr, $content = '' ) {
array_unshift( $default_types, 'src' );
}
+ /**
+ * Filter the media library used for the video shortcode.
+ *
+ * @since 3.6.0
+ *
+ * @param string $library Media library used for the video shortcode.
+ */
$library = apply_filters( 'wp_video_shortcode_library', 'mediaelement' );
if ( 'mediaelement' === $library && did_action( 'init' ) ) {
wp_enqueue_style( 'wp-mediaelement' );
wp_enqueue_script( 'wp-mediaelement' );
}
+ /**
+ * Filter the class attribute for the video shortcode output container.
+ *
+ * @since 3.6.0
+ *
+ * @param string $class CSS class or list of space-separated classes.
+ */
$atts = array(
'class' => apply_filters( 'wp_video_shortcode_class', 'wp-video-shortcode' ),
'id' => sprintf( 'video-%d-%d', $post_id, $instances ),
@@ -1677,6 +1819,18 @@ function wp_video_shortcode( $attr, $content = '' ) {
$html .= '';
$html = sprintf( '