=== Responsive oEmbed ===
Contributors: palasthotel, greatestview
Donate link: https://palasthotel.de/
Tags: oembed, responsive, aspect ratio, iframe, youtube, vimeo, soundcloud
Requires at least: 4.0
Tested up to: 5.1
Stable tag: 1.4.2
License: GNU General Public License v3
License URI: http://www.gnu.org/licenses/gpl-3.0.html

RETIRED — WordPress handles responsive embeds itself since 5.0. Please deactivate and remove this plugin.

== Description ==

**This plugin is retired and no longer maintained. Please deactivate and remove it.**

WordPress solves this itself since version 5.0. A theme that declares
`add_theme_support( 'responsive-embeds' )` — which every block theme does
automatically — gets responsive embeds from core for content written with the
block editor. Nothing needs to be installed for that.

Worse than being redundant, this plugin conflicts with it. Core wraps an embed
block in `.wp-block-embed__wrapper` and sets the aspect ratio there; this plugin
adds a second wrapper with a second aspect ratio inside it. The result is a
mis-sized embed. That has been the case since WordPress 5.0 and cannot be fixed
from where this plugin hooks, because `WP_Embed::autoembed` runs on `the_content`
at priority 8, before `do_blocks` at priority 9 — the filter never sees whether
it is inside a block.

= What to do instead =

If your site uses the block editor and a block theme, remove the plugin. Core
already handles it.

If you use a classic theme, add `add_theme_support( 'responsive-embeds' )` to it
and use embed blocks.

Core does not cover embeds in classic content or `wp_oembed_get()` calls in a
template. If you rely on those, this is what the plugin did, in a form you can
put into your own theme:

`add_filter( 'embed_oembed_html', 'my_responsive_embed', 99 );
add_filter( 'oembed_result', 'my_responsive_embed', 99 );

function my_responsive_embed( string $html ): string {
	// WordPress post embeds size themselves via wp-embed.js.
	if ( str_contains( $html, 'data-secret=' ) ) {
		return $html;
	}
	if ( ! preg_match( '/<(?:iframe|object|embed)\s[^>]*>/i', $html, $tag ) ) {
		return $html;
	}
	// The value has to end right after the digits, so width="100%" is skipped -
	// a percentage carries no aspect ratio.
	if ( ! preg_match( '/\bwidth=(["\']?)(\d+)\1[\s>]/i', $tag[0], $w )
		|| ! preg_match( '/\bheight=(["\']?)(\d+)\1[\s>]/i', $tag[0], $h ) ) {
		return $html;
	}

	return sprintf(
		'<div class="my-responsive-embed" style="aspect-ratio:%d/%d">%s</div>',
		(int) $w[2],
		(int) $h[2],
		$html
	);
}`

With this CSS:

`.my-responsive-embed { width: 100%; }
.my-responsive-embed > iframe,
.my-responsive-embed > object,
.my-responsive-embed > embed { width: 100%; height: 100%; }`

This uses the `aspect-ratio` CSS property instead of the padding-top trick the
plugin used, and it skips percentage widths — the plugin did not, which is why
SoundCloud embeds came out far too tall.

= What the plugin did =

It used minimal CSS rules and a wrapping HTML element to maintain the aspect
ratio of oEmbed elements with a fixed aspect ratio (e. g. YouTube, Vimeo or
Soundcloud).

Unlike other plugins, this plugin does not use any JavaScript!

The aspect ratio is calculated from the (iframe, object or embed) HTML tag width and height attributes. An aspect ratio will only be applied, if both width AND height attributes are given by the oEmbed element and if there is no data-secret attribut set (because those are handled via wp-embed.js). Some oEmbeds have no width or height attributes set, because they calculate their dimension via JavaScript. In those cases this plugin has no effect.

You can find a [list of all oEmbed sites supported by WordPress here](https://codex.wordpress.org/Embeds#Okay.2C_So_What_Sites_Can_I_Embed_From.3F).

== Installation ==

Please do not install this plugin any more — it is retired. See the description
for what to use instead.

To remove it: deactivate it under Plugins, then delete it. The plugin stores no
options and creates no database tables, so nothing is left behind. Embeds written
with the block editor keep working, because core supplies the CSS for them.

== Upgrade Notice ==

= 1.4.2 =
This plugin is retired. WordPress has handled responsive embeds itself since 5.0,
and this plugin conflicts with that mechanism in the block editor. Please
deactivate and remove it; the description explains what to use instead.

== Changelog ==

= 1.4.2 =
* Final release. The plugin is retired and no longer maintained: WordPress handles responsive embeds itself since 5.0, and this plugin adds a second, conflicting aspect ratio in the block editor. The readme explains what to use instead.

= 1.4.1 =
* WordPress 5.1 compatibility check and readme.txt update.

= 1.4 =
* Exclude WordPress post embeds, because their size is handled via wp-embed.js.

= 1.3 =
* Fixed problem with unexpected margins in frontend and backend.

= 1.2 =
* Changed wrapper HTML tag to div to prevent parsing errors, when there are blockquotes or other p tags inside the oembed code.

= 1.1 =
* Allow any aspect ratios.

= 1.0 =
* First release
