protected function filterDimensions( $html ) {

		$media_atts = [];
		$_html      = strip_tags( $html, '<object><embed><iframe><video>' );

		// Find the attributes of the media.
		$atts = wp_kses_hair( $_html, [ 'http', 'https' ] );

		// Loop through the media attributes and add them in key/value pairs.
		foreach ( $atts as $att ) {
			$media_atts[ $att['name'] ] = $att['value'];
		}

		// If no dimensions are found, just return the HTML.
		if ( empty( $media_atts ) || ! isset( $media_atts['width'] ) || ! isset( $media_atts['height'] ) ) {
			return $html;
		}

		// Set the max width.
		$max_width = $this->width;

		// Set the max height based on the max width and original width/height ratio.
		$max_height = round( $max_width / ( $media_atts['width'] / $media_atts['height'] ) );

		// Fix for Spotify embeds.
		if ( ! empty( $media_atts['src'] ) && preg_match( '#https?://(embed)\.spotify\.com/.*#i', $media_atts['src'], $matches ) ) {

			list( $max_width, $max_height ) = $this->spotifyDimensions( $media_atts );
		}

		// Calculate new media dimensions.
		$dimensions = wp_expand_dimensions(
			$media_atts['width'],
			$media_atts['height'],
			$max_width,
			$max_height
		);

		// Allow devs to filter the final width and height of the media.
		list( $width, $height ) = apply_filters(
			'hybrid/media/grabber/dimensions',
			$dimensions,                       // width/height array
			$media_atts,                       // media HTML attributes
			$this                              // media grabber object
		);

		// Set up the patterns for the 'width' and 'height' attributes.
		$patterns = [
			'/(width=[\'"]).+?([\'"])/i',
			'/(height=[\'"]).+?([\'"])/i',
			'/(<div.+?style=[\'"].*?width:.+?).+?(px;.+?[\'"].*?>)/i',
			'/(<div.+?style=[\'"].*?height:.+?).+?(px;.+?[\'"].*?>)/i'
		];

		// Set up the replacements for the 'width' and 'height' attributes.
		$replacements = [
			'${1}' . $width . '${2}',
			'${1}' . $height . '${2}',
			'${1}' . $width . '${2}',
			'${1}' . $height . '${2}',
		];

		// Filter the dimensions and return the media HTML.
		return preg_replace( $patterns, $replacements, $html );
	}
protected function filterDimensions( $html ) {

		$media_atts = [];
		$_html      = strip_tags( $html, '<object><embed><iframe><video>' );

		// Find the attributes of the media.
		$atts = wp_kses_hair( $_html, [ 'http', 'https' ] );

		// Loop through the media attributes and add them in key/value pairs.
		foreach ( $atts as $att ) {
			$media_atts[ $att['name'] ] = $att['value'];
		}

		// If no dimensions are found, just return the HTML.
		if ( empty( $media_atts ) || ! isset( $media_atts['width'] ) || ! isset( $media_atts['height'] ) ) {
			return $html;
		}

		// Set the max width.
		$max_width = $this->width;

		// Set the max height based on the max width and original width/height ratio.
		$max_height = round( $max_width / ( $media_atts['width'] / $media_atts['height'] ) );

		// Fix for Spotify embeds.
		if ( ! empty( $media_atts['src'] ) && preg_match( '#https?://(embed)\.spotify\.com/.*#i', $media_atts['src'], $matches ) ) {

			list( $max_width, $max_height ) = $this->spotifyDimensions( $media_atts );
		}

		// Calculate new media dimensions.
		$dimensions = wp_expand_dimensions(
			$media_atts['width'],
			$media_atts['height'],
			$max_width,
			$max_height
		);

		// Allow devs to filter the final width and height of the media.
		list( $width, $height ) = apply_filters(
			'hybrid/media/grabber/dimensions',
			$dimensions,                       // width/height array
			$media_atts,                       // media HTML attributes
			$this                              // media grabber object
		);

		// Set up the patterns for the 'width' and 'height' attributes.
		$patterns = [
			'/(width=[\'"]).+?([\'"])/i',
			'/(height=[\'"]).+?([\'"])/i',
			'/(<div.+?style=[\'"].*?width:.+?).+?(px;.+?[\'"].*?>)/i',
			'/(<div.+?style=[\'"].*?height:.+?).+?(px;.+?[\'"].*?>)/i'
		];

		// Set up the replacements for the 'width' and 'height' attributes.
		$replacements = [
			'${1}' . $width . '${2}',
			'${1}' . $height . '${2}',
			'${1}' . $width . '${2}',
			'${1}' . $height . '${2}',
		];

		// Filter the dimensions and return the media HTML.
		return preg_replace( $patterns, $replacements, $html );
	}
protected function filterDimensions ( $ html ) { $ media_atts = [ ] ; $ _html = strip_tags ( $ html , '<object><embed><iframe><video>' ) ; // Find the attributes of the media. $ atts = wp_kses_hair ( $ _html , [ 'http' , 'https' ] ) ; // Loop through the media attributes and add them in key/value pairs. foreach ( $ atts as $ att ) { $ media_atts [ $ att [ 'name' ] ] = $ att [ 'value' ] ; } // If no dimensions are found, just return the HTML. if ( empty ( $ media_atts ) || ! isset ( $ media_atts [ 'width' ] ) || ! isset ( $ media_atts [ 'height' ] ) ) { return $ html ; } // Set the max width. $ max_width = $ this -> width ; // Set the max height based on the max width and original width/height ratio. $ max_height = round ( $ max_width / ( $ media_atts [ 'width' ] / $ media_atts [ 'height' ] ) ) ; // Fix for Spotify embeds. if ( ! empty ( $ media_atts [ 'src' ] ) && preg_match ( '#https?://(embed)\.spotify\.com/.*#i' , $ media_atts [ 'src' ] , $ matches ) ) { list ( $ max_width , $ max_height ) = $ this -> spotifyDimensions ( $ media_atts ) ; } // Calculate new media dimensions. $ dimensions = wp_expand_dimensions ( $ media_atts [ 'width' ] , $ media_atts [ 'height' ] , $ max_width , $ max_height ) ; // Allow devs to filter the final width and height of the media. list ( $ width , $ height ) = apply_filters ( 'hybrid/media/grabber/dimensions' , $ dimensions , // width/height array $ media_atts , // media HTML attributes $ this // media grabber object ) ; // Set up the patterns for the 'width' and 'height' attributes. $ patterns = [ '/(width=[\'"]).+?([\'"])/i' , '/(height=[\'"]).+?([\'"])/i' , '/(<div.+?style=[\'"].*?width:.+?).+?(px;.+?[\'"].*?>)/i' , '/(<div.+?style=[\'"].*?height:.+?).+?(px;.+?[\'"].*?>)/i' ] ; // Set up the replacements for the 'width' and 'height' attributes. $ replacements = [ '${1}' . $ width . '${2}' , '${1}' . $ height . '${2}' , '${1}' . $ width . '${2}' , '${1}' . $ height . '${2}' , ] ; // Filter the dimensions and return the media HTML. return preg_replace ( $ patterns , $ replacements , $ html ) ; }
Method for filtering the media's 'width' and 'height' attributes so
that the theme can handle the dimensions how it sees fit.

@since  5.0.0
@access protected
@param  string  $html
@return string
Method for filtering the media s width and height attributes so that the theme can handle the dimensions how it sees fit .