~canonical-sysadmins/wordpress/4.2.1

« back to all changes in this revision

Viewing changes to wp-includes/media.php

  • Committer: Paul Gear
  • Date: 2015-04-24 01:35:20 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: paul.gear@canonical.com-20150424013520-w4p9ksth76zh6opw
Merge new upstream release 4.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
                // if no width is set, default to the theme content width if available
60
60
        }
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.
 
62
                /*
 
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.
 
67
                 */
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 )
109
111
 *
110
112
 * @since 2.5.0
111
113
 *
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.
115
117
 */
116
 
function image_hwstring($width, $height) {
 
118
function image_hwstring( $width, $height ) {
117
119
        $out = '';
118
120
        if ($width)
119
121
                $out .= 'width="'.intval($width).'" ';
140
142
 *
141
143
 * @since 2.5.0
142
144
 *
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.
146
149
 */
147
 
function image_downsize($id, $size = 'medium') {
 
150
function image_downsize( $id, $size = 'medium' ) {
148
151
 
149
152
        if ( !wp_attachment_is_image($id) )
150
153
                return false;
284
287
}
285
288
 
286
289
/**
287
 
 * An <img src /> tag for an image attachment, scaling it down if requested.
 
290
 * Gets an img tag for an image attachment, scaling it down if requested.
288
291
 *
289
292
 * The filter 'get_image_tag_class' allows for changing the class name for the
290
293
 * image without having to use regular expressions on the HTML content. The
297
300
 *
298
301
 * @since 2.5.0
299
302
 *
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
306
310
 */
307
 
function get_image_tag($id, $alt, $title, $align, $size='medium') {
 
311
function get_image_tag( $id, $alt, $title, $align, $size = 'medium' ) {
308
312
 
309
313
        list( $img_src, $width, $height ) = image_downsize($id, $size);
310
314
        $hwstring = image_hwstring($width, $height);
345
349
}
346
350
 
347
351
/**
348
 
 * Calculates the new dimensions for a downsampled image.
 
352
 * Calculates the new dimensions for a down-sampled image.
349
353
 *
350
354
 * If either width or height are empty, no constraint is applied on
351
355
 * that dimension.
352
356
 *
353
357
 * @since 2.5.0
354
358
 *
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.
360
364
 */
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 );
364
368
 
365
369
        $width_ratio = $height_ratio = 1.0;
405
409
                $h = $max_height; // Round it up
406
410
        }
407
411
 
 
412
        /**
 
413
         * Filter dimensions to constrain down-sampled images to.
 
414
         *
 
415
         * @since 4.1.0
 
416
         *
 
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.
 
422
         */
408
423
        return apply_filters( 'wp_constrain_dimensions', array( $w, $h ), $current_width, $current_height, $max_width, $max_height );
409
424
}
410
425
 
411
426
/**
412
 
 * Retrieve calculated resize dimensions for use in WP_Image_Editor.
 
427
 * Retrieves calculated resize dimensions for use in WP_Image_Editor.
413
428
 *
414
429
 * Calculates dimensions and coordinates for a resized image that fits
415
430
 * within a specified width and height.
523
538
}
524
539
 
525
540
/**
526
 
 * Resize an image to make a thumbnail or intermediate size.
 
541
 * Resizes an image to make a thumbnail or intermediate size.
527
542
 *
528
543
 * The returned array has the file size, the image width, and image height. The
529
544
 * filter 'image_make_intermediate_size' can be used to hook in and change the
531
546
 *
532
547
 * @since 2.5.0
533
548
 *
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.
 
553
 *                       Default false.
538
554
 * @return bool|array False, if no image was created. Metadata array on success.
539
555
 */
540
556
function image_make_intermediate_size( $file, $width, $height, $crop = false ) {
555
571
}
556
572
 
557
573
/**
558
 
 * Retrieve the image's intermediate size (resized) path, width, and height.
 
574
 * Retrieves the image's intermediate size (resized) path, width, and height.
559
575
 *
560
576
 * The $size parameter can be an array with the width and height respectively.
561
577
 * If the size matches the 'sizes' metadata array for width and height, then it
574
590
 * browser scale down the image.
575
591
 *
576
592
 * @since 2.5.0
577
 
 * @see add_image_size()
578
593
 *
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.
582
598
 */
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 ) ) )
585
601
                return false;
586
602
 
587
603
        // get the best one for a specified set of dimensions
588
604
        if ( is_array($size) && !empty($imagedata['sizes']) ) {
 
605
                $areas = array();
 
606
 
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] ) ) {
631
649
}
632
650
 
633
651
/**
634
 
 * Get the available image sizes
 
652
 * Gets the available intermediate image sizes.
 
653
 *
635
654
 * @since 3.0.0
636
 
 * @return array Returns a filtered array of image size strings
 
655
 *
 
656
 * @global array $_wp_additional_image_sizes
 
657
 *
 
658
 * @return array Returns a filtered array of image size strings.
637
659
 */
638
660
function get_intermediate_image_sizes() {
639
661
        global $_wp_additional_image_sizes;
659
681
 *
660
682
 * @since 2.5.0
661
683
 *
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.
666
689
 */
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 ) {
668
691
 
669
692
        // get a thumbnail or intermediate image if there is one
670
693
        if ( $image = image_downsize($attachment_id, $size) )
675
698
        if ( $icon && $src = wp_mime_type_icon($attachment_id) ) {
676
699
                /** This filter is documented in wp-includes/post.php */
677
700
                $icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/media' );
 
701
 
678
702
                $src_file = $icon_dir . '/' . wp_basename($src);
679
703
                @list($width, $height) = getimagesize($src_file);
680
704
        }
686
710
/**
687
711
 * Get an HTML img element representing an image attachment
688
712
 *
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.
693
717
 *
694
718
 * @since 2.5.0
695
719
 *
696
 
 * @see add_image_size()
697
 
 *
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.
703
726
 */
704
727
function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = false, $attr = '') {
747
770
}
748
771
 
749
772
/**
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
753
 
 *
 
773
 * Adds a 'wp-post-image' class to post thumbnails. Internal use only.
 
774
 *
 
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.
 
777
 *
 
778
 * @ignore
754
779
 * @since 2.9.0
755
 
 * @param array $attr Attributes including src, class, alt, title
756
 
 * @return array
 
780
 *
 
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.
757
783
 */
758
784
function _wp_post_thumbnail_class_filter( $attr ) {
759
785
        $attr['class'] .= ' wp-post-image';
761
787
}
762
788
 
763
789
/**
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.
765
792
 *
 
793
 * @ignore
766
794
 * @since 2.9.0
 
795
 *
 
796
 * @param array $attr Thumbnail attributes including src, class, alt, title.
767
797
 */
768
798
function _wp_post_thumbnail_class_filter_add( $attr ) {
769
799
        add_filter( 'wp_get_attachment_image_attributes', '_wp_post_thumbnail_class_filter' );
770
800
}
771
801
 
772
802
/**
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.
774
805
 *
 
806
 * @ignore
775
807
 * @since 2.9.0
 
808
 *
 
809
 * @param array $attr Thumbnail attributes including src, class, alt, title.
776
810
 */
777
811
function _wp_post_thumbnail_class_filter_remove( $attr ) {
778
812
        remove_filter( 'wp_get_attachment_image_attributes', '_wp_post_thumbnail_class_filter' );
782
816
add_shortcode('caption', 'img_caption_shortcode');
783
817
 
784
818
/**
785
 
 * The Caption shortcode.
 
819
 * Builds the Caption shortcode output.
786
820
 *
787
821
 * Allows a plugin to replace the content that would otherwise be returned. The
788
822
 * filter is 'img_caption_shortcode' and passes an empty string, the attr
793
827
 *
794
828
 * @since 2.6.0
795
829
 *
796
 
 * @param array $attr {
 
830
 * @param array  $attr {
797
831
 *     Attributes of the caption shortcode.
798
832
 *
799
833
 *     @type string $id      ID of the div element for the caption.
803
837
 *     @type string $caption The caption text.
804
838
 *     @type string $class   Additional class name(s) added to the caption container.
805
839
 * }
806
 
 * @param string $content Optional. Shortcode content.
 
840
 * @param string $content Shortcode content.
807
841
 * @return string HTML content to display the caption.
808
842
 */
809
843
function img_caption_shortcode( $attr, $content = null ) {
885
919
add_shortcode('gallery', 'gallery_shortcode');
886
920
 
887
921
/**
888
 
 * The Gallery shortcode.
 
922
 * Builds the Gallery shortcode output.
889
923
 *
890
924
 * This implements the functionality of the Gallery Shortcode for displaying
891
925
 * WordPress images on a post.
936
970
         * the default gallery template.
937
971
         *
938
972
         * @since 2.5.0
 
973
         * @since 4.2.0 The `$instance` parameter was added.
939
974
         *
940
975
         * @see gallery_shortcode()
941
976
         *
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.
944
980
         */
945
 
        $output = apply_filters( 'post_gallery', '', $attr );
 
981
        $output = apply_filters( 'post_gallery', '', $attr, $instance );
946
982
        if ( $output != '' ) {
947
983
                return $output;
948
984
        }
1101
1137
}
1102
1138
 
1103
1139
/**
1104
 
 * Output the templates used by playlists.
 
1140
 * Outputs the templates used by playlists.
1105
1141
 *
1106
1142
 * @since 3.9.0
1107
1143
 */
1139
1175
}
1140
1176
 
1141
1177
/**
1142
 
 * Output and enqueue default scripts and styles for playlists.
 
1178
 * Outputs and enqueue default scripts and styles for playlists.
1143
1179
 *
1144
1180
 * @since 3.9.0
1145
1181
 *
1154
1190
        add_action( 'wp_footer', 'wp_underscore_playlist_templates', 0 );
1155
1191
        add_action( 'admin_footer', 'wp_underscore_playlist_templates', 0 );
1156
1192
}
1157
 
add_action( 'wp_playlist_scripts', 'wp_playlist_scripts' );
1158
1193
 
1159
1194
/**
1160
 
 * The playlist shortcode.
 
1195
 * Builds the Playlist shortcode output.
1161
1196
 *
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.
1213
1248
         *
1214
1249
         * @since 3.9.0
 
1250
         * @since 4.2.0 The `$instance` parameter was added.
1215
1251
         *
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.
1218
1255
         */
1219
 
        $output = apply_filters( 'post_playlist', '', $attr );
 
1256
        $output = apply_filters( 'post_playlist', '', $attr, $instance );
1220
1257
        if ( $output != '' ) {
1221
1258
                return $output;
1222
1259
        }
1401
1438
add_shortcode( 'playlist', 'wp_playlist_shortcode' );
1402
1439
 
1403
1440
/**
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.
1405
1442
 *
1406
1443
 * @since 3.6.0
1407
1444
 *
1408
 
 * @param string $url
1409
 
 * @return string Fallback HTML
 
1445
 * @param string $url The media element URL.
 
1446
 * @return string Fallback HTML.
1410
1447
 */
1411
1448
function wp_mediaelement_fallback( $url ) {
1412
1449
        /**
1421
1458
}
1422
1459
 
1423
1460
/**
1424
 
 * Return a filtered list of WP-supported audio formats.
 
1461
 * Returns a filtered list of WP-supported audio formats.
1425
1462
 *
1426
1463
 * @since 3.6.0
1427
 
 * @return array
 
1464
 *
 
1465
 * @return array Supported audio formats.
1428
1466
 */
1429
1467
function wp_get_audio_extensions() {
1430
1468
        /**
1439
1477
}
1440
1478
 
1441
1479
/**
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.
1443
1481
 *
1444
1482
 * @since 3.9.0
1445
1483
 *
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.
1449
1487
 */
1450
1488
function wp_get_attachment_id3_keys( $attachment, $context = 'display' ) {
1474
1512
        return apply_filters( 'wp_get_attachment_id3_keys', $fields, $attachment, $context );
1475
1513
}
1476
1514
/**
1477
 
 * The Audio shortcode.
 
1515
 * Builds the Audio shortcode output.
1478
1516
 *
1479
1517
 * This implements the functionality of the Audio Shortcode for displaying
1480
1518
 * WordPress mp3s in a post.
1481
1519
 *
1482
1520
 * @since 3.6.0
1483
1521
 *
1484
 
 * @param array $attr {
 
1522
 * @param array  $attr {
1485
1523
 *     Attributes of the audio shortcode.
1486
1524
 *
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%'.
1494
1532
 * }
1495
 
 * @param string $content Optional. Shortcode content.
 
1533
 * @param string $content Shortcode content.
1496
1534
 * @return string HTML content to display audio.
1497
1535
 */
1498
1536
function wp_audio_shortcode( $attr, $content = '' ) {
1499
1537
        $post_id = get_post() ? get_the_ID() : 0;
1500
1538
 
1501
 
        static $instances = 0;
1502
 
        $instances++;
 
1539
        static $instance = 0;
 
1540
        $instance++;
1503
1541
 
1504
1542
        /**
1505
1543
         * Filter the default audio shortcode output.
1508
1546
         *
1509
1547
         * @since 3.6.0
1510
1548
         *
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.
1515
1553
         */
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;
1519
1557
        }
1589
1627
         */
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'],
1609
1647
        }
1610
1648
 
1611
1649
        $html = '';
1612
 
        if ( 'mediaelement' === $library && 1 === $instances ) {
 
1650
        if ( 'mediaelement' === $library && 1 === $instance ) {
1613
1651
                $html .= "<!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->\n";
1614
1652
        }
1615
1653
        $html .= sprintf( '<audio %s controls="controls">', join( ' ', $attr_strings ) );
1622
1660
                                $fileurl = $atts[ $fallback ];
1623
1661
                        }
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 ) );
1627
1665
                }
1628
1666
        }
1648
1686
add_shortcode( 'audio', 'wp_audio_shortcode' );
1649
1687
 
1650
1688
/**
1651
 
 * Return a filtered list of WP-supported video formats
 
1689
 * Returns a filtered list of WP-supported video formats.
1652
1690
 *
1653
1691
 * @since 3.6.0
1654
 
 * @return array
 
1692
 *
 
1693
 * @return array List of supported video formats.
1655
1694
 */
1656
1695
function wp_get_video_extensions() {
1657
1696
        /**
1666
1705
}
1667
1706
 
1668
1707
/**
1669
 
 * The Video shortcode.
 
1708
 * Builds the Video shortcode output.
1670
1709
 *
1671
1710
 * This implements the functionality of the Video Shortcode for displaying
1672
1711
 * WordPress mp4s in a post.
1673
1712
 *
1674
1713
 * @since 3.6.0
1675
1714
 *
1676
 
 * @param array $attr {
 
1715
 * @param array  $attr {
1677
1716
 *     Attributes of the shortcode.
1678
1717
 *
1679
1718
 *     @type string $src      URL to the source of the video file. Default empty.
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}'.
1691
1730
 * }
1692
 
 * @param string $content Optional. Shortcode content.
 
1731
 * @param string $content Shortcode content.
1693
1732
 * @return string HTML content to display video.
1694
1733
 */
1695
1734
function wp_video_shortcode( $attr, $content = '' ) {
1696
1735
        global $content_width;
1697
1736
        $post_id = get_post() ? get_the_ID() : 0;
1698
1737
 
1699
 
        static $instances = 0;
1700
 
        $instances++;
 
1738
        static $instance = 0;
 
1739
        $instance++;
1701
1740
 
1702
1741
        /**
1703
1742
         * Filter the default video shortcode output.
1709
1748
         *
1710
1749
         * @see wp_video_shortcode()
1711
1750
         *
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.
1716
1755
         */
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;
1720
1759
        }
1752
1791
                }
1753
1792
        }
1754
1793
 
 
1794
        $is_vimeo = $is_youtube = false;
1755
1795
        $yt_pattern = '#^https?://(?:www\.)?(?:youtube\.com/watch|youtu\.be/)#';
 
1796
        $vimeo_pattern = '#^https?://(.+\.)?vimeo\.com/.*#';
1756
1797
 
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'] ) );
1763
1806
                        }
1764
1807
                }
 
1808
 
 
1809
                if ( $is_vimeo ) {
 
1810
                        wp_enqueue_script( 'froogaloop' );
 
1811
                }
 
1812
 
1765
1813
                $primary = true;
1766
1814
                array_unshift( $default_types, 'src' );
1767
1815
        } else {
1812
1860
         */
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'] ),
1834
1882
        }
1835
1883
 
1836
1884
        $html = '';
1837
 
        if ( 'mediaelement' === $library && 1 === $instances ) {
 
1885
        if ( 'mediaelement' === $library && 1 === $instance ) {
1838
1886
                $html .= "<!--[if lt IE 9]><script>document.createElement('video');</script><![endif]-->\n";
1839
1887
        }
1840
1888
        $html .= sprintf( '<video %s controls="controls">', join( ' ', $attr_strings ) );
1846
1894
                        if ( empty( $fileurl ) ) {
1847
1895
                                $fileurl = $atts[ $fallback ];
1848
1896
                        }
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' );
1851
1901
                        } else {
1852
1902
                                $type = wp_check_filetype( $atts[ $fallback ], wp_get_mime_types() );
1853
1903
                        }
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 ) );
1856
1906
                }
1857
1907
        }
1890
1940
add_shortcode( 'video', 'wp_video_shortcode' );
1891
1941
 
1892
1942
/**
1893
 
 * Display previous image link that has the same post parent.
 
1943
 * Displays previous image link that has the same post parent.
1894
1944
 *
1895
1945
 * @since 2.5.0
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.
 
1946
 *
 
1947
 * @see adjacent_image_link()
 
1948
 *
 
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.
1899
1953
 */
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);
1902
1956
}
1903
1957
 
1904
1958
/**
1905
 
 * Display next image link that has the same post parent.
 
1959
 * Displays next image link that has the same post parent.
1906
1960
 *
1907
1961
 * @since 2.5.0
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.
 
1962
 *
 
1963
 * @see adjacent_image_link()
 
1964
 *
 
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.
1911
1969
 */
1912
1970
function next_image_link($size = 'thumbnail', $text = false) {
1913
1971
        adjacent_image_link(false, $size, $text);
1914
1972
}
1915
1973
 
1916
1974
/**
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.
1918
1976
 *
1919
1977
 * Retrieves the current attachment object from the $post global.
1920
1978
 *
1921
1979
 * @since 2.5.0
1922
1980
 *
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.
1924
1986
 */
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' ) ) );
1928
1990
 
1963
2025
}
1964
2026
 
1965
2027
/**
1966
 
 * Retrieve taxonomies attached to the attachment.
 
2028
 * Retrieves taxonomies attached to given the attachment.
1967
2029
 *
1968
2030
 * @since 2.5.0
1969
2031
 *
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.
1972
2034
 */
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;
1978
 
 
 
2040
        }
1979
2041
        if ( ! is_object($attachment) )
1980
2042
                return array();
1981
2043
 
2002
2064
}
2003
2065
 
2004
2066
/**
2005
 
 * Return all of the taxonomy names that are registered for attachments.
 
2067
 * Retrieves all of the taxonomy names that are registered for attachments.
2006
2068
 *
2007
2069
 * Handles mime-type-specific taxonomies such as attachment:image and attachment:video.
2008
2070
 *
2009
2071
 * @since 3.5.0
2010
 
 * @see get_attachment_taxonomies()
2011
 
 *
2012
 
 * @param string $output The type of output to return, either taxonomy 'names' or 'objects'. 'names' is the default.
 
2072
 *
 
2073
 * @see get_taxonomies()
 
2074
 *
 
2075
 * @param string $output Optional. The type of taxonomy output to return. Accepts 'names' or 'objects'.
 
2076
 *                       Default 'names'.
2013
2077
 * @return array The names of all taxonomy of $object_type.
2014
2078
 */
2015
2079
function get_taxonomies_for_attachments( $output = 'names' ) {
2031
2095
 
2032
2096
/**
2033
2097
 * Create new GD image resource with transparency support
2034
 
 * @TODO: Deprecate if possible.
 
2098
 *
 
2099
 * @todo: Deprecate if possible.
2035
2100
 *
2036
2101
 * @since 2.9.0
2037
2102
 *
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.
2041
2106
 */
2042
2107
function wp_imagecreatetruecolor($width, $height) {
2043
2108
        $img = imagecreatetruecolor($width, $height);
2049
2114
}
2050
2115
 
2051
2116
/**
2052
 
 * Register an embed handler. This function should probably only be used for sites that do not support oEmbed.
 
2117
 * Registers an embed handler.
 
2118
 *
 
2119
 * Should probably only be used for sites that do not support oEmbed.
2053
2120
 *
2054
2121
 * @since 2.9.0
 
2122
 *
2055
2123
 * @see WP_Embed::register_handler()
2056
2124
 *
2057
 
 * @global WP_Embed $wp_embed
2058
 
 * @param string   $id
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.
2062
2130
 */
2063
2131
function wp_embed_register_handler( $id, $regex, $callback, $priority = 10 ) {
2064
2132
        global $wp_embed;
2066
2134
}
2067
2135
 
2068
2136
/**
2069
 
 * Unregister a previously registered embed handler.
 
2137
 * Unregisters a previously-registered embed handler.
2070
2138
 *
2071
2139
 * @since 2.9.0
 
2140
 *
2072
2141
 * @see WP_Embed::unregister_handler()
2073
2142
 *
2074
 
 * @global WP_Embed $wp_embed
2075
 
 * @param string $id
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.
2077
2145
 */
2078
2146
function wp_embed_unregister_handler( $id, $priority = 10 ) {
2079
2147
        global $wp_embed;
2122
2190
 *
2123
2191
 * @since 2.9.0
2124
2192
 *
2125
 
 * @param int $example_width The width of an example embed.
 
2193
 * @see wp_constrain_dimensions()
 
2194
 *
 
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.
2130
2200
 */
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.
2142
2212
 *
2143
2213
 * @since 2.9.0
 
2214
 *
2144
2215
 * @see WP_oEmbed
2145
2216
 *
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.
 
2219
 *                     Default empty.
2148
2220
 * @return false|string False on failure or the embed HTML on success.
2149
2221
 */
2150
2222
function wp_oembed_get( $url, $args = '' ) {
2157
2229
 * Adds a URL format and oEmbed provider URL pair.
2158
2230
 *
2159
2231
 * @since 2.9.0
 
2232
 *
2160
2233
 * @see WP_oEmbed
2161
2234
 *
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
 
2236
 *                          as wildcards.
 
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.
2165
2239
 */
2166
2240
function wp_oembed_add_provider( $format, $provider, $regex = false ) {
2167
2241
        require_once( ABSPATH . WPINC . '/class-oembed.php' );
2178
2252
 * Removes an oEmbed provider.
2179
2253
 *
2180
2254
 * @since 3.5.0
 
2255
 *
2181
2256
 * @see WP_oEmbed
2182
2257
 *
2183
2258
 * @param string $format The URL format for the oEmbed provider to remove.
 
2259
 * @return bool Was the provider removed successfully?
2184
2260
 */
2185
2261
function wp_oembed_remove_provider( $format ) {
2186
2262
        require_once( ABSPATH . WPINC . '/class-oembed.php' );
2206
2282
 * it hasn't, then it will load the embeds library.
2207
2283
 *
2208
2284
 * @since 2.9.0
 
2285
 *
 
2286
 * @see wp_embed_register_handler()
2209
2287
 */
2210
2288
function wp_maybe_load_embeds() {
2211
2289
        /**
2245
2323
}
2246
2324
 
2247
2325
/**
2248
 
 * The Google Video embed handler callback. Google Video does not support oEmbed.
 
2326
 * The Google Video embed handler callback.
 
2327
 *
 
2328
 * Google Video does not support oEmbed.
2249
2329
 *
2250
2330
 * @see WP_Embed::register_handler()
2251
2331
 * @see WP_Embed::shortcode()
2252
2332
 *
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.
2258
2338
 */
2259
2339
function wp_embed_handler_googlevideo( $matches, $attr, $url, $rawattr ) {
2271
2351
         * @since 2.9.0
2272
2352
         *
2273
2353
         * @param string $html    Google Video HTML embed markup.
2274
 
         * @param array  $matches The regex matches from the provided regex.
 
2354
         * @param array  $matches The RegEx matches from the provided regex.
2275
2355
         * @param array  $attr    An array of embed attributes.
2276
2356
         * @param string $url     The original URL that was matched by the regex.
2277
2357
         * @param array  $rawattr The original unmodified attributes.
2280
2360
}
2281
2361
 
2282
2362
/**
2283
 
 * YouTube embed handler callback.
 
2363
 * YouTube iframe embed handler callback.
2284
2364
 *
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.
2286
2366
 *
2287
2367
 * @since 4.0.0
2288
2368
 *
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.
2296
2376
function wp_embed_handler_youtube( $matches, $attr, $url, $rawattr ) {
2297
2377
        global $wp_embed;
2298
2378
        $embed = $wp_embed->autoembed( "https://youtube.com/watch?v={$matches[2]}" );
 
2379
 
2299
2380
        /**
2300
2381
         * Filter the YoutTube embed output.
2301
2382
         *
2316
2397
 *
2317
2398
 * @since 3.6.0
2318
2399
 *
2319
 
 * @param array $matches The regex matches from the provided regex when calling {@link wp_embed_register_handler()}.
 
2400
 * @param array $matches The RegEx matches from the provided regex when calling wp_embed_register_handler().
2320
2401
 * @param array $attr Embed attributes.
2321
2402
 * @param string $url The original URL that was matched by the regex.
2322
2403
 * @param array $rawattr The original unmodified attributes.
2343
2424
 *
2344
2425
 * @since 3.6.0
2345
2426
 *
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.
2351
2432
 */
2352
2433
function wp_embed_handler_video( $matches, $attr, $url, $rawattr ) {
2391
2472
}
2392
2473
 
2393
2474
/**
2394
 
 * Determine the maximum upload size allowed in php.ini.
 
2475
 * Determines the maximum upload size allowed in php.ini.
2395
2476
 *
2396
2477
 * @since 2.5.0
2397
2478
 *
2417
2498
 * Returns a WP_Image_Editor instance and loads file into it.
2418
2499
 *
2419
2500
 * @since 3.5.0
2420
 
 * @access public
2421
2501
 *
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
 
2506
 *                                  object otherwise.
2425
2507
 */
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.
2455
2537
 *
2456
2538
 * @since 3.5.0
2457
 
 * @access public
2458
2539
 *
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.
2461
2543
 */
2462
2544
function wp_image_editor_supports( $args = array() ) {
2463
2545
        return (bool) _wp_image_editor_choose( $args );
2466
2548
/**
2467
2549
 * Tests which editors are capable of supporting the request.
2468
2550
 *
 
2551
 * @ignore
2469
2552
 * @since 3.5.0
2470
 
 * @access private
2471
2553
 *
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.
2474
2557
 */
2475
2558
function _wp_image_editor_choose( $args = array() ) {
2476
2559
        require_once ABSPATH . WPINC . '/class-wp-image-editor.php';
2582
2665
 
2583
2666
        $wp_scripts->add_data( 'wp-plupload', 'data', $script );
2584
2667
}
2585
 
add_action( 'customize_controls_enqueue_scripts', 'wp_plupload_default_settings' );
2586
2668
 
2587
2669
/**
2588
2670
 * Prepares an attachment post object for JS, where it is expected
2783
2865
 * all media JS APIs.
2784
2866
 *
2785
2867
 * @since 3.5.0
 
2868
 *
 
2869
 * @param array $args {
 
2870
 *     Arguments for enqueuing media scripts.
 
2871
 *
 
2872
 *     @type int|WP_Post A post object or ID.
 
2873
 * }
 
2874
 * @return array List of media view settings.
2786
2875
 */
2787
2876
function wp_enqueue_media( $args = array() ) {
2788
2877
 
2887
2976
 
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' );
2894
2983
                        }
2895
2984
                }
2918
3007
                   lack of plural support here, turn it into "selected: %d" then translate it.
2919
3008
                 */
2920
3009
                'selected'    => __( '%d selected' ),
2921
 
                'dragInfo'    => __( 'Drag and drop to reorder images.' ),
 
3010
                'dragInfo'    => __( 'Drag and drop to reorder media files.' ),
2922
3011
 
2923
3012
                // Upload
2924
3013
                'uploadFilesTitle'  => __( 'Upload Files' ),
3074
3163
}
3075
3164
 
3076
3165
/**
3077
 
 * Retrieve media attached to the passed post.
 
3166
 * Retrieves media attached to the passed post.
3078
3167
 *
3079
3168
 * @since 3.6.0
3080
3169
 *
3126
3215
 * @since 3.6.0
3127
3216
 *
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.
3131
3220
 */
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' );
 
3223
 
 
3224
        /**
 
3225
         * Filter the embedded media types that are allowed to be returned from the content blob.
 
3226
         *
 
3227
         * @since 4.2.0
 
3228
         *
 
3229
         * @param array $allowed_media_types An array of allowed media types. Default media types are
 
3230
         *                                   'audio', 'video', 'object', 'embed', and 'iframe'.
 
3231
         */
 
3232
        $allowed_media_types = apply_filters( 'media_embedded_in_content_allowed_types', array( 'audio', 'video', 'object', 'embed', 'iframe' ) );
 
3233
 
3135
3234
        if ( ! empty( $types ) ) {
3136
 
                if ( ! is_array( $types ) )
 
3235
                if ( ! is_array( $types ) ) {
3137
3236
                        $types = array( $types );
 
3237
                }
 
3238
 
3138
3239
                $allowed_media_types = array_intersect( $allowed_media_types, $types );
3139
3240
        }
3140
3241
 
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 );
 
3243
 
 
3244
        if ( preg_match_all( '#<(?P<tag>' . $tags . ')[^<]*?(?:>[\s\S]*?<\/(?P=tag)>|\s*\/>)#', $content, $matches ) ) {
 
3245
                foreach ( $matches[0] as $match ) {
 
3246
                        $html[] = $match;
3144
3247
                }
3145
3248
        }
3146
3249
 
3148
3251
}
3149
3252
 
3150
3253
/**
3151
 
 * Retrieve galleries from the passed post's content.
 
3254
 * Retrieves galleries from the passed post's content.
3152
3255
 *
3153
3256
 * @since 3.6.0
3154
3257
 *
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.
3159
3262
 */
3160
3263
function get_post_galleries( $post, $html = true ) {
3161
3264
        if ( ! $post = get_post( $post ) )
3205
3308
 * @since 3.6.0
3206
3309
 *
3207
3310
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
3208
 
 * @param bool        $html Whether to return HTML or data.
 
3311
 * @param bool        $html Optional. Whether to return HTML or data. Default is true.
3209
3312
 * @return string|array Gallery data and srcs parsed from the expanded shortcode.
3210
3313
 */
3211
3314
function get_post_gallery( $post = 0, $html = true ) {
3229
3332
 *
3230
3333
 * @since 3.6.0
3231
3334
 *
3232
 
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
 
3335
 * @see get_post_galleries()
 
3336
 *
 
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
3235
3340
 */
3236
3341
function get_post_galleries_images( $post = 0 ) {
3237
3342
        $galleries = get_post_galleries( $post, false );
3239
3344
}
3240
3345
 
3241
3346
/**
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
3243
3348
 *
3244
3349
 * @since 3.6.0
3245
3350
 *
3246
 
 * @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
 
3351
 * @see get_post_gallery()
 
3352
 *
 
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.
3248
3355
 */
3249
3356
function get_post_gallery_images( $post = 0 ) {
3252
3359
}
3253
3360
 
3254
3361
/**
3255
 
 * Maybe attempt to generate attachment metadata, if missing.
 
3362
 * Maybe attempts to generate attachment metadata, if missing.
3256
3363
 *
3257
3364
 * @since 3.9.0
3258
3365
 *
3277
3384
}
3278
3385
 
3279
3386
/**
3280
 
 * Try to convert an attachment URL into a post ID.
 
3387
 * Tries to convert an attachment URL into a post ID.
3281
3388
 *
3282
3389
 * @since 4.0.0
3283
3390
 *
3284
3391
 * @global wpdb $wpdb WordPress database abstraction object.
3285
3392
 *
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.
3288
3395
 */
3289
3396
function attachment_url_to_postid( $url ) {
3290
3397
        global $wpdb;
3301
3408
                $path
3302
3409
        );
3303
3410
        $post_id = $wpdb->get_var( $sql );
3304
 
        if ( ! empty( $post_id ) ) {
3305
 
                return (int) $post_id;
3306
 
        }
 
3411
 
 
3412
        /**
 
3413
         * Filter an attachment id found by URL.
 
3414
         *
 
3415
         * @since 4.2.0
 
3416
         *
 
3417
         * @param int|null $post_id The post_id (if any) found by the function.
 
3418
         * @param string   $url     The URL being looked up.
 
3419
         */
 
3420
        $post_id = apply_filters( 'attachment_url_to_postid', $post_id, $url );
 
3421
 
 
3422
        return (int) $post_id;
3307
3423
}
3308
3424
 
3309
3425
/**
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.
3311
3427
 *
3312
3428
 * @since 4.0.0
3313
3429
 *