diff --git wp-includes/media.php wp-includes/media.php
index 9b5d6a8..b69fb4f 100644
|
|
|
function wp_get_audio_extensions() {
|
| 839 | 839 | /** |
| 840 | 840 | * The Audio shortcode. |
| 841 | 841 | * |
| 842 | 842 | * This implements the functionality of the Audio Shortcode for displaying |
| 843 | 843 | * WordPress mp3s in a post. |
| 844 | 844 | * |
| 845 | 845 | * @since 3.6.0 |
| 846 | 846 | * |
| 847 | 847 | * @param array $attr Attributes of the shortcode. |
| 848 | 848 | * @return string HTML content to display audio. |
| 849 | 849 | */ |
| 850 | 850 | function wp_audio_shortcode( $attr ) { |
| 851 | 851 | $post_id = get_post() ? get_the_ID() : 0; |
| 852 | 852 | |
| 853 | 853 | static $instances = 0; |
| 854 | 854 | $instances++; |
| 855 | 855 | |
| 856 | 856 | $audio = null; |
| 857 | 857 | |
| 858 | 858 | $default_types = wp_get_audio_extensions(); |
| 859 | | $defaults_atts = array( 'src' => '' ); |
| | 859 | $defaults_atts = array( |
| | 860 | 'src' => '', |
| | 861 | 'loop' => '', |
| | 862 | 'autoplay' => '', |
| | 863 | 'preload' => 'none' |
| | 864 | ); |
| 860 | 865 | foreach ( $default_types as $type ) |
| 861 | 866 | $defaults_atts[$type] = ''; |
| 862 | 867 | |
| 863 | 868 | $atts = shortcode_atts( $defaults_atts, $attr, 'audio' ); |
| 864 | 869 | extract( $atts ); |
| 865 | 870 | |
| 866 | 871 | $primary = false; |
| 867 | 872 | if ( ! empty( $src ) ) { |
| 868 | 873 | $type = wp_check_filetype( $src ); |
| 869 | 874 | if ( ! in_array( $type['ext'], $default_types ) ) |
| 870 | 875 | return sprintf( '<a class="wp-post-format-link-audio" href="%s">%s</a>', esc_url( $src ), esc_html( $src ) ); |
| 871 | 876 | $primary = true; |
| 872 | 877 | array_unshift( $default_types, 'src' ); |
| 873 | 878 | } else { |
| 874 | 879 | foreach ( $default_types as $ext ) { |
| 875 | 880 | if ( ! empty( $$ext ) ) { |
| 876 | 881 | $type = wp_check_filetype( $$ext ); |
| 877 | 882 | if ( $type['ext'] === $ext ) |
| 878 | 883 | $primary = true; |
| 879 | 884 | } |
| … |
… |
function wp_audio_shortcode( $attr ) {
|
| 883 | 888 | if ( ! $primary ) { |
| 884 | 889 | $audios = get_attached_media( 'audio', $post_id ); |
| 885 | 890 | if ( empty( $audios ) ) |
| 886 | 891 | return; |
| 887 | 892 | |
| 888 | 893 | $audio = reset( $audios ); |
| 889 | 894 | $src = wp_get_attachment_url( $audio->ID ); |
| 890 | 895 | if ( empty( $src ) ) |
| 891 | 896 | return; |
| 892 | 897 | |
| 893 | 898 | array_unshift( $default_types, 'src' ); |
| 894 | 899 | } |
| 895 | 900 | |
| 896 | 901 | $library = apply_filters( 'wp_audio_shortcode_library', 'mediaelement' ); |
| 897 | 902 | if ( 'mediaelement' === $library && did_action( 'init' ) ) { |
| 898 | 903 | wp_enqueue_style( 'wp-mediaelement' ); |
| 899 | 904 | wp_enqueue_script( 'wp-mediaelement' ); |
| 900 | 905 | } |
| 901 | 906 | |
| 902 | 907 | $atts = array( |
| 903 | | sprintf( 'class="%s"', apply_filters( 'wp_audio_shortcode_class', 'wp-audio-shortcode' ) ), |
| 904 | | sprintf( 'id="audio-%d-%d"', $post_id, $instances ), |
| | 908 | 'class' => apply_filters( 'wp_audio_shortcode_class', 'wp-audio-shortcode' ), |
| | 909 | 'id' => sprintf( 'audio-%d-%d', $post_id, $instances ), |
| | 910 | 'loop' => $loop, |
| | 911 | 'autoplay' => $autoplay, |
| | 912 | 'preload' => $preload, |
| 905 | 913 | ); |
| 906 | 914 | |
| 907 | | $html = sprintf( '<audio %s controls="controls" preload="none">', join( ' ', $atts ) ); |
| | 915 | // These ones should just be omitted altogether if they are blank |
| | 916 | foreach ( array( 'loop', 'autoplay', 'preload' ) as $a ) { |
| | 917 | if ( empty( $atts[$a] ) ) |
| | 918 | unset( $atts[$a] ); |
| | 919 | } |
| | 920 | |
| | 921 | $attr_strings = []; |
| | 922 | foreach ( $atts as $k => $v ) { |
| | 923 | $attr_strings[] = $k . '="' . esc_attr( $v ) . '"'; |
| | 924 | } |
| | 925 | |
| | 926 | $html = sprintf( '<audio %s controls="controls" preload="none">', join( ' ', $attr_strings ) ); |
| 908 | 927 | |
| 909 | 928 | $fileurl = ''; |
| 910 | 929 | $source = '<source type="%s" src="%s" />'; |
| 911 | 930 | foreach ( $default_types as $fallback ) { |
| 912 | 931 | if ( ! empty( $$fallback ) ) { |
| 913 | 932 | if ( empty( $fileurl ) ) |
| 914 | 933 | $fileurl = $$fallback; |
| 915 | 934 | $type = wp_check_filetype( $$fallback ); |
| 916 | 935 | $html .= sprintf( $source, $type['type'], esc_url( $$fallback ) ); |
| 917 | 936 | } |
| 918 | 937 | } |
| 919 | 938 | |
| 920 | 939 | if ( 'mediaelement' === $library ) |
| 921 | 940 | $html .= wp_mediaelement_fallback( $fileurl ); |
| 922 | 941 | $html .= '</audio>'; |
| 923 | 942 | |
| 924 | 943 | return apply_filters( 'wp_audio_shortcode', $html, $atts, $audio, $post_id ); |
| 925 | 944 | } |
| 926 | 945 | add_shortcode( 'audio', apply_filters( 'wp_audio_shortcode_handler', 'wp_audio_shortcode' ) ); |
| 927 | 946 | |
| … |
… |
function wp_get_video_extensions() {
|
| 940 | 959 | * |
| 941 | 960 | * This implements the functionality of the Video Shortcode for displaying |
| 942 | 961 | * WordPress mp4s in a post. |
| 943 | 962 | * |
| 944 | 963 | * @since 3.6.0 |
| 945 | 964 | * |
| 946 | 965 | * @param array $attr Attributes of the shortcode. |
| 947 | 966 | * @return string HTML content to display video. |
| 948 | 967 | */ |
| 949 | 968 | function wp_video_shortcode( $attr ) { |
| 950 | 969 | global $content_width; |
| 951 | 970 | $post_id = get_post() ? get_the_ID() : 0; |
| 952 | 971 | |
| 953 | 972 | static $instances = 0; |
| 954 | 973 | $instances++; |
| 955 | 974 | |
| 956 | 975 | $video = null; |
| 957 | 976 | |
| 958 | 977 | $default_types = wp_get_video_extensions(); |
| 959 | 978 | $defaults_atts = array( |
| 960 | | 'src' => '', |
| 961 | | 'poster' => '', |
| 962 | | 'height' => 360, |
| 963 | | 'width' => empty( $content_width ) ? 640 : $content_width, |
| | 979 | 'src' => '', |
| | 980 | 'poster' => '', |
| | 981 | 'loop' => '', |
| | 982 | 'autoplay' => '', |
| | 983 | 'preload' => 'metadata', |
| | 984 | 'height' => 360, |
| | 985 | 'width' => empty( $content_width ) ? 640 : $content_width, |
| 964 | 986 | ); |
| 965 | 987 | |
| 966 | 988 | foreach ( $default_types as $type ) |
| 967 | 989 | $defaults_atts[$type] = ''; |
| 968 | 990 | |
| 969 | 991 | $atts = shortcode_atts( $defaults_atts, $attr, 'video' ); |
| 970 | 992 | extract( $atts ); |
| 971 | 993 | |
| 972 | 994 | $w = $width; |
| 973 | 995 | $h = $height; |
| 974 | 996 | if ( is_admin() && $width > 600 ) |
| 975 | 997 | $w = 600; |
| 976 | 998 | elseif ( ! is_admin() && $w > $defaults_atts['width'] ) |
| 977 | 999 | $w = $defaults_atts['width']; |
| 978 | 1000 | |
| 979 | 1001 | if ( $w < $width ) |
| 980 | 1002 | $height = round( ( $h * $w ) / $width ); |
| 981 | 1003 | |
| 982 | 1004 | $width = $w; |
| 983 | 1005 | |
| … |
… |
function wp_video_shortcode( $attr ) {
|
| 1001 | 1023 | if ( ! $primary ) { |
| 1002 | 1024 | $videos = get_attached_media( 'video', $post_id ); |
| 1003 | 1025 | if ( empty( $videos ) ) |
| 1004 | 1026 | return; |
| 1005 | 1027 | |
| 1006 | 1028 | $video = reset( $videos ); |
| 1007 | 1029 | $src = wp_get_attachment_url( $video->ID ); |
| 1008 | 1030 | if ( empty( $src ) ) |
| 1009 | 1031 | return; |
| 1010 | 1032 | |
| 1011 | 1033 | array_unshift( $default_types, 'src' ); |
| 1012 | 1034 | } |
| 1013 | 1035 | |
| 1014 | 1036 | $library = apply_filters( 'wp_video_shortcode_library', 'mediaelement' ); |
| 1015 | 1037 | if ( 'mediaelement' === $library && did_action( 'init' ) ) { |
| 1016 | 1038 | wp_enqueue_style( 'wp-mediaelement' ); |
| 1017 | 1039 | wp_enqueue_script( 'wp-mediaelement' ); |
| 1018 | 1040 | } |
| 1019 | 1041 | |
| 1020 | 1042 | $atts = array( |
| 1021 | | sprintf( 'class="%s"', apply_filters( 'wp_video_shortcode_class', 'wp-video-shortcode' ) ), |
| 1022 | | sprintf( 'id="video-%d-%d"', $post_id, $instances ), |
| 1023 | | sprintf( 'width="%d"', $width ), |
| 1024 | | sprintf( 'height="%d"', $height ), |
| | 1043 | 'class' => apply_filters( 'wp_video_shortcode_class', 'wp-video-shortcode' ), |
| | 1044 | 'id' => sprintf( 'video-%d-%d', $post_id, $instances ), |
| | 1045 | 'width' => absint( $width ), |
| | 1046 | 'height' => absint( $height ), |
| | 1047 | 'poster' => esc_url( $poster ), |
| | 1048 | 'loop' => $loop, |
| | 1049 | 'autoplay' => $autoplay, |
| | 1050 | 'preload' => $preload, |
| 1025 | 1051 | ); |
| 1026 | 1052 | |
| 1027 | | if ( ! empty( $poster ) ) |
| 1028 | | $atts[] = sprintf( 'poster="%s"', esc_url( $poster ) ); |
| | 1053 | // These ones should just be omitted altogether if they are blank |
| | 1054 | foreach ( array( 'poster', 'loop', 'autoplay', 'preload' ) as $a ) { |
| | 1055 | if ( empty( $atts[$a] ) ) |
| | 1056 | unset( $atts[$a] ); |
| | 1057 | } |
| | 1058 | |
| | 1059 | $attr_strings = []; |
| | 1060 | foreach ( $atts as $k => $v ) { |
| | 1061 | $attr_strings[] = $k . '="' . esc_attr( $v ) . '"'; |
| | 1062 | } |
| 1029 | 1063 | |
| 1030 | | $html = sprintf( '<video %s controls="controls" preload="none">', join( ' ', $atts ) ); |
| | 1064 | $html = sprintf( '<video %s controls="controls">', join( ' ', $attr_strings ) ); |
| 1031 | 1065 | |
| 1032 | 1066 | $fileurl = ''; |
| 1033 | 1067 | $source = '<source type="%s" src="%s" />'; |
| 1034 | 1068 | foreach ( $default_types as $fallback ) { |
| 1035 | 1069 | if ( ! empty( $$fallback ) ) { |
| 1036 | 1070 | if ( empty( $fileurl ) ) |
| 1037 | 1071 | $fileurl = $$fallback; |
| 1038 | 1072 | $type = wp_check_filetype( $$fallback ); |
| 1039 | 1073 | // m4v sometimes shows up as video/mpeg which collides with mp4 |
| 1040 | 1074 | if ( 'm4v' === $type['ext'] ) |
| 1041 | 1075 | $type['type'] = 'video/m4v'; |
| 1042 | 1076 | $html .= sprintf( $source, $type['type'], esc_url( $$fallback ) ); |
| 1043 | 1077 | } |
| 1044 | 1078 | } |
| 1045 | 1079 | if ( 'mediaelement' === $library ) |
| 1046 | 1080 | $html .= wp_mediaelement_fallback( $fileurl ); |
| 1047 | 1081 | $html .= '</video>'; |
| 1048 | 1082 | |
| | 1083 | $html = sprintf( '<div style="width: %dpx; max-width: 100%%;">%s</div>', $width, $html ); |
| 1049 | 1084 | return apply_filters( 'wp_video_shortcode', $html, $atts, $video, $post_id ); |
| 1050 | 1085 | } |
| 1051 | 1086 | add_shortcode( 'video', apply_filters( 'wp_video_shortcode_handler', 'wp_video_shortcode' ) ); |
| 1052 | 1087 | |
| 1053 | 1088 | /** |
| 1054 | 1089 | * Display previous image link that has the same post parent. |
| 1055 | 1090 | * |
| 1056 | 1091 | * @since 2.5.0 |
| 1057 | 1092 | * @param string $size Optional, default is 'thumbnail'. Size of image, either array or string. 0 or 'none' will default to post_title or $text; |
| 1058 | 1093 | * @param string $text Optional, default is false. If included, link will reflect $text variable. |
| 1059 | 1094 | * @return string HTML content. |
| 1060 | 1095 | */ |
| 1061 | 1096 | function previous_image_link($size = 'thumbnail', $text = false) { |
| 1062 | 1097 | adjacent_image_link(true, $size, $text); |
| 1063 | 1098 | } |
| 1064 | 1099 | |
| 1065 | 1100 | /** |
| 1066 | 1101 | * Display next image link that has the same post parent. |
| 1067 | 1102 | * |
| 1068 | 1103 | * @since 2.5.0 |