| 806 | * Retrieve all attachment posts with mime-type |
| 807 | * |
| 808 | */ |
| 809 | function wp_get_attached_audio() { |
| 810 | |
| 811 | } |
| 812 | |
| 813 | /** |
| 814 | * The Audio shortcode. |
| 815 | * |
| 816 | * This implements the functionality of the Audio Shortcode for displaying |
| 817 | * WordPress mp3s in a post. |
| 818 | * |
| 819 | * @since 3.6.0 |
| 820 | * |
| 821 | * @param array $attr Attributes of the shortcode. |
| 822 | * @return string HTML content to display audio. |
| 823 | */ |
| 824 | function wp_audio_shortcode( $attr ) { |
| 825 | global $content_width; |
| 826 | $post = get_post(); |
| 827 | |
| 828 | static $instances = 0; |
| 829 | $instances++; |
| 830 | |
| 831 | $audio = null; |
| 832 | |
| 833 | extract( shortcode_atts( array( 'src' => '' ), $attr ) ); |
| 834 | |
| 835 | if ( empty( $src ) ) { |
| 836 | $children = get_children( array( |
| 837 | 'post_parent' => $post->ID, |
| 838 | 'post_type' => 'attachment', |
| 839 | 'post_mime_type' => 'audio', |
| 840 | 'posts_per_page' => 1 |
| 841 | ) ); |
| 842 | |
| 843 | if ( empty( $children ) ) |
| 844 | return; |
| 845 | |
| 846 | $audio = reset( $children ); |
| 847 | $src = wp_get_attachment_url( $audio->ID ); |
| 848 | if ( empty( $src ) ) |
| 849 | return; |
| 850 | } |
| 851 | |
| 852 | wp_enqueue_style( 'wp-mediaelement' ); |
| 853 | wp_enqueue_script( 'wp-mediaelement' ); |
| 854 | |
| 855 | $html = sprintf( '<audio class="%s" id="%s" src="%s" type="audio/mp3" controls="controls"></audio>', |
| 856 | apply_filters( 'audio_shortcode_class', 'wp-audio-shortcode' ), |
| 857 | sprintf( 'audio-%d-%d', $post->ID, $instances ), |
| 858 | esc_url( $src ) |
| 859 | ); |
| 860 | |
| 861 | return apply_filters( 'audio_shortcode', $html, $src, $audio, $post ); |
| 862 | } |
| 863 | add_shortcode( 'audio', 'wp_audio_shortcode' ); |
| 864 | |
| 865 | /** |
| 866 | * The Video shortcode. |
| 867 | * |
| 868 | * This implements the functionality of the Video Shortcode for displaying |
| 869 | * WordPress mp4s in a post. |
| 870 | * |
| 871 | * @since 3.6.0 |
| 872 | * |
| 873 | * @param array $attr Attributes of the shortcode. |
| 874 | * @return string HTML content to display video. |
| 875 | */ |
| 876 | function wp_video_shortcode( $attr ) { |
| 877 | global $content_width; |
| 878 | $post = get_post(); |
| 879 | |
| 880 | static $instances = 0; |
| 881 | $instances++; |
| 882 | |
| 883 | $video = null; |
| 884 | |
| 885 | extract( shortcode_atts( array( |
| 886 | 'src' => '', |
| 887 | 'width' => empty( $content_width ) ? 640 : $content_width, |
| 888 | 'height' => 360 |
| 889 | ), $attr ) ); |
| 890 | |
| 891 | if ( empty( $src ) ) { |
| 892 | $children = get_children( array( |
| 893 | 'post_parent' => $post->ID, |
| 894 | 'post_type' => 'attachment', |
| 895 | 'post_mime_type' => 'video', |
| 896 | 'posts_per_page' => 1 |
| 897 | ) ); |
| 898 | |
| 899 | if ( empty( $children ) ) |
| 900 | return; |
| 901 | |
| 902 | $video = reset( $children ); |
| 903 | $src = wp_get_attachment_url( $video->ID ); |
| 904 | if ( empty( $src ) ) |
| 905 | return; |
| 906 | } |
| 907 | |
| 908 | wp_enqueue_style( 'wp-mediaelement' ); |
| 909 | wp_enqueue_script( 'wp-mediaelement' ); |
| 910 | |
| 911 | $html = sprintf( '<video class="%s" id="%s" width="%d" height="%d" src="%s" type="video/mp4" controls="controls" preload="none"></video>', |
| 912 | apply_filters( 'video_shortcode_class', 'wp-video-shortcode' ), |
| 913 | sprintf( 'video-%d-%d', $post->ID, $instances ), |
| 914 | $width, |
| 915 | $height, |
| 916 | esc_url( $src ) |
| 917 | ); |
| 918 | |
| 919 | return apply_filters( 'video_shortcode', $html, $src, $video, $post ); |
| 920 | } |
| 921 | add_shortcode( 'video', 'wp_video_shortcode' ); |
| 922 | |
| 923 | /** |