59
59
// if no width is set, default to the theme content width if available
61
61
elseif ( $size == 'large' ) {
62
// We're inserting a large size image into the editor. If it's a really
63
// big image we'll scale it down to fit reasonably within the editor
64
// itself, and within the theme's content width if it's known. The user
65
// can resize it in the editor if they wish.
63
* We're inserting a large size image into the editor. If it's a really
64
* big image we'll scale it down to fit reasonably within the editor
65
* itself, and within the theme's content width if it's known. The user
66
* can resize it in the editor if they wish.
66
68
$max_width = intval(get_option('large_size_w'));
67
69
$max_height = intval(get_option('large_size_h'));
68
70
if ( intval($content_width) > 0 )
112
* @param int|string $width Optional. Width attribute value.
113
* @param int|string $height Optional. Height attribute value.
114
* @param int|string $width Image width in pixels.
115
* @param int|string $height Image height in pixels.
114
116
* @return string HTML attributes for width and, or height.
116
function image_hwstring($width, $height) {
118
function image_hwstring( $width, $height ) {
119
121
$out .= 'width="'.intval($width).'" ';
143
* @param int $id Attachment ID for image.
144
* @param array|string $size Optional, default is 'medium'. Size of image, either array or string.
145
* @param int $id Attachment ID for image.
146
* @param array|string $size Optional. Image size to scale to. Accepts a registered image size
147
* or flat array of height and width values. Default 'medium'.
145
148
* @return bool|array False on failure, array on success.
147
function image_downsize($id, $size = 'medium') {
150
function image_downsize( $id, $size = 'medium' ) {
149
152
if ( !wp_attachment_is_image($id) )
300
* @param int $id Attachment ID.
301
* @param string $alt Image Description for the alt attribute.
302
* @param string $title Image Description for the title attribute.
303
* @param string $align Part of the class name for aligning the image.
304
* @param string $size Optional. Default is 'medium'.
303
* @param int $id Attachment ID.
304
* @param string $alt Image Description for the alt attribute.
305
* @param string $title Image Description for the title attribute.
306
* @param string $align Part of the class name for aligning the image.
307
* @param string|array $size Optional. Registered image size to retrieve a tag for, or flat array
308
* of height and width values. Default 'medium'.
305
309
* @return string HTML IMG element for given image attachment
307
function get_image_tag($id, $alt, $title, $align, $size='medium') {
311
function get_image_tag( $id, $alt, $title, $align, $size = 'medium' ) {
309
313
list( $img_src, $width, $height ) = image_downsize($id, $size);
310
314
$hwstring = image_hwstring($width, $height);
348
* Calculates the new dimensions for a downsampled image.
352
* Calculates the new dimensions for a down-sampled image.
350
354
* If either width or height are empty, no constraint is applied on
351
355
* that dimension.
355
* @param int $current_width Current width of the image.
359
* @param int $current_width Current width of the image.
356
360
* @param int $current_height Current height of the image.
357
* @param int $max_width Optional. Maximum wanted width.
358
* @param int $max_height Optional. Maximum wanted height.
361
* @param int $max_width Optional. Max width in pixels to constrain to. Default 0.
362
* @param int $max_height Optional. Max height in pixels to constrain to. Default 0.
359
363
* @return array First item is the width, the second item is the height.
361
function wp_constrain_dimensions( $current_width, $current_height, $max_width=0, $max_height=0 ) {
362
if ( !$max_width and !$max_height )
365
function wp_constrain_dimensions( $current_width, $current_height, $max_width = 0, $max_height = 0 ) {
366
if ( !$max_width && !$max_height )
363
367
return array( $current_width, $current_height );
365
369
$width_ratio = $height_ratio = 1.0;
405
409
$h = $max_height; // Round it up
413
* Filter dimensions to constrain down-sampled images to.
417
* @param array $dimensions The image width and height.
418
* @param int $current_width The current width of the image.
419
* @param int $current_height The current height of the image.
420
* @param int $max_width The maximum width permitted.
421
* @param int $max_height The maximum height permitted.
408
423
return apply_filters( 'wp_constrain_dimensions', array( $w, $h ), $current_width, $current_height, $max_width, $max_height );
412
* Retrieve calculated resize dimensions for use in WP_Image_Editor.
427
* Retrieves calculated resize dimensions for use in WP_Image_Editor.
414
429
* Calculates dimensions and coordinates for a resized image that fits
415
430
* within a specified width and height.
534
* @param string $file File path.
535
* @param int $width Image width.
536
* @param int $height Image height.
537
* @param bool $crop Optional, default is false. Whether to crop image to specified height and width or resize.
549
* @param string $file File path.
550
* @param int $width Image width.
551
* @param int $height Image height.
552
* @param bool $crop Optional. Whether to crop image to specified height and width or resize.
538
554
* @return bool|array False, if no image was created. Metadata array on success.
540
556
function image_make_intermediate_size( $file, $width, $height, $crop = false ) {
574
590
* browser scale down the image.
577
* @see add_image_size()
579
* @param int $post_id Attachment ID for image.
580
* @param array|string $size Optional, default is 'thumbnail'. Size of image, either array or string.
594
* @param int $post_id Attachment ID.
595
* @param array|string $size Optional. Registered image size to retrieve or flat array of height
596
* and width dimensions. Default 'thumbnail'.
581
597
* @return bool|array False on failure or array of file path, width, and height on success.
583
function image_get_intermediate_size($post_id, $size='thumbnail') {
599
function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) {
584
600
if ( !is_array( $imagedata = wp_get_attachment_metadata( $post_id ) ) )
587
603
// get the best one for a specified set of dimensions
588
604
if ( is_array($size) && !empty($imagedata['sizes']) ) {
589
607
foreach ( $imagedata['sizes'] as $_size => $data ) {
590
608
// already cropped to width or height; so use this size
591
609
if ( ( $data['width'] == $size[0] && $data['height'] <= $size[1] ) || ( $data['height'] == $size[1] && $data['width'] <= $size[0] ) ) {
662
* @param int $attachment_id Image attachment ID.
663
* @param string $size Optional, default is 'thumbnail'.
664
* @param bool $icon Optional, default is false. Whether it is an icon.
684
* @param int $attachment_id Image attachment ID.
685
* @param string|array $size Optional. Registered image size to retrieve the source for or a flat
686
* array of height and width dimensions. Default 'thumbnail'.
687
* @param bool $icon Optional. Whether the image should be treated as an icon. Default false.
665
688
* @return bool|array Returns an array (url, width, height), or false, if no image is available.
667
function wp_get_attachment_image_src($attachment_id, $size='thumbnail', $icon = false) {
690
function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon = false ) {
669
692
// get a thumbnail or intermediate image if there is one
670
693
if ( $image = image_downsize($attachment_id, $size) )
687
711
* Get an HTML img element representing an image attachment
689
* While $size will accept an array, it is better to register a size with
713
* While `$size` will accept an array, it is better to register a size with
690
714
* add_image_size() so that a cropped version is generated. It's much more
691
715
* efficient than having to find the closest-sized image and then having the
692
716
* browser scale down the image.
696
* @see add_image_size()
698
720
* @param int $attachment_id Image attachment ID.
699
* @param string|array $size Optional. Default 'thumbnail'.
700
* @param bool $icon Optional. Whether it is an icon. Default false.
701
* @param string|array $attr Optional. Attributes for the image markup. Default empty string.
721
* @param string|array $size Optional. Registered image size or flat array of height and width
722
* dimensions. Default 'thumbnail'.
723
* @param bool $icon Optional. Whether the image should be treated as an icon. Default false.
724
* @param string|array $attr Optional. Attributes for the image markup. Default empty.
702
725
* @return string HTML img element or empty string on failure.
704
727
function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = false, $attr = '') {
750
* Adds a 'wp-post-image' class to post thumbnails
751
* Uses the begin_fetch_post_thumbnail_html and end_fetch_post_thumbnail_html action hooks to
752
* dynamically add/remove itself so as to only filter post thumbnails
773
* Adds a 'wp-post-image' class to post thumbnails. Internal use only.
775
* Uses the 'begin_fetch_post_thumbnail_html' and 'end_fetch_post_thumbnail_html' action hooks to
776
* dynamically add/remove itself so as to only filter post thumbnails.
755
* @param array $attr Attributes including src, class, alt, title
781
* @param array $attr Thumbnail attributes including src, class, alt, title.
782
* @return array Modified array of attributes including the new 'wp-post-image' class.
758
784
function _wp_post_thumbnail_class_filter( $attr ) {
759
785
$attr['class'] .= ' wp-post-image';
764
* Adds _wp_post_thumbnail_class_filter to the wp_get_attachment_image_attributes filter
790
* Adds '_wp_post_thumbnail_class_filter' callback to the 'wp_get_attachment_image_attributes'
791
* filter hook. Internal use only.
796
* @param array $attr Thumbnail attributes including src, class, alt, title.
768
798
function _wp_post_thumbnail_class_filter_add( $attr ) {
769
799
add_filter( 'wp_get_attachment_image_attributes', '_wp_post_thumbnail_class_filter' );
773
* Removes _wp_post_thumbnail_class_filter from the wp_get_attachment_image_attributes filter
803
* Removes the '_wp_post_thumbnail_class_filter' callback from the 'wp_get_attachment_image_attributes'
804
* filter hook. Internal use only.
809
* @param array $attr Thumbnail attributes including src, class, alt, title.
777
811
function _wp_post_thumbnail_class_filter_remove( $attr ) {
778
812
remove_filter( 'wp_get_attachment_image_attributes', '_wp_post_thumbnail_class_filter' );
936
970
* the default gallery template.
973
* @since 4.2.0 The `$instance` parameter was added.
940
975
* @see gallery_shortcode()
942
* @param string $output The gallery output. Default empty.
943
* @param array $attr Attributes of the gallery shortcode.
977
* @param string $output The gallery output. Default empty.
978
* @param array $attr Attributes of the gallery shortcode.
979
* @param int $instance Unique numeric ID of this gallery shortcode instance.
945
$output = apply_filters( 'post_gallery', '', $attr );
981
$output = apply_filters( 'post_gallery', '', $attr, $instance );
946
982
if ( $output != '' ) {
1154
1190
add_action( 'wp_footer', 'wp_underscore_playlist_templates', 0 );
1155
1191
add_action( 'admin_footer', 'wp_underscore_playlist_templates', 0 );
1157
add_action( 'wp_playlist_scripts', 'wp_playlist_scripts' );
1160
* The playlist shortcode.
1195
* Builds the Playlist shortcode output.
1162
1197
* This implements the functionality of the playlist shortcode for displaying
1163
1198
* a collection of WordPress audio or video files in a post.
1212
1247
* of the default playlist output, returning the passed value instead.
1250
* @since 4.2.0 The `$instance` parameter was added.
1216
* @param string $output Playlist output. Default empty.
1217
* @param array $attr An array of shortcode attributes.
1252
* @param string $output Playlist output. Default empty.
1253
* @param array $attr An array of shortcode attributes.
1254
* @param int $instance Unique numeric ID of this playlist shortcode instance.
1219
$output = apply_filters( 'post_playlist', '', $attr );
1256
$output = apply_filters( 'post_playlist', '', $attr, $instance );
1220
1257
if ( $output != '' ) {
1221
1258
return $output;
1401
1438
add_shortcode( 'playlist', 'wp_playlist_shortcode' );
1404
* Provide a No-JS Flash fallback as a last resort for audio / video
1441
* Provides a No-JS Flash fallback as a last resort for audio / video.
1408
* @param string $url
1409
* @return string Fallback HTML
1445
* @param string $url The media element URL.
1446
* @return string Fallback HTML.
1411
1448
function wp_mediaelement_fallback( $url ) {
1442
* Return useful keys to use to lookup data from an attachment's stored metadata.
1480
* Returns useful keys to use to lookup data from an attachment's stored metadata.
1446
1484
* @param WP_Post $attachment The current attachment, provided for context.
1447
* @param string $context The context. Accepts 'edit', 'display'. Default 'display'.
1485
* @param string $context Optional. The context. Accepts 'edit', 'display'. Default 'display'.
1448
1486
* @return array Key/value pairs of field keys to labels.
1450
1488
function wp_get_attachment_id3_keys( $attachment, $context = 'display' ) {
1474
1512
return apply_filters( 'wp_get_attachment_id3_keys', $fields, $attachment, $context );
1477
* The Audio shortcode.
1515
* Builds the Audio shortcode output.
1479
1517
* This implements the functionality of the Audio Shortcode for displaying
1480
1518
* WordPress mp3s in a post.
1484
* @param array $attr {
1522
* @param array $attr {
1485
1523
* Attributes of the audio shortcode.
1487
1525
* @type string $src URL to the source of the audio file. Default empty.
1489
1527
* @type string $autoplay The 'autoplay' attribute for the `<audio>` element. Default empty.
1490
1528
* @type string $preload The 'preload' attribute for the `<audio>` element. Default empty.
1491
1529
* @type string $class The 'class' attribute for the `<audio>` element. Default 'wp-audio-shortcode'.
1492
* @type string $id The 'id' attribute for the `<audio>` element. Default 'audio-{$post_id}-{$instances}'.
1530
* @type string $id The 'id' attribute for the `<audio>` element. Default 'audio-{$post_id}-{$instance}'.
1493
1531
* @type string $style The 'style' attribute for the `<audio>` element. Default 'width: 100%'.
1495
* @param string $content Optional. Shortcode content.
1533
* @param string $content Shortcode content.
1496
1534
* @return string HTML content to display audio.
1498
1536
function wp_audio_shortcode( $attr, $content = '' ) {
1499
1537
$post_id = get_post() ? get_the_ID() : 0;
1501
static $instances = 0;
1539
static $instance = 0;
1505
1543
* Filter the default audio shortcode output.
1511
* @param string $html Empty variable to be replaced with shortcode markup.
1512
* @param array $attr Attributes of the shortcode. @see wp_audio_shortcode()
1513
* @param string $content Shortcode content.
1514
* @param int $instances Unique numeric ID of this audio shortcode instance.
1549
* @param string $html Empty variable to be replaced with shortcode markup.
1550
* @param array $attr Attributes of the shortcode. @see wp_audio_shortcode()
1551
* @param string $content Shortcode content.
1552
* @param int $instance Unique numeric ID of this audio shortcode instance.
1516
$override = apply_filters( 'wp_audio_shortcode_override', '', $attr, $content, $instances );
1554
$override = apply_filters( 'wp_audio_shortcode_override', '', $attr, $content, $instance );
1517
1555
if ( '' !== $override ) {
1518
1556
return $override;
1590
1628
$html_atts = array(
1591
1629
'class' => apply_filters( 'wp_audio_shortcode_class', 'wp-audio-shortcode' ),
1592
'id' => sprintf( 'audio-%d-%d', $post_id, $instances ),
1630
'id' => sprintf( 'audio-%d-%d', $post_id, $instance ),
1593
1631
'loop' => wp_validate_boolean( $atts['loop'] ),
1594
1632
'autoplay' => wp_validate_boolean( $atts['autoplay'] ),
1595
1633
'preload' => $atts['preload'],
1622
1660
$fileurl = $atts[ $fallback ];
1624
1662
$type = wp_check_filetype( $atts[ $fallback ], wp_get_mime_types() );
1625
$url = add_query_arg( '_', $instances, $atts[ $fallback ] );
1663
$url = add_query_arg( '_', $instance, $atts[ $fallback ] );
1626
1664
$html .= sprintf( $source, $type['type'], esc_url( $url ) );
1687
1726
* @type string $class The 'class' attribute for the `<video>` element.
1688
1727
* Default 'wp-video-shortcode'.
1689
1728
* @type string $id The 'id' attribute for the `<video>` element.
1690
* Default 'video-{$post_id}-{$instances}'.
1729
* Default 'video-{$post_id}-{$instance}'.
1692
* @param string $content Optional. Shortcode content.
1731
* @param string $content Shortcode content.
1693
1732
* @return string HTML content to display video.
1695
1734
function wp_video_shortcode( $attr, $content = '' ) {
1696
1735
global $content_width;
1697
1736
$post_id = get_post() ? get_the_ID() : 0;
1699
static $instances = 0;
1738
static $instance = 0;
1703
1742
* Filter the default video shortcode output.
1710
1749
* @see wp_video_shortcode()
1712
* @param string $html Empty variable to be replaced with shortcode markup.
1713
* @param array $attr Attributes of the video shortcode.
1714
* @param string $content Video shortcode content.
1715
* @param int $instances Unique numeric ID of this video shortcode instance.
1751
* @param string $html Empty variable to be replaced with shortcode markup.
1752
* @param array $attr Attributes of the video shortcode.
1753
* @param string $content Video shortcode content.
1754
* @param int $instance Unique numeric ID of this video shortcode instance.
1717
$override = apply_filters( 'wp_video_shortcode_override', '', $attr, $content, $instances );
1756
$override = apply_filters( 'wp_video_shortcode_override', '', $attr, $content, $instance );
1718
1757
if ( '' !== $override ) {
1719
1758
return $override;
1794
$is_vimeo = $is_youtube = false;
1755
1795
$yt_pattern = '#^https?://(?:www\.)?(?:youtube\.com/watch|youtu\.be/)#';
1796
$vimeo_pattern = '#^https?://(.+\.)?vimeo\.com/.*#';
1757
1798
$primary = false;
1758
1799
if ( ! empty( $atts['src'] ) ) {
1759
if ( ! preg_match( $yt_pattern, $atts['src'] ) ) {
1800
$is_vimeo = ( preg_match( $vimeo_pattern, $atts['src'] ) );
1801
$is_youtube = ( preg_match( $yt_pattern, $atts['src'] ) );
1802
if ( ! $is_youtube && ! $is_vimeo ) {
1760
1803
$type = wp_check_filetype( $atts['src'], wp_get_mime_types() );
1761
1804
if ( ! in_array( strtolower( $type['ext'] ), $default_types ) ) {
1762
1805
return sprintf( '<a class="wp-embedded-video" href="%s">%s</a>', esc_url( $atts['src'] ), esc_html( $atts['src'] ) );
1810
wp_enqueue_script( 'froogaloop' );
1765
1813
$primary = true;
1766
1814
array_unshift( $default_types, 'src' );
1813
1861
$html_atts = array(
1814
1862
'class' => apply_filters( 'wp_video_shortcode_class', 'wp-video-shortcode' ),
1815
'id' => sprintf( 'video-%d-%d', $post_id, $instances ),
1863
'id' => sprintf( 'video-%d-%d', $post_id, $instance ),
1816
1864
'width' => absint( $atts['width'] ),
1817
1865
'height' => absint( $atts['height'] ),
1818
1866
'poster' => esc_url( $atts['poster'] ),
1846
1894
if ( empty( $fileurl ) ) {
1847
1895
$fileurl = $atts[ $fallback ];
1849
if ( 'src' === $fallback && preg_match( $yt_pattern, $atts['src'] ) ) {
1897
if ( 'src' === $fallback && $is_youtube ) {
1850
1898
$type = array( 'type' => 'video/youtube' );
1899
} elseif ( 'src' === $fallback && $is_vimeo ) {
1900
$type = array( 'type' => 'video/vimeo' );
1852
1902
$type = wp_check_filetype( $atts[ $fallback ], wp_get_mime_types() );
1854
$url = add_query_arg( '_', $instances, $atts[ $fallback ] );
1904
$url = add_query_arg( '_', $instance, $atts[ $fallback ] );
1855
1905
$html .= sprintf( $source, $type['type'], esc_url( $url ) );
1890
1940
add_shortcode( 'video', 'wp_video_shortcode' );
1893
* Display previous image link that has the same post parent.
1943
* Displays previous image link that has the same post parent.
1896
* @param string $size Optional, default is 'thumbnail'. Size of image, either array or string. 0 or 'none' will default to post_title or $text;
1897
* @param string $text Optional, default is false. If included, link will reflect $text variable.
1898
* @return string HTML content.
1947
* @see adjacent_image_link()
1949
* @param string|array $size Optional. Registered image size or flat array of height and width dimensions.
1950
* 0 or 'none' will default to 'post_title' or `$text`. Default 'thumbnail'.
1951
* @param string $text Optional. Link text. Default false.
1952
* @return string HTML output for the previous image link.
1900
function previous_image_link($size = 'thumbnail', $text = false) {
1954
function previous_image_link( $size = 'thumbnail', $text = false ) {
1901
1955
adjacent_image_link(true, $size, $text);
1905
* Display next image link that has the same post parent.
1959
* Displays next image link that has the same post parent.
1908
* @param string $size Optional, default is 'thumbnail'. Size of image, either array or string. 0 or 'none' will default to post_title or $text;
1909
* @param string $text Optional, default is false. If included, link will reflect $text variable.
1910
* @return string HTML content.
1963
* @see adjacent_image_link()
1965
* @param string|array $size Optional. Registered image size or flat array of height and width dimensions.
1966
* 0 or 'none' will default to 'post_title' or `$text`. Default 'thumbnail'.
1967
* @param string $text Optional. Link text. Default false.
1968
* @return string HTML output for the next image link.
1912
1970
function next_image_link($size = 'thumbnail', $text = false) {
1913
1971
adjacent_image_link(false, $size, $text);
1917
* Display next or previous image link that has the same post parent.
1975
* Displays next or previous image link that has the same post parent.
1919
1977
* Retrieves the current attachment object from the $post global.
1923
* @param bool $prev Optional. Default is true to display previous link, false for next.
1981
* @param bool $prev Optional. Whether to display the next (false) or previous (true) link. Default true.
1982
* @param string|array $size Optional. Registered image size or flat array of height and width dimensions.
1983
* Default 'thumbnail'.
1984
* @param bool $text Optional. Link text. Default false.
1985
* @return string The adjacent image link.
1925
function adjacent_image_link($prev = true, $size = 'thumbnail', $text = false) {
1987
function adjacent_image_link( $prev = true, $size = 'thumbnail', $text = false ) {
1926
1988
$post = get_post();
1927
1989
$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' ) ) );
1966
* Retrieve taxonomies attached to the attachment.
2028
* Retrieves taxonomies attached to given the attachment.
1970
* @param int|array|object $attachment Attachment ID, Attachment data array, or Attachment data object.
2032
* @param int|array|object $attachment Attachment ID, data array, or data object.
1971
2033
* @return array Empty array on failure. List of taxonomies on success.
1973
function get_attachment_taxonomies($attachment) {
1974
if ( is_int( $attachment ) )
1975
$attachment = get_post($attachment);
1976
else if ( is_array($attachment) )
2035
function get_attachment_taxonomies( $attachment ) {
2036
if ( is_int( $attachment ) ) {
2037
$attachment = get_post( $attachment );
2038
} elseif ( is_array( $attachment ) ) {
1977
2039
$attachment = (object) $attachment;
1979
2041
if ( ! is_object($attachment) )
1980
2042
return array();
2005
* Return all of the taxonomy names that are registered for attachments.
2067
* Retrieves all of the taxonomy names that are registered for attachments.
2007
2069
* Handles mime-type-specific taxonomies such as attachment:image and attachment:video.
2010
* @see get_attachment_taxonomies()
2012
* @param string $output The type of output to return, either taxonomy 'names' or 'objects'. 'names' is the default.
2073
* @see get_taxonomies()
2075
* @param string $output Optional. The type of taxonomy output to return. Accepts 'names' or 'objects'.
2013
2077
* @return array The names of all taxonomy of $object_type.
2015
2079
function get_taxonomies_for_attachments( $output = 'names' ) {
2033
2097
* Create new GD image resource with transparency support
2034
* @TODO: Deprecate if possible.
2099
* @todo: Deprecate if possible.
2038
* @param int $width Image width
2039
* @param int $height Image height
2040
* @return resource resource
2103
* @param int $width Image width in pixels.
2104
* @param int $height Image height in pixels..
2105
* @return resource The GD image resource.
2042
2107
function wp_imagecreatetruecolor($width, $height) {
2043
2108
$img = imagecreatetruecolor($width, $height);
2052
* Register an embed handler. This function should probably only be used for sites that do not support oEmbed.
2117
* Registers an embed handler.
2119
* Should probably only be used for sites that do not support oEmbed.
2055
2123
* @see WP_Embed::register_handler()
2057
* @global WP_Embed $wp_embed
2059
* @param string $regex
2060
* @param callable $callback
2061
* @param int $priority
2125
* @param string $id An internal ID/name for the handler. Needs to be unique.
2126
* @param string $regex The regex that will be used to see if this handler should be used for a URL.
2127
* @param callback $callback The callback function that will be called if the regex is matched.
2128
* @param int $priority Optional. Used to specify the order in which the registered handlers will
2129
* be tested. Default 10.
2063
2131
function wp_embed_register_handler( $id, $regex, $callback, $priority = 10 ) {
2064
2132
global $wp_embed;
2069
* Unregister a previously registered embed handler.
2137
* Unregisters a previously-registered embed handler.
2072
2141
* @see WP_Embed::unregister_handler()
2074
* @global WP_Embed $wp_embed
2076
* @param int $priority
2143
* @param string $id The handler ID that should be removed.
2144
* @param int $priority Optional. The priority of the handler to be removed. Default 10.
2078
2146
function wp_embed_unregister_handler( $id, $priority = 10 ) {
2079
2147
global $wp_embed;
2125
* @param int $example_width The width of an example embed.
2193
* @see wp_constrain_dimensions()
2195
* @param int $example_width The width of an example embed.
2126
2196
* @param int $example_height The height of an example embed.
2127
* @param int $max_width The maximum allowed width.
2128
* @param int $max_height The maximum allowed height.
2197
* @param int $max_width The maximum allowed width.
2198
* @param int $max_height The maximum allowed height.
2129
2199
* @return array The maximum possible width and height based on the example ratio.
2131
2201
function wp_expand_dimensions( $example_width, $example_height, $max_width, $max_height ) {
2141
2211
* Attempts to fetch the embed HTML for a provided URL using oEmbed.
2144
2215
* @see WP_oEmbed
2146
* @param string $url The URL that should be embedded.
2147
* @param array $args Additional arguments and parameters.
2217
* @param string $url The URL that should be embedded.
2218
* @param array $args Optional. Additional arguments and parameters for retrieving embed HTML.
2148
2220
* @return false|string False on failure or the embed HTML on success.
2150
2222
function wp_oembed_get( $url, $args = '' ) {
2157
2229
* Adds a URL format and oEmbed provider URL pair.
2160
2233
* @see WP_oEmbed
2162
* @param string $format The format of URL that this provider can handle. You can use asterisks as wildcards.
2163
* @param string $provider The URL to the oEmbed provider.
2164
* @param boolean $regex Whether the $format parameter is in a regex format.
2235
* @param string $format The format of URL that this provider can handle. You can use asterisks
2237
* @param string $provider The URL to the oEmbed provider.
2238
* @param boolean $regex Optional. Whether the `$format` parameter is in a RegEx format. Default false.
2166
2240
function wp_oembed_add_provider( $format, $provider, $regex = false ) {
2167
2241
require_once( ABSPATH . WPINC . '/class-oembed.php' );
2248
* The Google Video embed handler callback. Google Video does not support oEmbed.
2326
* The Google Video embed handler callback.
2328
* Google Video does not support oEmbed.
2250
2330
* @see WP_Embed::register_handler()
2251
2331
* @see WP_Embed::shortcode()
2253
* @param array $matches The regex matches from the provided regex when calling {@link wp_embed_register_handler()}.
2254
* @param array $attr Embed attributes.
2255
* @param string $url The original URL that was matched by the regex.
2256
* @param array $rawattr The original unmodified attributes.
2333
* @param array $matches The RegEx matches from the provided regex when calling wp_embed_register_handler().
2334
* @param array $attr Embed attributes.
2335
* @param string $url The original URL that was matched by the regex.
2336
* @param array $rawattr The original unmodified attributes.
2257
2337
* @return string The embed HTML.
2259
2339
function wp_embed_handler_googlevideo( $matches, $attr, $url, $rawattr ) {
2283
* YouTube embed handler callback.
2363
* YouTube iframe embed handler callback.
2285
* Catches URLs that can be parsed but aren't supported by oEmbed.
2365
* Catches YouTube iframe embed URLs that are not parsable by oEmbed but can be translated into a URL that is.
2289
* @param array $matches The regex matches from the provided regex when calling
2290
* {@see wp_embed_register_handler()}.
2369
* @param array $matches The RegEx matches from the provided regex when calling
2370
* wp_embed_register_handler().
2291
2371
* @param array $attr Embed attributes.
2292
2372
* @param string $url The original URL that was matched by the regex.
2293
2373
* @param array $rawattr The original unmodified attributes.
2346
* @param array $matches The regex matches from the provided regex when calling {@link wp_embed_register_handler()}.
2347
* @param array $attr Embed attributes.
2348
* @param string $url The original URL that was matched by the regex.
2349
* @param array $rawattr The original unmodified attributes.
2427
* @param array $matches The RegEx matches from the provided regex when calling wp_embed_register_handler().
2428
* @param array $attr Embed attributes.
2429
* @param string $url The original URL that was matched by the regex.
2430
* @param array $rawattr The original unmodified attributes.
2350
2431
* @return string The embed HTML.
2352
2433
function wp_embed_handler_video( $matches, $attr, $url, $rawattr ) {
2417
2498
* Returns a WP_Image_Editor instance and loads file into it.
2422
* @param string $path Path to file to load
2423
* @param array $args Additional data. Accepts { 'mime_type'=>string, 'methods'=>{string, string, ...} }
2424
* @return WP_Image_Editor|WP_Error
2502
* @param string $path Path to the file to load.
2503
* @param array $args Optional. Additional arguments for retrieving the image editor.
2504
* Default empty array.
2505
* @return WP_Image_Editor|WP_Error The WP_Image_Editor object if successful, an WP_Error
2426
2508
function wp_get_image_editor( $path, $args = array() ) {
2427
2509
$args['path'] = $path;
2454
2536
* Tests whether there is an editor that supports a given mime type or methods.
2459
* @param string|array $args Array of requirements. Accepts { 'mime_type'=>string, 'methods'=>{string, string, ...} }
2460
* @return boolean true if an eligible editor is found; false otherwise
2540
* @param string|array $args Optional. Array of arguments to retrieve the image editor supports.
2541
* Default empty array.
2542
* @return bool True if an eligible editor is found; false otherwise.
2462
2544
function wp_image_editor_supports( $args = array() ) {
2463
2545
return (bool) _wp_image_editor_choose( $args );
2467
2549
* Tests which editors are capable of supporting the request.
2472
* @param array $args Additional data. Accepts { 'mime_type'=>string, 'methods'=>{string, string, ...} }
2473
* @return string|bool Class name for the first editor that claims to support the request. False if no editor claims to support the request.
2554
* @param array $args Optional. Array of arguments for choosing a capable editor. Default empty array.
2555
* @return string|bool Class name for the first editor that claims to support the request. False if no
2556
* editor claims to support the request.
2475
2558
function _wp_image_editor_choose( $args = array() ) {
2476
2559
require_once ABSPATH . WPINC . '/class-wp-image-editor.php';
2888
2977
$thumbnail_support = current_theme_supports( 'post-thumbnails', $post->post_type ) && post_type_supports( $post->post_type, 'thumbnail' );
2889
2978
if ( ! $thumbnail_support && 'attachment' === $post->post_type && $post->post_mime_type ) {
2890
if ( 0 === strpos( $post->post_mime_type, 'audio/' ) ) {
2979
if ( wp_attachment_is( 'audio', $post ) ) {
2891
2980
$thumbnail_support = post_type_supports( 'attachment:audio', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:audio' );
2892
} elseif ( 0 === strpos( $post->post_mime_type, 'video/' ) ) {
2981
} elseif ( wp_attachment_is( 'video', $post ) ) {
2893
2982
$thumbnail_support = post_type_supports( 'attachment:video', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:video' );
2918
3007
lack of plural support here, turn it into "selected: %d" then translate it.
2920
3009
'selected' => __( '%d selected' ),
2921
'dragInfo' => __( 'Drag and drop to reorder images.' ),
3010
'dragInfo' => __( 'Drag and drop to reorder media files.' ),
2924
3013
'uploadFilesTitle' => __( 'Upload Files' ),
3128
3217
* @param string $content A string which might contain media data.
3129
* @param array $types array of media types: 'audio', 'video', 'object', 'embed', or 'iframe'
3130
* @return array A list of found HTML media embeds
3218
* @param array $types An array of media types: 'audio', 'video', 'object', 'embed', or 'iframe'.
3219
* @return array A list of found HTML media embeds.
3132
3221
function get_media_embedded_in_content( $content, $types = null ) {
3133
3222
$html = array();
3134
$allowed_media_types = array( 'audio', 'video', 'object', 'embed', 'iframe' );
3225
* Filter the embedded media types that are allowed to be returned from the content blob.
3229
* @param array $allowed_media_types An array of allowed media types. Default media types are
3230
* 'audio', 'video', 'object', 'embed', and 'iframe'.
3232
$allowed_media_types = apply_filters( 'media_embedded_in_content_allowed_types', array( 'audio', 'video', 'object', 'embed', 'iframe' ) );
3135
3234
if ( ! empty( $types ) ) {
3136
if ( ! is_array( $types ) )
3235
if ( ! is_array( $types ) ) {
3137
3236
$types = array( $types );
3138
3239
$allowed_media_types = array_intersect( $allowed_media_types, $types );
3141
foreach ( $allowed_media_types as $tag ) {
3142
if ( preg_match( '#' . get_tag_regex( $tag ) . '#', $content, $matches ) ) {
3143
$html[] = $matches[0];
3242
$tags = implode( '|', $allowed_media_types );
3244
if ( preg_match_all( '#<(?P<tag>' . $tags . ')[^<]*?(?:>[\s\S]*?<\/(?P=tag)>|\s*\/>)#', $content, $matches ) ) {
3245
foreach ( $matches[0] as $match ) {
3151
* Retrieve galleries from the passed post's content.
3254
* Retrieves galleries from the passed post's content.
3155
* @param int|WP_Post $post Optional. Post ID or object.
3156
* @param bool $html Whether to return HTML or data in the array.
3258
* @param int|WP_Post $post Post ID or object.
3259
* @param bool $html Optional. Whether to return HTML or data in the array. Default true.
3157
3260
* @return array A list of arrays, each containing gallery data and srcs parsed
3158
* from the expanded shortcode.
3261
* from the expanded shortcode.
3160
3263
function get_post_galleries( $post, $html = true ) {
3161
3264
if ( ! $post = get_post( $post ) )
3232
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
3335
* @see get_post_galleries()
3337
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`.
3233
3338
* @return array A list of lists, each containing image srcs parsed.
3234
* from an expanded shortcode
3339
* from an expanded shortcode
3236
3341
function get_post_galleries_images( $post = 0 ) {
3237
3342
$galleries = get_post_galleries( $post, false );
3242
* Check a post's content for galleries and return the image srcs for the first found gallery
3347
* Checks a post's content for galleries and return the image srcs for the first found gallery
3246
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
3351
* @see get_post_gallery()
3353
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global `$post`.
3247
3354
* @return array A list of a gallery's image srcs in order.
3249
3356
function get_post_gallery_images( $post = 0 ) {
3280
* Try to convert an attachment URL into a post ID.
3387
* Tries to convert an attachment URL into a post ID.
3284
3391
* @global wpdb $wpdb WordPress database abstraction object.
3286
3393
* @param string $url The URL to resolve.
3287
* @return int The found post ID.
3394
* @return int The found post ID, or 0 on failure.
3289
3396
function attachment_url_to_postid( $url ) {
3303
3410
$post_id = $wpdb->get_var( $sql );
3304
if ( ! empty( $post_id ) ) {
3305
return (int) $post_id;
3413
* Filter an attachment id found by URL.
3417
* @param int|null $post_id The post_id (if any) found by the function.
3418
* @param string $url The URL being looked up.
3420
$post_id = apply_filters( 'attachment_url_to_postid', $post_id, $url );
3422
return (int) $post_id;
3310
* Return the URLs for CSS files used in an iframe-sandbox'd TinyMCE media view.
3426
* Returns the URLs for CSS files used in an iframe-sandbox'd TinyMCE media view.