<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[24682] trunk: Simplify and reduce the new media/content extraction functions.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://core.trac.wordpress.org/changeset/24682">24682</a></dd>
<dt>Author</dt> <dd>nacin</dd>
<dt>Date</dt> <dd>2013-07-12 19:34:59 +0000 (Fri, 12 Jul 2013)</dd>
</dl>
<h3>Log Message</h3>
<pre>Simplify and reduce the new media/content extraction functions.
The URL extraction function is now get_url_in_content(). For more, see <a href="http://core.trac.wordpress.org/ticket/24202">#24202</a>.
Also adds filters to get_post_galleries() and get_post_gallery(). fixes <a href="http://core.trac.wordpress.org/ticket/24309">#24309</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpcontentthemestwentythirteenfunctionsphp">trunk/wp-content/themes/twentythirteen/functions.php</a></li>
<li><a href="#trunkwpincludesmediaphp">trunk/wp-includes/media.php</a></li>
<li><a href="#trunkwpincludespostformatsphp">trunk/wp-includes/post-formats.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpcontentthemestwentythirteenfunctionsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-content/themes/twentythirteen/functions.php (24681 => 24682)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-content/themes/twentythirteen/functions.php 2013-07-12 18:58:55 UTC (rev 24681)
+++ trunk/wp-content/themes/twentythirteen/functions.php 2013-07-12 19:34:59 UTC (rev 24682)
</span><span class="lines">@@ -484,7 +484,7 @@
</span><span class="cx"> /**
</span><span class="cx"> * Returns the URL from the post.
</span><span class="cx"> *
</span><del>- * @uses get_content_url() to get the URL in the post meta (if it exists) or
</del><ins>+ * @uses get_url_in_content() to get the URL in the post meta (if it exists) or
</ins><span class="cx"> * the first link found in the post content.
</span><span class="cx"> *
</span><span class="cx"> * Falls back to the post permalink if no URL is found in the post.
</span><span class="lines">@@ -495,7 +495,7 @@
</span><span class="cx"> */
</span><span class="cx"> function twentythirteen_get_link_url() {
</span><span class="cx"> $content = get_the_content();
</span><del>- $has_url = get_content_url( $content );
</del><ins>+ $has_url = get_url_in_content( $content );
</ins><span class="cx">
</span><span class="cx"> return ( $has_url ) ? $has_url : apply_filters( 'the_permalink', get_permalink() );
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkwpincludesmediaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/media.php (24681 => 24682)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/media.php 2013-07-12 18:58:55 UTC (rev 24681)
+++ trunk/wp-includes/media.php 2013-07-12 19:34:59 UTC (rev 24682)
</span><span class="lines">@@ -857,7 +857,7 @@
</span><span class="cx">
</span><span class="cx"> $default_types = wp_get_audio_extensions();
</span><span class="cx"> $defaults_atts = array( 'src' => '' );
</span><del>- foreach ( $default_types as $type )
</del><ins>+ foreach ( $default_types as $type )
</ins><span class="cx"> $defaults_atts[$type] = '';
</span><span class="cx">
</span><span class="cx"> $atts = shortcode_atts( $defaults_atts, $attr, 'audio' );
</span><span class="lines">@@ -963,7 +963,7 @@
</span><span class="cx"> 'width' => empty( $content_width ) ? 640 : $content_width,
</span><span class="cx"> );
</span><span class="cx">
</span><del>- foreach ( $default_types as $type )
</del><ins>+ foreach ( $default_types as $type )
</ins><span class="cx"> $defaults_atts[$type] = '';
</span><span class="cx">
</span><span class="cx"> $atts = shortcode_atts( $defaults_atts, $attr, 'video' );
</span><span class="lines">@@ -1444,7 +1444,7 @@
</span><span class="cx"> $args['path'] = $path;
</span><span class="cx">
</span><span class="cx"> if ( ! isset( $args['mime_type'] ) ) {
</span><del>- $file_info = wp_check_filetype( $args['path'] );
</del><ins>+ $file_info = wp_check_filetype( $args['path'] );
</ins><span class="cx">
</span><span class="cx"> // If $file_info['type'] is false, then we let the editor attempt to
</span><span class="cx"> // figure out the file type, rather than forcing a failure based on extension.
</span><span class="lines">@@ -1473,7 +1473,7 @@
</span><span class="cx"> * @since 3.5.0
</span><span class="cx"> * @access public
</span><span class="cx"> *
</span><del>- * @param string|array $args Array of requirements. Accepts { 'mime_type'=>string, 'methods'=>{string, string, ...} }
</del><ins>+ * @param string|array $args Array of requirements. Accepts { 'mime_type'=>string, 'methods'=>{string, string, ...} }
</ins><span class="cx"> * @return boolean true if an eligible editor is found; false otherwise
</span><span class="cx"> */
</span><span class="cx"> function wp_image_editor_supports( $args = array() ) {
</span><span class="lines">@@ -1842,12 +1842,12 @@
</span><span class="cx"> * @since 3.6.0
</span><span class="cx"> *
</span><span class="cx"> * @param string $type (Mime) type of media desired
</span><del>- * @param int $post_id Post ID
</del><ins>+ * @param mixed $post Post ID or object
</ins><span class="cx"> * @return array Found attachments
</span><span class="cx"> */
</span><del>-function get_attached_media( $type, $post_id = 0 ) {
- if ( ! $post = get_post( $post_id ) )
- return;
</del><ins>+function get_attached_media( $type, $post = 0 ) {
+ if ( ! $post = get_post( $post ) )
+ return array();
</ins><span class="cx">
</span><span class="cx"> $args = array(
</span><span class="cx"> 'post_parent' => $post->ID,
</span><span class="lines">@@ -1866,187 +1866,51 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Extract and parse {media type} shortcodes or srcs from the passed content
</del><ins>+ * Check the content blob for an <audio>, <video> <object>, <embed>, or <iframe>
</ins><span class="cx"> *
</span><span class="cx"> * @since 3.6.0
</span><span class="cx"> *
</span><span class="cx"> * @param string $type Type of media: audio or video
</span><span class="cx"> * @param string $content A string which might contain media data.
</span><del>- * @param boolean $html Whether to return HTML or URLs
- * @param int $limit Optional. The number of medias to return
- * @return array A list of parsed shortcodes or extracted srcs
</del><ins>+ * @return array A list of found HTML media embeds
</ins><span class="cx"> */
</span><del>-function get_content_media( $type, $content, $html = true, $limit = 0 ) {
- $items = array();
-
- if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {
- foreach ( $matches as $shortcode ) {
- if ( $type === $shortcode[2] ) {
- $count = 1;
-
- $items[] = do_shortcode_tag( $shortcode );
- if ( $limit > 0 && count( $items ) >= $limit )
- break;
- }
- }
- }
-
- if ( $html )
- return $items;
-
- $data = array();
-
- foreach ( $items as $item ) {
- preg_match_all( '#src=([\'"])(.+?)\1#is', $item, $src, PREG_SET_ORDER );
- if ( ! empty( $src ) ) {
- $srcs = array();
- foreach ( $src as $s )
- $srcs[] = $s[2];
-
- $data[] = array_values( array_unique( $srcs ) );
- }
- }
-
- return $data;
-}
-
-/**
- * Check the content blob for an <{media type}>, <object>, <embed>, or <iframe>, in that order
- * If no HTML tag is found, check the first line of the post for a URL
- *
- * @since 3.6.0
- *
- * @param string $type Type of media: audio or video
- * @param string $content A string which might contain media data.
- * @param int $limit Optional. The number of galleries to return
- * @return array A list of found HTML media embeds and possibly a URL by itself
- */
-function get_embedded_media( $type, $content, $limit = 0 ) {
</del><ins>+function get_media_embedded_in_content( $content ) {
</ins><span class="cx"> $html = array();
</span><span class="cx">
</span><del>- foreach ( array( $type, 'object', 'embed', 'iframe' ) as $tag ) {
</del><ins>+ foreach ( array( 'audio', 'video', 'object', 'embed', 'iframe' ) as $tag ) {
</ins><span class="cx"> if ( preg_match( '#' . get_tag_regex( $tag ) . '#', $content, $matches ) ) {
</span><span class="cx"> $html[] = $matches[0];
</span><del>-
- if ( $limit > 0 && count( $html ) >= $limit )
- break;
</del><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><del>- if ( ! empty( $html ) && count( $html ) >= $limit )
- return $html;
-
- $lines = explode( "\n", trim( $content ) );
- $line = trim( array_shift( $lines ) );
- if ( 0 === stripos( $line, 'http' ) ) {
- $html[] = $line;
- }
</del><span class="cx"> return $html;
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Extract the HTML or <source> srcs from the content's [audio]
- *
- * @since 3.6.0
- *
- * @param string $content A string which might contain audio data.
- * @param boolean $html Whether to return HTML or URLs
- * @return array A list of lists. Each item has a list of HTML or srcs corresponding
- * to an [audio]'s HTML or primary src and specified fallbacks
- */
-function get_content_audio( $content, $html = true ) {
- return get_content_media( 'audio', $content, $html );
-}
-
-/**
- * Check the content blob for an <audio>, <object>, <embed>, or <iframe>, in that order
- * If no HTML tag is found, check the first line of the post for a URL
- *
- * @since 3.6.0
- *
- * @param string $content A string which might contain audio data.
- * @return array A list of found HTML audio embeds and possibly a URL by itself
- */
-function get_embedded_audio( $content ) {
- return get_embedded_media( 'audio', $content );
-}
-
-/**
- * Extract the HTML or <source> srcs from the content's [video]
- *
- * @since 3.6.0
- *
- * @param string $content A string which might contain video data.
- * @param boolean $html Whether to return HTML or URLs
- * @return array A list of lists. Each item has a list of HTML or srcs corresponding
- * to a [video]'s HTML or primary src and specified fallbacks
- */
-function get_content_video( $content, $html = true ) {
- return get_content_media( 'video', $content, $html );
-}
-
-/**
- * Check the content blob for a <video>, <object>, <embed>, or <iframe>, in that order
- * If no HTML tag is found, check the first line of the post for a URL
- *
- * @since 3.6.0
- *
- * @param string $content A string which might contain video data.
- * @return array A list of found HTML video embeds and possibly a URL by itself
- */
-function get_embedded_video( $content ) {
- return get_embedded_media( 'video', $content );
-}
-
-/**
- * Retrieve images attached to the passed post
- *
- * @since 3.6.0
- *
- * @param int $post_id Optional. Post ID.
- * @return array Found image attachments
- */
-function get_attached_image_srcs( $post_id = 0 ) {
- $children = get_attached_media( 'image', $post_id );
- if ( empty( $children ) )
- return array();
-
- $srcs = array();
- foreach ( $children as $attachment )
- $srcs[] = wp_get_attachment_url( $attachment->ID );
-
- return $srcs;
-}
-
-/**
</del><span class="cx"> * Check the content blob for images or image srcs
</span><span class="cx"> *
</span><span class="cx"> * @since 3.6.0
</span><span class="cx"> *
</span><span class="cx"> * @param string $content A string which might contain image data.
</span><span class="cx"> * @param boolean $html Whether to return HTML or URLs in the array
</span><del>- * @param int $limit Optional. The number of image srcs to return
</del><span class="cx"> * @return array The found images or srcs
</span><span class="cx"> */
</span><del>-function get_content_images( $content, $html = true, $limit = 0 ) {
</del><ins>+function get_images_in_content( $content, $html = true ) {
</ins><span class="cx"> $tags = array();
</span><span class="cx"> $captions = array();
</span><span class="cx">
</span><del>- if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {
</del><ins>+ if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) ) {
</ins><span class="cx"> foreach ( $matches as $shortcode ) {
</span><span class="cx"> if ( 'caption' === $shortcode[2] ) {
</span><span class="cx"> $captions[] = $shortcode[0];
</span><span class="cx"> if ( $html )
</span><span class="cx"> $tags[] = do_shortcode_tag( $shortcode );
</span><span class="cx"> }
</span><del>-
- if ( $limit > 0 && count( $tags ) >= $limit )
- break;
</del><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> foreach ( array( 'a', 'img' ) as $tag ) {
</span><del>- if ( preg_match_all( '#' . get_tag_regex( $tag ) . '#i', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {
</del><ins>+ if ( preg_match_all( '#' . get_tag_regex( $tag ) . '#i', $content, $matches, PREG_SET_ORDER ) ) {
</ins><span class="cx"> foreach ( $matches as $node ) {
</span><span class="cx"> if ( ! strstr( $node[0], '<img ' ) )
</span><span class="cx"> continue;
</span><span class="lines">@@ -2062,9 +1926,6 @@
</span><span class="cx">
</span><span class="cx"> if ( ! $found )
</span><span class="cx"> $tags[] = $node[0];
</span><del>-
- if ( $limit > 0 && count( $tags ) >= $limit )
- break 2;
</del><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="lines">@@ -2072,18 +1933,16 @@
</span><span class="cx"> if ( $html )
</span><span class="cx"> return $tags;
</span><span class="cx">
</span><del>- $srcs = array();
</del><ins>+ $image_srcs = array();
</ins><span class="cx">
</span><span class="cx"> foreach ( $tags as $tag ) {
</span><span class="cx"> preg_match( '#src=([\'"])(.+?)\1#is', $tag, $src );
</span><del>- if ( ! empty( $src[2] ) ) {
- $srcs[] = $src[2];
- if ( $limit > 0 && count( $srcs ) >= $limit )
- break;
- }
</del><ins>+ if ( ! empty( $src[2] ) )
+ $image_srcs[] = $src[2];
</ins><span class="cx"> }
</span><span class="cx">
</span><del>- return apply_filters( 'content_images', array_values( array_unique( $srcs ) ), $content );
</del><ins>+ $image_srcs = array_values( array_unique( $image_srcs ) );
+ return apply_filters( 'get_images_in_content', $image_srcs, $content );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -2095,34 +1954,35 @@
</span><span class="cx"> * @param boolean $html Whether to return HTML or URLs
</span><span class="cx"> * @return string The found data
</span><span class="cx"> */
</span><del>-function get_content_image( $content, $html = true ) {
- $srcs = get_content_images( $content, $html, 1 );
- if ( empty( $srcs ) )
- return '';
-
- return apply_filters( 'content_image', reset( $srcs ), $content );
</del><ins>+function get_image_in_content( $content, $html = true ) {
+ $srcs = get_images_from_content( $content, $html );
+ return apply_filters( 'get_image_in_content', reset( $srcs ), $content );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Check the content blob for galleries and return their image srcs
</del><ins>+ * Retrieve galleries from the passed post's content
</ins><span class="cx"> *
</span><span class="cx"> * @since 3.6.0
</span><span class="cx"> *
</span><del>- * @param string $content A string which might contain image data.
</del><ins>+ * @param mixed $post Optional. Post ID or object.
</ins><span class="cx"> * @param boolean $html Whether to return HTML or data in the array
</span><del>- * @param int $limit Optional. The number of galleries to return
- * @return array A list of galleries, which in turn are a list of their srcs in order
</del><ins>+ * @return array A list of arrays, each containing gallery data and srcs parsed
+ * from the expanded shortcode
</ins><span class="cx"> */
</span><del>-function get_content_galleries( $content, $html = true, $limit = 0 ) {
</del><ins>+function get_post_galleries( $post, $html = true ) {
+ if ( ! $post = get_post( $post ) )
+ return array();
+
+ if ( ! has_shortcode( $post->post_content, 'gallery' ) )
+ return array();
+
</ins><span class="cx"> $galleries = array();
</span><del>-
- if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {
</del><ins>+ if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $post->post_content, $matches, PREG_SET_ORDER ) ) {
</ins><span class="cx"> foreach ( $matches as $shortcode ) {
</span><span class="cx"> if ( 'gallery' === $shortcode[2] ) {
</span><span class="cx"> $srcs = array();
</span><span class="cx"> $count = 1;
</span><span class="cx">
</span><del>- $data = shortcode_parse_atts( $shortcode[3] );
</del><span class="cx"> $gallery = do_shortcode_tag( $shortcode );
</span><span class="cx"> if ( $html ) {
</span><span class="cx"> $galleries[] = $gallery;
</span><span class="lines">@@ -2133,37 +1993,31 @@
</span><span class="cx"> $srcs[] = $s[2];
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+ $data = shortcode_parse_atts( $shortcode[3] );
</ins><span class="cx"> $data['src'] = array_values( array_unique( $srcs ) );
</span><span class="cx"> $galleries[] = $data;
</span><span class="cx"> }
</span><del>-
- if ( $limit > 0 && count( $galleries ) >= $limit )
- break;
</del><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx"> }
</span><span class="cx">
</span><del>- return apply_filters( 'content_galleries', $galleries, $content );
</del><ins>+ return apply_filters( 'get_post_galleries', $galleries, $post );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Retrieve galleries from the passed post's content
</del><ins>+ * Check a specified post's content for gallery and, if present, return the first
</ins><span class="cx"> *
</span><span class="cx"> * @since 3.6.0
</span><span class="cx"> *
</span><del>- * @param int $post_id Optional. Post ID.
- * @param boolean $html Whether to return HTML or data in the array
- * @return array A list of arrays, each containing gallery data and srcs parsed
- * from the expanded shortcode
</del><ins>+ * @param mixed $post Optional. Post ID or object.
+ * @param boolean $html Whether to return HTML or data
+ * @return string|array Gallery data and srcs parsed from the expanded shortcode
</ins><span class="cx"> */
</span><del>-function get_post_galleries( $post_id = 0, $html = true ) {
- if ( ! $post = get_post( $post_id ) )
- return array();
</del><ins>+function get_post_gallery( $post = 0, $html = true ) {
+ $galleries = get_post_galleries( $post, $html );
+ $gallery = reset( $galleries );
</ins><span class="cx">
</span><del>- if ( ! has_shortcode( $post->post_content, 'gallery' ) )
- return array();
-
- return get_content_galleries( $post->post_content, $html );
</del><ins>+ return apply_filters( 'get_post_gallery', $gallery, $post, $galleries );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><span class="lines">@@ -2171,53 +2025,24 @@
</span><span class="cx"> *
</span><span class="cx"> * @since 3.6.0
</span><span class="cx"> *
</span><del>- * @param int $post_id Optional. Post ID.
</del><ins>+ * @param mixed $post Optional. Post ID or object.
</ins><span class="cx"> * @return array A list of lists, each containing image srcs parsed
</span><span class="cx"> * from an expanded shortcode
</span><span class="cx"> */
</span><del>-function get_post_galleries_images( $post_id = 0 ) {
- if ( ! $post = get_post( $post_id ) )
- return array();
-
- if ( ! has_shortcode( $post->post_content, 'gallery' ) )
- return array();
-
- $data = get_content_galleries( $post->post_content, false );
- return wp_list_pluck( $data, 'src' );
</del><ins>+function get_post_galleries_images( $post = 0 ) {
+ $galleries = get_post_galleries( $post, false );
+ return wp_list_pluck( $galleries, 'src' );
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Check a specified post's content for gallery and, if present, return the first
- *
- * @since 3.6.0
- *
- * @param int $post_id Optional. Post ID.
- * @param boolean $html Whether to return HTML or data
- * @return string|array Gallery data and srcs parsed from the expanded shortcode
- */
-function get_post_gallery( $post_id = 0, $html = true ) {
- if ( ! $post = get_post( $post_id ) )
- return $html ? '' : array();
-
- if ( ! has_shortcode( $post->post_content, 'gallery' ) )
- return $html ? '' : array();
-
- $data = get_content_galleries( $post->post_content, $html, false, 1 );
- return reset( $data );
-}
-
-/**
</del><span class="cx"> * Check a post's content for galleries and return the image srcs for the first found gallery
</span><span class="cx"> *
</span><span class="cx"> * @since 3.6.0
</span><span class="cx"> *
</span><del>- * @param int $post_id Optional. Post ID.
</del><ins>+ * @param mixed $post Optional. Post ID or object.
</ins><span class="cx"> * @return array A list of a gallery's image srcs in order
</span><span class="cx"> */
</span><del>-function get_post_gallery_images( $post_id = 0 ) {
- $gallery = get_post_gallery( $post_id, false );
- if ( empty( $gallery['src'] ) )
- return array();
-
- return $gallery['src'];
</del><ins>+function get_post_gallery_images( $post = 0 ) {
+ $galleries = get_post_gallery( $post, false );
+ return empty( $gallery['src'] ) ? array() : $gallery['src'];
</ins><span class="cx"> }
</span></span></pre></div>
<a id="trunkwpincludespostformatsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/post-formats.php (24681 => 24682)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/post-formats.php 2013-07-12 18:58:55 UTC (rev 24681)
+++ trunk/wp-includes/post-formats.php 2013-07-12 19:34:59 UTC (rev 24682)
</span><span class="lines">@@ -235,36 +235,21 @@
</span><span class="cx"> add_filter( 'wp_get_object_terms', '_post_format_wp_get_object_terms' );
</span><span class="cx">
</span><span class="cx"> /**
</span><del>- * Extract a URL from passed content, if possible
- * Checks for a URL on the first line of the content or the first encountered href attribute.
</del><ins>+ * Extract and return the first URL from passed content.
</ins><span class="cx"> *
</span><span class="cx"> * @since 3.6.0
</span><span class="cx"> *
</span><span class="cx"> * @param string $content A string which might contain a URL.
</span><span class="cx"> * @return string The found URL.
</span><span class="cx"> */
</span><del>-function get_content_url( $content ) {
</del><ins>+function get_url_in_content( $content ) {
</ins><span class="cx"> if ( empty( $content ) )
</span><span class="cx"> return '';
</span><span class="cx">
</span><del>- // the content is a URL
- $trimmed = trim( $content );
- if ( 0 === stripos( $trimmed, 'http' ) && ! preg_match( '#\s#', $trimmed ) ) {
- return $trimmed;
-
- // the content is HTML so we grab the first href
- } elseif ( preg_match( '/<a\s[^>]*?href=([\'"])(.+?)\1/is', $content, $matches ) ) {
</del><ins>+ if ( preg_match( '/<a\s[^>]*?href=([\'"])(.+?)\1/is', $content, $matches ) )
</ins><span class="cx"> return esc_url_raw( $matches[2] );
</span><del>- }
</del><span class="cx">
</span><del>- $lines = explode( "\n", $trimmed );
- $line = trim( array_shift( $lines ) );
-
- // the content is a URL followed by content
- if ( 0 === stripos( $line, 'http' ) )
- return esc_url_raw( $line );
-
- return '';
</del><ins>+ return false;
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> /**
</span></span></pre>
</div>
</div>
</body>
</html>