W3cubDocs

/WordPress

WP_Customize_Manager::_validate_external_header_video( WP_Error $validity, mixed $value ): mixed

Callback for validating the external_header_video value.

Description

Ensures that the provided URL is supported.

Parameters

$validityWP_Errorrequired
$valuemixedrequired

Return

mixed

Source

public function _validate_external_header_video( $validity, $value ) {
	$video = sanitize_url( $value );
	if ( $video ) {
		if ( ! preg_match( '#^https?://(?:www\.)?(?:youtube\.com/watch|youtu\.be/)#', $video ) ) {
			$validity->add( 'invalid_url', __( 'Please enter a valid YouTube URL.' ) );
		}
	}
	return $validity;
}

Changelog

Version Description
4.7.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_customize_manager/_validate_external_header_video