Make WordPress Core

Ticket #17267: 17267-2.diff

File 17267-2.diff, 868 bytes (added by lancewillett, 12 years ago)

Refreshed patch with better comment text

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

     
    448448        <?php endif;
    449449}
    450450
    451 /**
    452  * Grab the first URL from a Link post
    453  */
     451// Return the URL for the first link found in the post content.
    454452function twentyeleven_url_grabber() {
    455         global $post, $posts;
    456 
    457         $first_url = '';
    458 
    459         ob_start();
    460         ob_end_clean();
    461 
    462         $output = preg_match_all('/<a.+href=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
    463 
    464         $first_url = $matches [1] [0];
    465 
    466         if ( empty( $first_url ) )
     453        if ( ! preg_match( '/<a\s[^>]*?href=[\'"](.+?)[\'"]/is', get_the_content(), $matches ) )
    467454                return false;
    468455
    469         return $first_url;
     456        return esc_url_raw( $matches[1] );
    470457}
    471458
    472459/**