Make WordPress Core


Ignore:
Timestamp:
06/02/2016 09:23:43 PM (9 years ago)
Author:
azaozz
Message:

Auto-embedding:

  • We already match URLs on their own line, add another regex to match URLs in their own paragraphs.
  • Always exclude the \s<>" characters when matching.
  • Add more unit tests.

Props iseulde, azaozz.
Fixes #25387.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-embed.php

    r37539 r37627  
    335335        $content = wp_replace_in_html_tags( $content, array( "\n" => '<!-- wp-line-break -->' ) );
    336336
    337         // Find URLs that are on their own line.
    338         $content = preg_replace_callback( '|^(\s*)(https?://[^\s"]+)(\s*)$|im', array( $this, 'autoembed_callback' ), $content );
     337        if ( preg_match( '#(^|\s|>)https?://#i', $content ) ) {
     338            // Find URLs on their own line.
     339            $content = preg_replace_callback( '|^(\s*)(https?://[^\s<>"]+)(\s*)$|im', array( $this, 'autoembed_callback' ), $content );
     340            // Find URLs in their own paragraph.
     341            $content = preg_replace_callback( '|(<p(?: [^>]*)?>\s*)(https?://[^\s<>"]+)(\s*<\/p>)|i', array( $this, 'autoembed_callback' ), $content );
     342        }
    339343
    340344        // Put the line breaks back.
Note: See TracChangeset for help on using the changeset viewer.