: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
use Embera\ProviderCollection\DefaultProviderCollection;
use EmbedPress\Includes\Classes\Helper;
(defined('ABSPATH') && defined('EMBEDPRESS_IS_LOADED')) or die("No direct script access allowed.");
* Entity responsible to handle the plugin's shortcode events and behaviors.
* @author EmbedPress <help@embedpress.com>
* @copyright Copyright (C) 2023 WPDeveloper. All rights reserved.
* @license GPLv3 or later
* The WP_oEmbed class instance.
* @var WP_oEmbed $oEmbedInstance
private static $oEmbedInstance = null;
* The Embera class instance.
* @var Embera $embera_instance
private static $embera_instance = null;
* The DefaultProviderCollection class instance.
* @var DefaultProviderCollection $collection
private static $collection = null;
private static $emberaInstanceSettings = [];
private static $ombed_attributes;
public static $attributes_data;
* Register the plugin's shortcode into WordPress.
public static function register()
// Register the new shortcode for embeds.
add_shortcode(EMBEDPRESS_SHORTCODE, ['\\EmbedPress\\Shortcode', 'do_shortcode']);
add_shortcode('embed_oembed_html', ['\\EmbedPress\\Shortcode', 'do_shortcode']);
add_shortcode('embedpress', ['\\EmbedPress\\Shortcode', 'do_shortcode']);
add_shortcode('embedpress_pdf', ['\\EmbedPress\\Shortcode', 'do_shortcode_pdf']);
* Method that converts the plugin shortcoded-string into its complex content.
* @param array $attributes Array of attributes
* @param string $subject The given string
public static function do_shortcode($attributes = [], $subject = null)
$plgSettings = Core::getSettings();
if ($plgSettings->enableGlobalEmbedResize) {
'width' => esc_attr($plgSettings->enableEmbedResizeWidth),
'height' => esc_attr($plgSettings->enableEmbedResizeHeight),
'powered_by' => !empty($plgSettings->embedpress_document_powered_by) ? esc_attr($plgSettings->embedpress_document_powered_by) : esc_attr('no'),
if(is_array($attributes)) {
$attributes = array_map('esc_attr', $attributes);
$attributes = wp_parse_args($attributes, $default);
$embed = self::parseContent($subject, true, $attributes);
$array = get_object_vars($embed);
if(!empty($array[$embed->url]['provider_name']) && $array[$embed->url]['provider_name'] === 'Instagram Feed'){
$embed->embed = '<div class="ep-embed-content-wraper insta-grid">' . $embed->embed . '</div>';
return is_object($embed) ? $embed->embed : $embed;
* Replace a given content with its embeded HTML code.
* @param string The raw content that will be replaced.
* @param bool $stripNewLine
* @param array $customAttributes
public static function parseContent($subject, $stripNewLine = false, $customAttributes = [])
if (empty($customAttributes)) {
$customAttributes = self::parseContentAttributesFromString($subject);
self::set_default_size($customAttributes);
'/(\[' . EMBEDPRESS_SHORTCODE . '(?:\]|.+?\])|\[\/' . EMBEDPRESS_SHORTCODE . '\])/i',
$uniqid = 'ose-uid-'.md5($url);
$subject = esc_url($subject);
// Converts any special HTML entities back to characters.
$url = htmlspecialchars_decode($url);
$content_uid = md5($url);
self::$ombed_attributes = self::parseContentAttributes($customAttributes, $content_uid);
self::set_embera_settings(self::$ombed_attributes);
// Identify what service provider the shortcode's link belongs to
$is_embra_provider = apply_filters('embedpress:isEmbra', false, $url, self::get_embera_settings());
if ($is_embra_provider || (strpos($url, 'meetup.com') !== false) || (strpos($url, 'sway.office.com') !== false)) {
$serviceProvider = self::get_oembed()->get_provider($url);
// FIX FOR MEETUP as MEETUP API is OFF, use OUR custom embed
if ('https://api.meetup.com/oembed' === $serviceProvider) {
$urlData = self::get_url_data($url, self::$ombed_attributes, $serviceProvider);
$urlData = self::sanitizeUrlData($urlData, $url);
// Stores the original content
if (is_object($urlData)) {
$urlData->originalContent = $url;
$embedResults = apply_filters('embedpress:onBeforeEmbed', $urlData, $subject);
if (empty($embedResults)) {
// Transform all shortcode attributes into html form. I.e.: {foo: "joe"} -> foo="joe"
$attributesHtml = ['class="ose-{provider_alias} ' . $uniqid .' ose-embedpress-responsive"'];
//foreach ( self::$ombed_attributes as $attrName => $attrValue ) {
// $attributesHtml[] = $attrName . '="' . $attrValue . '"';
if (isset($customAttributes['height'])) {
$height = esc_attr($customAttributes['height']);
if (isset($customAttributes['width'])) {
$width = esc_attr($customAttributes['width']);
$attributesHtml[] = "style=\"width:{$width}px; height:{$height}px; max-height:{$height}px; max-width:100%; display:inline-block;\"";
// Check if $url is a google shortened url and tries to extract from it which Google service it refers to.
self::check_for_google_url($url);
$provider_name = self::get_provider_name($urlData, $url);
// if (strpos($url, 'youtube') !== false) {
// $html = '<div class="youtube-video">{html}</div>';
$embedTemplate = '<div ' . implode(' ', $attributesHtml) . '>{html}</div>';
$parsedContent = self::get_content_from_template($url, $embedTemplate, $serviceProvider);
// Replace all single quotes to double quotes. I.e: foo='joe' -> foo="joe"
$parsedContent = str_replace("'", '"', $parsedContent);
$parsedContent = str_replace("{provider_alias}", $provider_name, $parsedContent);
$parsedContent = str_replace('sandbox="allow-scripts"', 'sandbox="allow-modals allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox"', $parsedContent);
$parsedContent = str_replace('<iframe ', '<iframe allowFullScreen="true" ', $parsedContent);
self::purify_html_content($parsedContent);
self::modify_content_for_fb_and_canada($provider_name, $parsedContent);
unset($embedTemplate, $serviceProvider);
// This assure that the iframe has the same dimensions the user wants to
if (isset(self::$emberaInstanceSettings['maxwidth']) || isset(self::$emberaInstanceSettings['maxheight'])) {
if (isset(self::$emberaInstanceSettings['maxwidth']) && isset(self::$emberaInstanceSettings['maxheight'])) {
$customWidth = (int) self::$emberaInstanceSettings['maxwidth'];
$customHeight = (int) self::$emberaInstanceSettings['maxheight'];
if (preg_match('~width="(\d+)"|width\s+:\s+(\d+)~i', $parsedContent, $matches)) {
$iframeWidth = (int) $matches[1];
if (preg_match('~height="(\d+)"|height\s+:\s+(\d+)~i', $parsedContent, $matches)) {
$iframeHeight = (int) $matches[1];
if (isset($iframeWidth) && isset($iframeHeight) && $iframeWidth > 0 && $iframeHeight > 0) {
$iframeRatio = ceil($iframeWidth / $iframeHeight);
if (isset(self::$emberaInstanceSettings['maxwidth'])) {
$customWidth = (int) self::$emberaInstanceSettings['maxwidth'];
$customHeight = ceil($customWidth / $iframeRatio);
$customHeight = (int) self::$emberaInstanceSettings['maxheight'];
$customWidth = $iframeRatio * $customHeight;
if (isset($customWidth) && isset($customHeight)) {
if (preg_match('~width="(\d+)"~i', $parsedContent)) {
$parsedContent = preg_replace(
'width="' . esc_attr($customWidth) . '"',
} elseif (preg_match('~width="({.+})"~i', $parsedContent)) {
// this block was needed for twitch that has width="{width}" in iframe
$parsedContent = preg_replace(
'width="' . esc_attr($customWidth) . '"',
if (preg_match('~height="(\d+)"~i', $parsedContent)) {
$parsedContent = preg_replace(
'height="' . esc_attr($customHeight) . '"',
} elseif (preg_match('~height="({.+})"~i', $parsedContent)) {
$parsedContent = preg_replace(
'height="' . esc_attr($customHeight) . '"',
if (preg_match('~width\s+:\s+(\d+)~i', $parsedContent)) {
$parsedContent = preg_replace(
'width: ' . esc_attr($customWidth),
if (preg_match('~height\s+:\s+(\d+)~i', $parsedContent)) {
$parsedContent = preg_replace(
'height: ' . esc_attr($customHeight),
if ('gfycat' === $provider_name && preg_match('~height\s*:\s*auto\s*;~i', $parsedContent)) {
$parsedContent = preg_replace(
'~height\s*:\s*auto\s*~i',
'height: ' . esc_attr($customHeight) . 'px',
$parsedContent = preg_replace(
'~style="position:relative;padding-bottom(.+?)"~i',
.ose-gfycat.ose-embedpress-responsive{
$parsedContent = $styles . $parsedContent;
if ('the-new-york-times' === $provider_name && isset($customAttributes['height']) && isset($customAttributes['width'])) {
$height = $customAttributes['height'];
$width = $customAttributes['width'];
.ose-the-new-york-times iframe{
$styles = str_replace(['{height}', '{width}'], [esc_attr($height), esc_attr($width)], $styles);
$parsedContent = $styles . $parsedContent;
$parsedContent = preg_replace('/\n/', '', $parsedContent);
$parsedContent = apply_filters('pp_embed_parsed_content', $parsedContent, $urlData, self::get_oembed_attributes());
if (!empty($parsedContent)) {
$embed = (object) array_merge((array) $urlData, [
'attributes' => (object) self::get_oembed_attributes(),
'embed' => $parsedContent,
$embed = self::modify_spotify_content($embed);
$embed = apply_filters('embedpress:onAfterEmbed', $embed);
$attributesToRemove = 'autoplay;';
$newAttribute = 'encrypted-media;'.'accelerometer;'.'autoplay;'.'clipboard-write;'.'gyroscope;'.'picture-in-picture';
// Remove existing attributes
$embed->embed = str_replace($attributesToRemove, $newAttribute, $embed->embed);
protected static function get_oembed()
if (!self::$oEmbedInstance) {
if (version_compare($wp_version, '5.3.0', '>=')) {
require_once ABSPATH . 'wp-includes/class-wp-oembed.php';
require_once ABSPATH . 'wp-includes/class-oembed.php';
self::$oEmbedInstance = _wp_oembed_get_object();
return self::$oEmbedInstance;
protected static function set_default_size(&$customAttributes)
$plgSettings = Core::getSettings();
if (empty($customAttributes['width'])) {
$customAttributes['width'] = !empty($plgSettings->enableEmbedResizeWidth) ? esc_attr($plgSettings->enableEmbedResizeWidth) : 600;
if (empty($customAttributes['height'])) {
$customAttributes['height'] = !empty($plgSettings->enableEmbedResizeHeight) ? esc_attr($plgSettings->enableEmbedResizeHeight) : 550;
protected static function get_url_data($url, $attributes = [], $serviceProvider = '')
if (!empty($serviceProvider)) {
$urlData = self::get_oembed()->fetch($serviceProvider, $url, $attributes);
$urlData = self::get_embera_instance()->getUrlData($url);
// self::$attributes_data = self::$ombed_attributes;
public static function getAttributesData(){
self::$attributes_data = self::get_oembed_attributes();
// return self::get_oembed_attributes();
return self::$attributes_data;
public static function get_embera_instance()
if (!self::$embera_instance) {
$additionalServiceProviders = Core::getAdditionalServiceProviders();
if (!empty($additionalServiceProviders)) {
foreach ($additionalServiceProviders as $serviceProviderClassName => $serviceProviderUrls) {
self::addServiceProvider($serviceProviderClassName, $serviceProviderUrls);
unset($serviceProviderUrls, $serviceProviderClassName);
self::$embera_instance = new Embera(self::get_embera_settings(), self::get_collection());
self::$embera_instance->setConfig(self::get_embera_settings());
return self::$embera_instance;
* Method that adds support to a given new service provider (SP).
* @param string $className The new SP class name.
* @param string $reference The new SP reference name.*
* @return DefaultProviderCollection|bool
public static function addServiceProvider($className, $reference)
if (empty($className) || empty($reference)) {
if (is_null(self::$collection)) {
self::$collection = new DefaultProviderCollection();
if (is_string($reference)) {
self::$collection->addProvider($reference, $className);
return self::$collection;
} elseif (is_array($reference)) {
foreach ($reference as $serviceProviderUrl) {
self::addServiceProvider($className, $serviceProviderUrl);
return self::$collection;
* Method that retrieves all custom parameters from a shortcoded string.
* @param string $subject The given shortcoded string.
public static function parseContentAttributesFromString($subject)