: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
if (preg_match('/\[embed\s*(.*?)\]/i', stripslashes($subject), $m)) {
if (preg_match_all('/(\!?\w+-?\w*)(?:="(.+?)")?/i', stripslashes($m[1]), $matches)) {
$attributes = $matches[1];
$attrValues = $matches[2];
foreach ($attributes as $attrIndex => $attrName) {
$customAttributes[$attrName] = $attrValues[$attrIndex];
return $customAttributes;
* Method that parses and adds the "data-" prefix to the given custom shortcode attributes.
* @param array $customAttributes The array containing the embed attributes.
* @param string $content_uid An optional string specifying a unique ID for the embed
private static function parseContentAttributes(array $customAttributes, $content_uid = null)
'class' => ["embedpress-wrapper ose-embedpress-responsive"],
$embedShouldBeResponsive = true;
$embedShouldHaveCustomDimensions = false;
if (!empty($customAttributes)) {
if (isset($customAttributes['class'])) {
if (!empty($customAttributes['class'])) {
$customAttributes['class'] = explode(' ', $customAttributes['class']);
$attributes['class'] = array_merge($attributes['class'], $customAttributes['class']);
unset($customAttributes['class']);
if (isset($customAttributes['width'])) {
if (!empty($customAttributes['width'])) {
$attributes['width'] = (int) $customAttributes['width'];
$embedShouldHaveCustomDimensions = true;
if (isset($customAttributes['height'])) {
if (!empty($customAttributes['height'])) {
$attributes['height'] = (int) $customAttributes['height'];
$embedShouldHaveCustomDimensions = true;
if (!empty($customAttributes)) {
$attrNameDefaultPrefix = "data-";
foreach ($customAttributes as $attrName => $attrValue) {
if (is_numeric($attrName)) {
$attrName = str_replace($attrNameDefaultPrefix, "", $attrName);
else if (!strlen($attrValue)) {
if ($attrName[0] === "!") {
$attrName = substr($attrName, 1);
$attributes[$attrNameDefaultPrefix . $attrName] = $attrValue;
// Check if there's any "responsive" parameter
$responsiveAttributes = ["responsive", "data-responsive"];
foreach ($responsiveAttributes as $responsiveAttr) {
if (isset($attributes[$responsiveAttr])) {
if (!strlen($attributes[$responsiveAttr])) { // If the parameter is passed but have no value, it will be true by default
$embedShouldBeResponsive = true;
$embedShouldBeResponsive = !self::valueIsFalse($attributes[$responsiveAttr]);
unset($responsiveAttr, $responsiveAttributes);
$attributes['class'][] = 'ose-{provider_alias}';
if (!empty($content_uid)) {
$attributes['class'][] = 'ose-uid-' . $content_uid;
if ($embedShouldBeResponsive && !$embedShouldHaveCustomDimensions) {
$attributes['class'][] = 'responsive';
$attributes['data-responsive'] = "false";
$attributes['class'] = implode(' ', array_unique(array_filter($attributes['class'])));
if (isset($attributes['width'])) {
$height = esc_attr($attributes['height']);
$width = esc_attr($attributes['width']);
$attributes['style'] = "width:{$width}px;height:{$height}px;";
protected static function set_embera_settings(&$attributes)
if (isset($attributes['width']) || isset($attributes['height'])) {
if (isset($attributes['width'])) {
self::$emberaInstanceSettings['maxwidth'] = esc_attr($attributes['width']);
self::$emberaInstanceSettings['width'] = esc_attr($attributes['width']);
unset($attributes['width']);
if (isset($attributes['height'])) {
self::$emberaInstanceSettings['maxheight'] = esc_attr($attributes['height']);
self::$emberaInstanceSettings['height'] = esc_attr($attributes['height']);
unset($attributes['height']);
foreach ($attributes as $key => $value) {
if(strpos($key, 'data-') === 0){
$key = str_replace('data-', '', $key);
self::$emberaInstanceSettings[$key] = $value;
protected static function get_embera_settings()
return self::$emberaInstanceSettings;
public static function get_block_controls_data(){
var_dump(self::$emberaInstanceSettings);
* Method that checks if a given value is/can be identified as (bool)false.
* @param mixed $subject The value to be checked.
public static function valueIsFalse($subject)
$subject = strtolower(trim((string) $subject));
* Return the value from a header which is in an array resulted from a get_headers() call.
* If the header cannot be found, this method will return null instead.
* @param string $headerPattern Regex pattern the header and its value must match.
* @param array $headersList A list of headers resulted from a get_headers() call.
private static function extractContentFromHeaderAsArray($headerPattern, $headersList)
foreach ($headersList as $header) {
if (preg_match($headerPattern, $header, $matches)) {
$headerValue = $matches[1];
* Sanitize the object returned by the embed source. Sometimes we need to convert
* attributes from "dash" separated to "underline" separated to be able to access
* those attributes from the object, without having to convert it to an array.
private static function sanitizeUrlData($data, $url = '')
$attributes = get_object_vars($data);
foreach ($attributes as $key => $value) {
if (substr_count($key, '-') && $key !== $url) {
$key = str_replace('-', '_', $key);
} elseif (is_array($data)) {
foreach ($data as $key => $value) {
if (substr_count($key, '-') && $key !== $url) {
$key = str_replace('-', '_', $key);
public static function get_collection()
return self::$collection;
protected static function purify_html_content(&$html)
if (!class_exists('\simple_html_dom')) {
include_once EMBEDPRESS_PATH_CORE . 'simple_html_dom.php';
$dom = str_get_html($html);
$ifDom = $dom->find('iframe', 0);
if (!empty($ifDom) && is_object($ifDom)) {
$ifDom->removeAttribute('sandbox');
protected static function get_content_from_template($url, $template, $serviceProvider)
if (is_embedpress_pro_active()) {
if (strpos($url, 'podcasts.apple.com')) {
$iframe_url = str_replace('podcasts.apple.com', 'embed.podcasts.apple.com', $url);
$html = '<iframe allow="autoplay *; encrypted-media *; fullscreen *" frameborder="0" height="175" style="width:100%;max-width:660px;overflow:hidden;background:transparent;" src="' . esc_url($iframe_url) . '"></iframe>';
return str_replace('{html}', $html, $template);
if (empty($serviceProvider)) {
$html = self::get_oembed()->get_html($url, self::get_oembed_attributes());
$html = self::get_embera_instance()->autoEmbed($url);
return str_replace('{html}', $html, $template);
protected static function get_oembed_attributes()
return self::$ombed_attributes;
protected static function set_oembed_attributes($atts)
self::$ombed_attributes = $atts;
protected static function check_for_google_url(&$url)
if (preg_match('/http[s]?:\/\/goo\.gl\/(?:([a-z]+)\/)?[a-z0-9]+\/?$/i', $url, $matches)) {
// Fetch all headers from the short-url so we can know how to handle its original content depending on the service.
$headers = get_headers($url);
$supportedServicesHeadersPatterns = [
'maps' => '/^Location:\s+(http[s]?:\/\/.+)$/i',
$service = isset($matches[1]) ? strtolower($matches[1]) : null;
// No specific service was found in the url.
// Let's try to guess which service the original url belongs to.
foreach ($headers as $header) {
// Check if the short-url reffers to a Google Maps url.
if (preg_match($supportedServicesHeadersPatterns['maps'], $header, $matches)) {
// Replace the shortened url with its original url.
// Check if the Google service is supported atm.
if (isset($supportedServicesHeadersPatterns[$service])) {
// Tries to extract the url based on its headers.
$originalUrl = self::extractContentFromHeaderAsArray(
$supportedServicesHeadersPatterns[$service],
// Replace the shortened url with its original url if the specific header was found.
if (!empty($originalUrl)) {
unset($service, $supportedServicesHeadersPatterns, $headers, $matches);
protected static function get_provider_name($urlData, $url)
if (isset($urlData->provider_name)) {
$provider_name = str_replace([' ', ','], '-', strtolower($urlData->provider_name));
} elseif (is_array($urlData) && !empty($urlData)) {
$data = array_shift($urlData);
if (isset($data['provider_name'])) {
$provider_name = str_replace([' ', ','], '-', strtolower($data['provider_name']));
protected static function modify_content_for_fb_and_canada($provider_name, &$html)
if (!empty($provider_name)) {
// NFB seems to always return their embed code with all HTML entities into their applicable characters string.
$PROVIDER_NAME_IN_CAP = strtoupper($provider_name);
if ($PROVIDER_NAME_IN_CAP === "NATIONAL FILM BOARD OF CANADA") {
$html = html_entity_decode($html);
} elseif ($PROVIDER_NAME_IN_CAP === "FACEBOOK") {
$plgSettings = Core::getSettings();
// Check if the user wants to force a certain language into Facebook embeds.
$locale = isset($plgSettings->fbLanguage) && !empty($plgSettings->fbLanguage) ? $plgSettings->fbLanguage : false;
// Replace the automatically detected language by Facebook's API with the language chosen by the user.
'/\/[a-z]{2}\_[a-z]{2}\/sdk\.js/i',
// Make sure `adapt_container_width` parameter is set to false. Setting to true, as it is by default, might cause Facebook to render embeds inside editors (in admin) with only 180px wide.
'~data\-adapt\-container\-width=\"(?:true|1)\"~i',
'data-adapt-container-width="0"',
unset($locale, $plgSettings);
public static function modify_spotify_content($embed)
$should_modify = apply_filters('embedpress_should_modify_spotify', true);
$isSpotify = (isset($embed->provider_name) && strtoupper($embed->provider_name) === 'SPOTIFY') || (isset($embed->url) && isset($embed->{$embed->url}) && isset($embed->{$embed->url}['provider_name']) && strtoupper($embed->{$embed->url}['provider_name']) === 'SPOTIFY');
$should_modify && $isSpotify && isset($embed->embed)
&& preg_match('/src=\"(.+?)\"/', $embed->embed, $match)
$options = (array) get_option(EMBEDPRESS_PLG_NAME . ':spotify');
// Parse the url to retrieve all its info like variables etc.
$modified_url = str_replace('playlist-v2', 'playlist', $url_full);
if (isset($options['theme'])) {
if (strpos($modified_url, '?') !== false) {
$modified_url .= '&theme=' . sanitize_text_field($options['theme']);
$modified_url .= '?theme=' . sanitize_text_field($options['theme']);
// Replaces the old url with the new one.
$embed->embed = str_replace($url_full, $modified_url, $embed->embed);
public static function getParamData($attributes){
'themeMode' => isset($attributes['theme_mode']) ? esc_attr($attributes['theme_mode']) : 'default',
'toolbar' => isset($attributes['toolbar']) ? esc_attr($attributes['toolbar']) : 'true',
'position' => isset($attributes['toolbar_position']) ? esc_attr($attributes['toolbar_position']) : 'top',
'presentation' => isset($attributes['presentation']) ? esc_attr($attributes['presentation']) : 'true',
'download' => isset($attributes['download']) ? esc_attr($attributes['download']) : 'true',
'copy_text' => isset($attributes['copy_text']) ? esc_attr($attributes['copy_text']) : 'true',
'add_text' => isset($attributes['add_text']) ? esc_attr($attributes['add_text']) : 'true',
'draw' => isset($attributes['draw']) ? esc_attr($attributes['draw']) : 'true',
'doc_rotation' => isset($attributes['doc_rotation']) ? esc_attr($attributes['doc_rotation']) : 'true',
'add_image' => isset($attributes['add_image']) ? esc_attr($attributes['add_image']) : 'true',
'doc_details' => isset($attributes['doc_details']) ? esc_attr($attributes['doc_details']) : 'true',
if($urlParamData['themeMode'] == 'custom') {
$urlParamData['customColor'] = isset($attributes['custom_color']) ? esc_attr($attributes['custom_color']) : '#333333';
return "#". http_build_query($urlParamData);
public static function do_shortcode_pdf($attributes = [], $subject = null)
$plgSettings = Core::getSettings();
'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(!empty($plgSettings->pdf_custom_color_settings)){
$default['theme_mode'] = 'custom';
if(isset($default['theme_mode']) && $default['theme_mode'] == 'custom' ){
$default['custom_color'] = esc_attr($plgSettings->custom_color);
$attributes = wp_parse_args($attributes, $default);
'/(\[' . EMBEDPRESS_SHORTCODE . '(?:\]|.+?\])|\[\/' . EMBEDPRESS_SHORTCODE . '\])/i',
$id = 'embedpress-pdf-shortcode';
$dimension = "width: {$attributes['width']}px;height: {$attributes['height']}px";
<div class="embedpress-document-embed ose-document <?php echo 'ep-doc-' . md5($id); ?>" style="<?php echo esc_attr($dimension); ?>; max-width:100%; display: block">
if (self::is_pdf($url) && !self::is_external_url($url)) {
$renderer = Helper::get_pdf_renderer();
$src = $renderer . ((strpos($renderer, '?') == false) ? '?' : '&') . 'file=' . urlencode($url).self::getParamData($attributes);
<iframe title="<?php echo esc_attr(Helper::get_file_title($url)); ?>" allowfullscreen="true" mozallowfullscreen="true" webkitallowfullscreen="true" title="" style="<?php echo esc_attr($dimension); ?>; max-width:100%; display: inline-block" data-emsrc="<?php echo esc_url($url); ?>" data-emid="<?php echo esc_attr($id); ?>" class="embedpress-embed-document-pdf <?php echo esc_attr($id); ?>" src="<?php echo esc_url($src); ?>" frameborder="0"></iframe>