Make WordPress Core

Ticket #24202: 24202.5.diff

File 24202.5.diff, 13.5 KB (added by DrewAPicture, 13 years ago)

Refreshed at r24580

  • wp-content/themes/twentyeleven/functions.php

     
    644644        $images = array();
    645645
    646646        if ( function_exists( 'get_post_galleries' ) ) {
    647                 $galleries = get_post_galleries( get_the_ID(), false );
     647                $galleries = get_post_galleries( array(
     648                        'post_id' => get_the_ID(),
     649                        'html'    => false
     650                ) );
     651
    648652                if ( isset( $galleries[0]['ids'] ) )
    649653                        $images = explode( ',', $galleries[0]['ids'] );
    650654        } else {
  • wp-content/themes/twentyten/functions.php

     
    529529        $images = array();
    530530
    531531        if ( function_exists( 'get_post_galleries' ) ) {
    532                 $galleries = get_post_galleries( get_the_ID(), false );
     532                $galleries = get_post_galleries( array(
     533                        'post_id' => get_the_ID(),
     534                        'html'    => false
     535                ) );
     536
    533537                if ( isset( $galleries[0]['ids'] ) )
    534538                        $images = explode( ',', $galleries[0]['ids'] );
    535539        } else {
  • wp-includes/media.php

     
    18681868/**
    18691869 * Extract and parse {media type} shortcodes or srcs from the passed content
    18701870 *
     1871 * $args contents:
     1872 * - type   - Type of media: audio or video.
     1873 * - return - Whether to return HTML or URLs.
     1874 * - limit  - The number of medias to return.
     1875 *
    18711876 * @since 3.6.0
    18721877 *
    1873  * @param string $type Type of media: audio or video
    18741878 * @param string $content A string which might contain media data.
    1875  * @param boolean $html Whether to return HTML or URLs
    1876  * @param int $limit Optional. The number of medias to return
     1879 * @param array $args An array of arguments.
    18771880 * @return array A list of parsed shortcodes or extracted srcs
    18781881 */
    1879 function get_content_media( $type, $content, $html = true, $limit = 0 ) {
     1882function get_content_media( $content, $args ) {
     1883        $defaults = array(
     1884                'type'  => null,
     1885                'html'  => true,
     1886                'limit' => 0
     1887        );
     1888
     1889        $args = wp_parse_args( $args, $defaults );
     1890
     1891        if ( empty( $args['type'] ) )
     1892                return;
     1893
    18801894        $items = array();
    18811895
    18821896        if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {
    18831897                foreach ( $matches as $shortcode ) {
    1884                         if ( $type === $shortcode[2] ) {
     1898                        if ( $args['type'] === $shortcode[2] ) {
    18851899                                $count = 1;
    18861900
    18871901                                $items[] = do_shortcode_tag( $shortcode );
    1888                                 if ( $limit > 0 && count( $items ) >= $limit )
     1902                                if ( $args['limit'] > 0 && count( $items ) >= $args['limit'] )
    18891903                                        break;
    18901904                        }
    18911905                }
    18921906        }
    18931907
    1894         if ( $html )
     1908        if ( $args['html'] )
    18951909                return $items;
    18961910
    18971911        $data = array();
     
    19141928 * Check the content blob for an <{media type}>, <object>, <embed>, or <iframe>, in that order
    19151929 * If no HTML tag is found, check the first line of the post for a URL
    19161930 *
     1931 * $args contents:
     1932 * - type  - Type of media: audio or video.
     1933 * - limit - The number of medias to return.
     1934 *
    19171935 * @since 3.6.0
    19181936 *
    1919  * @param string $type Type of media: audio or video
    19201937 * @param string $content A string which might contain media data.
    1921  * @param int $limit Optional. The number of galleries to return
     1938 * @param array $args An array of arguments.
    19221939 * @return array A list of found HTML media embeds and possibly a URL by itself
    19231940 */
    1924 function get_embedded_media( $type, $content, $limit = 0 ) {
     1941function get_embedded_media( $content, $args ) {
     1942        $defaults = array(
     1943                'type'  => null,
     1944                'limit' => 0
     1945        );
     1946
     1947        $args = wp_parse_args( $args, $defaults );
     1948
     1949        if ( empty( $args['type'] ) )
     1950                return;
     1951
    19251952        $html = array();
    19261953
    1927         foreach ( array( $type, 'object', 'embed', 'iframe' ) as $tag ) {
     1954        foreach ( array( $args['type'], 'object', 'embed', 'iframe' ) as $tag ) {
    19281955                if ( preg_match( '#' . get_tag_regex( $tag ) . '#', $content, $matches ) ) {
    19291956                        $html[] = $matches[0];
    19301957
    1931                         if ( $limit > 0 && count( $html ) >= $limit )
     1958                        if ( $args['limit'] > 0 && count( $html ) >= $args['limit'] )
    19321959                                break;
    19331960                }
    19341961        }
    19351962
    1936         if ( ! empty( $html ) && count( $html ) >= $limit )
     1963        if ( ! empty( $html ) && count( $html ) >= $args['limit'] )
    19371964                return $html;
    19381965
    19391966        $lines = explode( "\n", trim( $content ) );
     
    19491976 *
    19501977 * @since 3.6.0
    19511978 *
     1979 * @uses get_content_media()
     1980 *
    19521981 * @param string $content A string which might contain audio data.
    1953  * @param boolean $html Whether to return HTML or URLs
     1982 * @param array $args (optional) An array of arguments.
    19541983 * @return array A list of lists. Each item has a list of HTML or srcs corresponding
    19551984 *              to an [audio]'s HTML or primary src and specified fallbacks
    19561985 */
    1957 function get_content_audio( $content, $html = true ) {
    1958         return get_content_media( 'audio', $content, $html );
     1986function get_content_audio( $content, $args = array() ) {
     1987        return get_content_media( $content, array_merge( $args, array( 'type' => 'audio' ) ) );
    19591988}
    19601989
    19611990/**
     
    19641993 *
    19651994 * @since 3.6.0
    19661995 *
     1996 * @uses get_embedded_media()
     1997 *
    19671998 * @param string $content A string which might contain audio data.
     1999 * @param array $args (optional) An array of arguments.
    19682000 * @return array A list of found HTML audio embeds and possibly a URL by itself
    19692001 */
    1970 function get_embedded_audio( $content ) {
    1971         return get_embedded_media( 'audio', $content );
     2002function get_embedded_audio( $content, $args = array() ) {
     2003        return get_embedded_media( $content, array_merge( $args, array( 'type' => 'audio' ) ) );
    19722004}
    19732005
    19742006/**
     
    19762008 *
    19772009 * @since 3.6.0
    19782010 *
     2011 * @uses get_content_media()
     2012 *
    19792013 * @param string $content A string which might contain video data.
    1980  * @param boolean $html Whether to return HTML or URLs
     2014 * @param array $args (optional) An array of arguments.
    19812015 * @return array A list of lists. Each item has a list of HTML or srcs corresponding
    19822016 *              to a [video]'s HTML or primary src and specified fallbacks
    19832017 */
    1984 function get_content_video( $content, $html = true ) {
    1985         return get_content_media( 'video', $content, $html );
     2018function get_content_video( $content, $args = array() ) {
     2019        return get_content_media( $content, array_merge( $args, array( 'type' => 'video' ) ) );
    19862020}
    19872021
    19882022/**
     
    19912025 *
    19922026 * @since 3.6.0
    19932027 *
     2028 * @uses get_embedded_media()
     2029 *
    19942030 * @param string $content A string which might contain video data.
     2031 * @param array $args (optional) An array of arguments.
    19952032 * @return array A list of found HTML video embeds and possibly a URL by itself
    19962033 */
    1997 function get_embedded_video( $content ) {
    1998         return get_embedded_media( 'video', $content );
     2034function get_embedded_video( $content, $args = array() ) {
     2035        return get_embedded_media( $content, array_merge( $args, array( 'type' => 'video' ) ) );
    19992036}
    20002037
    20012038/**
     
    20212058/**
    20222059 * Check the content blob for images or image srcs
    20232060 *
     2061 * $args contents:
     2062 * - html  - Whether to return HTML or URLs.
     2063 * - limit - The number of images to return.
     2064 *
    20242065 * @since 3.6.0
    20252066 *
    20262067 * @param string $content A string which might contain image data.
    2027  * @param boolean $html Whether to return HTML or URLs in the array
    2028  * @param int $limit Optional. The number of image srcs to return
     2068 * @param array $args An array of arguments.
    20292069 * @return array The found images or srcs
    20302070 */
    2031 function get_content_images( $content, $html = true, $limit = 0 ) {
     2071function get_content_images( $content, $args ) {
     2072        $defaults = array(
     2073                'html'  => true,
     2074                'limit' => 0
     2075        );
     2076
     2077        $args = wp_parse_args( $args, $defaults );
     2078
    20322079        $tags = array();
    20332080        $captions = array();
    20342081
     
    20362083                foreach ( $matches as $shortcode ) {
    20372084                        if ( 'caption' === $shortcode[2] ) {
    20382085                                $captions[] = $shortcode[0];
    2039                                 if ( $html )
     2086                                if ( $args['html'] )
    20402087                                        $tags[] = do_shortcode_tag( $shortcode );
    20412088                        }
    20422089
    2043                         if ( $limit > 0 && count( $tags ) >= $limit )
     2090                        if ( $args['limit'] > 0 && count( $tags ) >= $args['limit'] )
    20442091                                break;
    20452092                }
    20462093        }
     
    20632110                                if ( ! $found )
    20642111                                        $tags[] = $node[0];
    20652112
    2066                                 if ( $limit > 0 && count( $tags ) >= $limit )
     2113                                if ( $args['limit'] > 0 && count( $tags ) >= $args['limit'] )
    20672114                                        break 2;
    20682115                        }
    20692116                }
    20702117        }
    20712118
    2072         if ( $html )
     2119        if ( $args['html'] )
    20732120                return $tags;
    20742121
    20752122        $srcs = array();
     
    20782125                preg_match( '#src=([\'"])(.+?)\1#is', $tag, $src );
    20792126                if ( ! empty( $src[2] ) ) {
    20802127                        $srcs[] = $src[2];
    2081                         if ( $limit > 0 && count( $srcs ) >= $limit )
     2128                        if ( $args['limit'] > 0 && count( $srcs ) >= $args['limit'] )
    20822129                                break;
    20832130                }
    20842131        }
     
    20922139 * @since 3.6.0
    20932140 *
    20942141 * @param string $content A string which might contain image data.
    2095  * @param boolean $html Whether to return HTML or URLs
     2142 * @param array $args (optional) An array of arguments.
    20962143 * @return string The found data
    20972144 */
    2098 function get_content_image( $content, $html = true ) {
    2099         $srcs = get_content_images( $content, $html, 1 );
     2145function get_content_image( $content, $args = array() ) {
     2146        $srcs = get_content_images( $content, array_merge( $args, array( 'limit' => 1 ) ) );
    21002147        if ( empty( $srcs ) )
    21012148                return '';
    21022149
     
    21062153/**
    21072154 * Check the content blob for galleries and return their image srcs
    21082155 *
     2156 * $args contents:
     2157 * - html  - Whether to return HTML or URLs.
     2158 * - limit - The number of galleries to return.
     2159 *
    21092160 * @since 3.6.0
    21102161 *
    21112162 * @param string $content A string which might contain image data.
    2112  * @param boolean $html Whether to return HTML or data in the array
    2113  * @param int $limit Optional. The number of galleries to return
     2163 * @param array $args (optional) An array of arguments.
    21142164 * @return array A list of galleries, which in turn are a list of their srcs in order
    21152165 */
    2116 function get_content_galleries( $content, $html = true, $limit = 0 ) {
     2166function get_content_galleries( $content, $args = array() ) {
     2167        $defaults = array(
     2168                'html'  => true,
     2169                'limit' => 0
     2170        );
     2171
     2172        $args = wp_parse_args( $args, $defaults );
     2173
    21172174        $galleries = array();
    21182175
    21192176        if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {
     
    21242181
    21252182                                $data = shortcode_parse_atts( $shortcode[3] );
    21262183                                $gallery = do_shortcode_tag( $shortcode );
    2127                                 if ( $html ) {
     2184                                if ( $args['html'] ) {
    21282185                                        $galleries[] = $gallery;
    21292186                                } else {
    21302187                                        preg_match_all( '#src=([\'"])(.+?)\1#is', $gallery, $src, PREG_SET_ORDER );
     
    21372194                                        $galleries[] = $data;
    21382195                                }
    21392196
    2140                                 if ( $limit > 0 && count( $galleries ) >= $limit )
     2197                                if ( $args['limit'] > 0 && count( $galleries ) >= $args['limit'] )
    21412198                                        break;
    21422199                        }
    21432200                }
     
    21492206/**
    21502207 * Retrieve galleries from the passed post's content
    21512208 *
     2209 * $args contents:
     2210 * - post_id - The post id.
     2211 * - html    - Whether to return HTML or data.
     2212 *
    21522213 * @since 3.6.0
    21532214 *
    2154  * @param int $post_id Optional. Post ID.
    2155  * @param boolean $html Whether to return HTML or data in the array
     2215 * @uses get_content_galleries()
     2216 *
     2217 * @param array $args (optional) An array of arguments.
    21562218 * @return array A list of arrays, each containing gallery data and srcs parsed
    21572219 *              from the expanded shortcode
    21582220 */
    2159 function get_post_galleries( $post_id = 0, $html = true ) {
    2160         if ( ! $post = get_post( $post_id ) )
     2221function get_post_galleries( $args = array() ) {
     2222        $defaults = array(
     2223                'post_id' => 0,
     2224                'html'    => true
     2225        );
     2226
     2227        $args = wp_parse_args( $args, $defaults );
     2228
     2229        if ( ! $post = get_post( $args['post_id'] ) )
    21612230                return array();
    21622231
    21632232        if ( ! has_shortcode( $post->post_content, 'gallery' )  )
    21642233                return array();
    21652234
    2166         return get_content_galleries( $post->post_content, $html );
     2235        return get_content_galleries( $post->post_content, array( 'html' => $args['html'] ) );
    21672236}
    21682237
    21692238/**
     
    21712240 *
    21722241 * @since 3.6.0
    21732242 *
     2243 * @uses get_content_galleries()
     2244 *
    21742245 * @param int $post_id Optional. Post ID.
    21752246 * @return array A list of lists, each containing image srcs parsed
    21762247 *              from an expanded shortcode
     
    21822253        if ( ! has_shortcode( $post->post_content, 'gallery' )  )
    21832254                return array();
    21842255
    2185         $data = get_content_galleries( $post->post_content, false );
     2256        $data = get_content_galleries( $post->post_content, array( 'html' => false ) );
    21862257        return wp_list_pluck( $data, 'src' );
    21872258}
    21882259
    21892260/**
    21902261 * Check a specified post's content for gallery and, if present, return the first
    21912262 *
     2263 * $args contents:
     2264 * - post_id - The post id.
     2265 * - html    - Whether to return HTML or URLs.
     2266 *
    21922267 * @since 3.6.0
    21932268 *
    2194  * @param int $post_id Optional. Post ID.
    2195  * @param boolean $html Whether to return HTML or data
     2269 * @uses get_content_galleries()
     2270 *
     2271 * @param array $args (optional) An array of arguments.
    21962272 * @return string|array Gallery data and srcs parsed from the expanded shortcode
    21972273 */
    2198 function get_post_gallery( $post_id = 0, $html = true ) {
    2199         if ( ! $post = get_post( $post_id ) )
     2274function get_post_gallery( $args = array() ) {
     2275        $defaults = array(
     2276                'post_id' => 0,
     2277                'html'    => true
     2278        );
     2279
     2280        $args = wp_parse_args( $args, $defaults );
     2281
     2282        if ( ! $post = get_post( $args['post_id'] ) )
    22002283                return $html ? '' : array();
    22012284
    22022285        if ( ! has_shortcode( $post->post_content, 'gallery' ) )
    22032286                return $html ? '' : array();
    22042287
    2205         $data = get_content_galleries( $post->post_content, $html, false, 1 );
     2288        $data = get_content_galleries( $post->post_content, array(
     2289                'html'  => $args['html'],
     2290                'limit' => 1
     2291        ) );
     2292
    22062293        return reset( $data );
    22072294}
    22082295
     
    22152302 * @return array A list of a gallery's image srcs in order
    22162303 */
    22172304function get_post_gallery_images( $post_id = 0 ) {
    2218         $gallery = get_post_gallery( $post_id, false );
     2305        $gallery = get_post_gallery( array(
     2306                'post_id' => $post_id,
     2307                'html'    => false
     2308        ) );
     2309
    22192310        if ( empty( $gallery['src'] ) )
    22202311                return array();
    22212312