# jetpack/16.3/jetpack_vendor/automattic/jetpack-videopress/src/class-utils.php

Jetpack – WP Security, Backup, Speed, &amp; Growth, version 16.3. 102 lines.

- Page: https://pluginprobe.com/plugins/jetpack/16.3/code/jetpack_vendor/automattic/jetpack-videopress/src/class-utils.php
- Raw: https://pluginprobe.com/plugins/jetpack/16.3/raw/jetpack_vendor/automattic/jetpack-videopress/src/class-utils.php
- Modified: 2026-09-08T18:39:34+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/jetpack/16.3/code/jetpack_vendor/automattic/jetpack-videopress/src/class-utils.php#L10-L20`.

```php
<?php
/**
 * The Utils class.
 *
 * @package automattic/jetpack-videopress
 */

namespace Automattic\Jetpack\VideoPress;

/**
 * The Utils class.
 */
class Utils {
	/**
	 * Build a VideoPress video URL based on the guid and block attributes.
	 *
	 * @param string|null $guid       - Video GUID; null returns null.
	 * @param array       $attributes - Video block attributes. Default is an empty array.
	 *
	 * @return string|null VideoPress video URL with the specified attributes, or null without a guid.
	 */
	public static function get_video_press_url( $guid, $attributes = array() ) {
		if ( ! $guid ) {
			return null;
		}

		$video_press_url_options = wp_parse_args(
			$attributes,
			array(
				'autoplay'            => false,
				'controls'            => true,
				'loop'                => false,
				'muted'               => false,
				'playsinline'         => false,
				'poster'              => '',
				'preload'             => 'metadata',
				'seekbarColor'        => '',
				'seekbarPlayedColor'  => '',
				'seekbarLoadingColor' => '',
				'useAverageColor'     => true,
			)
		);

		// The site-wide opt-out wins over the block's own preload attribute.
		if ( Data::get_videopress_player_preload_disabled() ) {
			$video_press_url_options['preload'] = 'none';
		}

		$query_args = array(
			'resizeToParent'  => 1,
			'cover'           => 1,
			'autoPlay'        => (int) $video_press_url_options['autoplay'],
			'controls'        => (int) $video_press_url_options['controls'],
			'loop'            => (int) $video_press_url_options['loop'],
			'muted'           => (int) $video_press_url_options['muted'],
			'persistVolume'   => $video_press_url_options['muted'] ? 0 : 1,
			'playsinline'     => (int) $video_press_url_options['playsinline'],
			'preloadContent'  => $video_press_url_options['preload'],
			'sbc'             => $video_press_url_options['seekbarColor'],
			'sbpc'            => $video_press_url_options['seekbarPlayedColor'],
			'sblc'            => $video_press_url_options['seekbarLoadingColor'],
			'useAverageColor' => (int) $video_press_url_options['useAverageColor'],
		);

		if ( ! empty( $video_press_url_options['poster'] ) ) {
			$query_args['posterUrl'] = rawurlencode( $video_press_url_options['poster'] );
		}

		$url = 'https://videopress.com/v/' . $guid;
		return add_query_arg( $query_args, $url );
	}

	/**
	 * Determines if a given URL is a VideoPress URL.
	 *
	 * @since x.x.x
	 *
	 * @param mixed $url The URL to check. Non-strings return false.
	 * @return bool True if the URL is a VideoPress URL, false otherwise.
	 */
	public static function is_videopress_url( $url ) {
		return null !== self::extract_videopress_guid_from_url( $url );
	}

	/**
	 * Extract the VideoPress guid from a recognised VideoPress URL.
	 *
	 * @param mixed $url The URL to inspect. Non-strings return null.
	 * @return string|null The 8-character guid, or null if the URL is not a recognised VideoPress URL.
	 */
	public static function extract_videopress_guid_from_url( $url ) {
		if ( ! is_string( $url ) ) {
			return null;
		}
		$pattern = '/^https?:\/\/(?:(?:v(?:ideo)?\.wordpress\.com|videopress\.com)\/(?:v|embed)|v\.wordpress\.com|videos\.(?:videopress\.com|files\.wordpress\.com))\/([a-z\d]{8})(\/|\b)/i'; // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledInText
		if ( preg_match( $pattern, $url, $matches ) ) {
			return $matches[1];
		}
		return null;
	}
}

```
