Automattic\WooCommerce\Internal\Admin\EmailPreview

EmailPreview::ensure_links_open_in_new_tab()publicWC 1.0

Ensure links open in new tab. User in WooCommerce Settings, so the links don't open inside the iframe.

Method of the class: EmailPreview{}

No Hooks.

Return

String.

Usage

$EmailPreview = new EmailPreview();
$EmailPreview->ensure_links_open_in_new_tab( $content );
$content(string) (required)
Email content HTML.

EmailPreview::ensure_links_open_in_new_tab() code WC 9.7.1

public function ensure_links_open_in_new_tab( string $content ) {
	return (string) preg_replace_callback(
		'/<a\s+([^>]*?)(target=["\']?[^"\']*["\']?)?([^>]*)>/i',
		function ( $matches ) {
			$before = $matches[1];
			$target = 'target="_blank"';
			$after  = $matches[3];
			return "<a $before $target $after>";
		},
		$content
	);
}