Make WordPress Core


Ignore:
Timestamp:
07/12/2013 07:34:59 PM (12 years ago)
Author:
nacin
Message:

Simplify and reduce the new media/content extraction functions.

The URL extraction function is now get_url_in_content(). For more, see #24202.

Also adds filters to get_post_galleries() and get_post_gallery(). fixes #24309.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post-formats.php

    r24554 r24682  
    236236
    237237/**
    238  * Extract a URL from passed content, if possible
    239  * Checks for a URL on the first line of the content or the first encountered href attribute.
     238 * Extract and return the first URL from passed content.
    240239 *
    241240 * @since 3.6.0
     
    244243 * @return string The found URL.
    245244 */
    246 function get_content_url( $content ) {
     245function get_url_in_content( $content ) {
    247246    if ( empty( $content ) )
    248247        return '';
    249248
    250     // the content is a URL
    251     $trimmed = trim( $content );
    252     if ( 0 === stripos( $trimmed, 'http' ) && ! preg_match( '#\s#', $trimmed ) ) {
    253         return $trimmed;
    254 
    255     // the content is HTML so we grab the first href
    256     } elseif ( preg_match( '/<a\s[^>]*?href=([\'"])(.+?)\1/is', $content, $matches ) ) {
     249    if ( preg_match( '/<a\s[^>]*?href=([\'"])(.+?)\1/is', $content, $matches ) )
    257250        return esc_url_raw( $matches[2] );
    258     }
    259 
    260     $lines = explode( "\n", $trimmed );
    261     $line = trim( array_shift( $lines ) );
    262 
    263     // the content is a URL followed by content
    264     if ( 0 === stripos( $line, 'http' ) )
    265         return esc_url_raw( $line );
    266 
    267     return '';
     251
     252    return false;
    268253}
    269254
Note: See TracChangeset for help on using the changeset viewer.