]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/class-wp-embed.php
WordPress 4.2.3
[autoinstalls/wordpress.git] / wp-includes / class-wp-embed.php
index a10024a789a74ae532401574dcd3e792ca8790c4..eda4467c45633659c4f630dae0dff4ada96bd34b 100644 (file)
@@ -57,7 +57,7 @@ class WP_Embed {
                add_shortcode( 'embed', array( $this, 'shortcode' ) );
 
                // Do the shortcode (only the [embed] one is registered)
-               $content = do_shortcode( $content );
+               $content = do_shortcode( $content, true );
 
                // Put the original shortcodes back
                $shortcode_tags = $orig_shortcode_tags;
@@ -77,11 +77,9 @@ class WP_Embed {
 
 ?>
 <script type="text/javascript">
-/* <![CDATA[ */
        jQuery(document).ready(function($){
                $.get("<?php echo admin_url( 'admin-ajax.php?action=oembed-cache&post=' . $post->ID, 'relative' ); ?>");
        });
-/* ]]> */
 </script>
 <?php
        }
@@ -126,7 +124,8 @@ class WP_Embed {
         *     @type int $height Height of the embed in pixels.
         * }
         * @param string $url The URL attempting to be embedded.
-        * @return string The embed HTML on success, otherwise the original URL.
+        * @return string|false The embed HTML on success, otherwise the original URL.
+        *                      `->maybe_make_link()` can return false on failure.
         */
        public function shortcode( $attr, $url = '' ) {
                $post = get_post();
@@ -135,6 +134,7 @@ class WP_Embed {
                        $url = $attr['src'];
                }
 
+
                if ( empty( $url ) )
                        return '';
 
@@ -312,7 +312,11 @@ class WP_Embed {
         * @return string Potentially modified $content.
         */
        public function autoembed( $content ) {
-               return preg_replace_callback( '|^\s*(https?://[^\s"]+)\s*$|im', array( $this, 'autoembed_callback' ), $content );
+               // Strip newlines from all elements.
+               $content = wp_replace_in_html_tags( $content, array( "\n" => " " ) );
+
+               // Find URLs that are on their own line.
+               return preg_replace_callback( '|^(\s*)(https?://[^\s"]+)(\s*)$|im', array( $this, 'autoembed_callback' ), $content );
        }
 
        /**
@@ -324,10 +328,10 @@ class WP_Embed {
        public function autoembed_callback( $match ) {
                $oldval = $this->linkifunknown;
                $this->linkifunknown = false;
-               $return = $this->shortcode( array(), $match[1] );
+               $return = $this->shortcode( array(), $match[2] );
                $this->linkifunknown = $oldval;
 
-               return "\n$return\n";
+               return $match[1] . $return . $match[3];
        }
 
        /**