Automattic\WooCommerce\EmailEditor\Integrations\Core\Renderer\Blocks

Video::get_current_post_urlprivateWC 1.0

Get the current post permalink with security validation.

Method of the class: Video{}

No Hooks.

Returns

String. Post permalink or empty string if invalid.

Usage

// private - for code of main (parent) class only
$result = $this->get_current_post_url(): string;

Video::get_current_post_url() code WC 10.8.1

private function get_current_post_url(): string {
	global $post;

	if ( ! $post instanceof \WP_Post ) {
		return '';
	}

	$permalink = get_permalink( $post->ID );
	if ( empty( $permalink ) ) {
		return '';
	}

	// Validate URL type and format (following audio block pattern).
	if ( strpos( $permalink, 'https://' ) !== 0 && strpos( $permalink, 'http://' ) !== 0 ) {
		// Reject non-HTTP protocols for security.
		return '';
	}

	// For all HTTP(S) URLs, validate with wp_http_validate_url.
	if ( ! wp_http_validate_url( $permalink ) ) {
		return '';
	}

	return $permalink;
}