WordPress.org

Make WordPress Core

Ticket #23776: autoembed-preserve-whitespace.diff

File autoembed-preserve-whitespace.diff, 951 bytes (added by chipx86, 6 years ago)

Preserves whitespace around URLs in the auto-embed code.

  • src/wp-includes/class-wp-embed.php

     
    326326         * @return string Potentially modified $content.
    327327         */
    328328        public function autoembed( $content ) {
    329                 return preg_replace_callback( '|^\s*(https?://[^\s"]+)\s*$|im', array( $this, 'autoembed_callback' ), $content );
     329                return preg_replace_callback( '|^(\s*)(https?://[^\s"]+)(\s*)$|im', array( $this, 'autoembed_callback' ), $content );
    330330        }
    331331
    332332        /**
     
    340340        public function autoembed_callback( $match ) {
    341341                $oldval = $this->linkifunknown;
    342342                $this->linkifunknown = false;
    343                 $return = $this->shortcode( array(), $match[1] );
     343                $return = $this->shortcode( array(), $match[2] );
    344344                $this->linkifunknown = $oldval;
    345345
    346                 return "\n$return\n";
     346                return $match[1] . $return . $match[3];
    347347        }
    348348
    349349        /**