GC_Embed::autoembed()

最后更新于:2021-11-27 14:39:43

GC_Embed::autoembed( string$content)

Passes any unlinked URLs that are on their own line to GC_Embed::shortcode() for potential embedding.

参数

$content

(string) (Required) The content to be searched.

响应

(string) Potentially modified $content.

源文件

文件: gc-includes/class-gc-embed.php

	public function autoembed( $content ) {
		// Replace line breaks from all HTML elements with placeholders.
		$content = gc_replace_in_html_tags( $content, array( "n" => '<!-- gc-line-break -->' ) );

		if ( preg_match( '#(^|s|>)https?://#i', $content ) ) {
			// Find URLs on their own line.
			$content = preg_replace_callback( '|^(s*)(https?://[^s<>"]+)(s*)$|im', array( $this, 'autoembed_callback' ), $content );
			// Find URLs in their own paragraph.
			$content = preg_replace_callback( '|(<p(?: [^>]*)?>s*)(https?://[^s<>"]+)(s*</p>)|i', array( $this, 'autoembed_callback' ), $content );
		}

		// Put the line breaks back.
		return str_replace( '<!-- gc-line-break -->', "n", $content );
	}