: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
namespace EmbedPress\Includes\Classes;
use \EmbedPress\Providers\Youtube;
use EmbedPress\Shortcode;
use EmbedPress\Includes\Classes\Helper;
use \Elementor\Controls_Manager;
use EmbedPress\Providers\TikTok;
use EmbedPress\Providers\Wrapper;
public static $attributes_data;
public function __construct()
add_filter('embedpress:onAfterEmbed', [$this, 'enhance_youtube'], 90);
add_filter('embedpress:onAfterEmbed', [$this, 'enhance_vimeo'], 90);
add_filter('embedpress:onAfterEmbed', [$this, 'enhance_wistia'], 90);
add_filter('embedpress:onAfterEmbed', [$this, 'enhance_twitch'], 90);
add_filter('embedpress:onAfterEmbed', [$this, 'enhance_dailymotion'], 90);
add_filter('embedpress:onAfterEmbed', [$this, 'enhance_soundcloud'], 90);
add_filter('embedpress:onAfterEmbed', [$this, 'enhance_missing_title'], 90);
'embedpress_gutenberg_youtube_params',
[$this, 'embedpress_gutenberg_register_block_youtube']
add_action('init', array($this, 'embedpress_gutenberg_register_block_vimeo'));
add_action('embedpress_gutenberg_wistia_block_after_embed', array($this, 'embedpress_wistia_block_after_embed'));
add_action('elementor/widget/embedpres_elementor/skins_init', [$this, 'elementor_setting_init']);
add_action('wp_ajax_youtube_rest_api', [$this, 'youtube_rest_api']);
add_action('wp_ajax_nopriv_youtube_rest_api', [$this, 'youtube_rest_api']);
add_action('embedpress_gutenberg_embed', [$this, 'gutenberg_embed'], 10, 2);
add_action('wp_ajax_save_source_data', [$this, 'save_source_data']);
add_action('save_post', [$this, 'save_source_data_on_post_update'], 10, 3);
add_action('wp_ajax_delete_source_data', [$this, 'delete_source_data']);
add_action('load-post.php', [$this, 'delete_source_temp_data_on_reload']);
add_action('embedpress:isEmbra', [$this, 'isEmbra'], 10, 3);
add_action('elementor/editor/after_save', [$this, 'save_el_source_data_on_post_update']);
add_action('wp_head', [$this, 'embedpress_generate_social_share_meta']);
add_action('wp_ajax_get_viewer', function () {
$pdf = EMBEDPRESS_PATH_BASE . 'assets/pdf/web/viewer.html';
header('Content-Type: text/html');
$contents = file_get_contents($pdf);
echo str_replace('<head>', '<head><base href="' . EMBEDPRESS_URL_ASSETS . 'pdf/web/' . '">', $contents);
add_action('wp_ajax_nopriv_get_viewer', function () {
$pdf = EMBEDPRESS_PATH_BASE . 'assets/pdf/web/viewer.html';
header('Content-Type: text/html');
$contents = file_get_contents($pdf);
echo str_replace('<head>', '<head><base href="' . EMBEDPRESS_URL_ASSETS . 'pdf/web/' . '">', $contents);
public function save_source_data()
if (!isset($_POST['_source_nonce']) || !wp_verify_nonce($_POST['_source_nonce'], 'source_nonce_embedpress')) {
if (!current_user_can('manage_options')) {
$source_url = isset($_POST['source_url']) ? $_POST['source_url'] : null;
$blockid = isset($_POST['block_id']) ? $_POST['block_id'] : null;
Helper::get_source_data($blockid, $source_url, 'gutenberg_source_data', 'gutenberg_temp_source_data');
function save_el_source_data_on_post_update($post_id)
Helper::get_save_source_data_on_post_update('elementor_source_data', 'elementor_temp_source_data');
function save_source_data_on_post_update($post_id, $post, $update)
if (!empty(strpos($post->post_content, 'wp:embedpress'))) {
Helper::get_save_source_data_on_post_update('gutenberg_source_data', 'gutenberg_temp_source_data');
public function delete_source_data()
if (!isset($_POST['_source_nonce']) || !wp_verify_nonce($_POST['_source_nonce'], 'source_nonce_embedpress')) {
if (!current_user_can('manage_options')) {
$blockid = isset($_POST['block_id']) ? $_POST['block_id'] : '';
Helper::get_delete_source_data($blockid, 'gutenberg_source_data', 'gutenberg_temp_source_data');
public function delete_source_temp_data_on_reload()
Helper::get_delete_source_temp_data_on_reload('gutenberg_temp_source_data');
public function isEmbra($isEmbra, $url, $atts)
if (strpos($url, 'youtube.com') !== false) {
$youtube = new Youtube($url, $atts);
if ($youtube->validateUrl($youtube->getUrl(false))) {
if (strpos($url, 'tiktok.com') !== false) {
$tiktok = new TikTok($url, $atts);
if ($tiktok->validateUrl($tiktok->getUrl(false))) {
if (strpos($url, site_url()) !== false) {
$wrapper = new Wrapper($url, $atts);
if ($wrapper->validateUrl($wrapper->getUrl(false))) {
public function youtube_rest_api()
$result = Youtube::get_gallery_page([
'playlistId' => isset($_POST['playlistid']) ? sanitize_text_field($_POST['playlistid']) : null,
'pageToken' => isset($_POST['pagetoken']) ? sanitize_text_field($_POST['pagetoken']) : null,
'pagesize' => isset($_POST['pagesize']) ? sanitize_text_field($_POST['pagesize']) : null,
'currentpage' => isset($_POST['currentpage']) ? sanitize_text_field($_POST['currentpage']) : null,
'columns' => isset($_POST['epcolumns']) ? sanitize_text_field($_POST['epcolumns']) : null,
'showTitle' => isset($_POST['showtitle']) ? sanitize_text_field($_POST['showtitle']) : null,
'showPaging' => isset($_POST['showpaging']) ? sanitize_text_field($_POST['showpaging']) : null,
'autonext' => isset($_POST['autonext']) ? sanitize_text_field($_POST['autonext']) : null,
'thumbplay' => isset($_POST['thumbplay']) ? sanitize_text_field($_POST['thumbplay']) : null,
'thumbnail_quality' => isset($_POST['thumbnail_quality']) ? sanitize_text_field($_POST['thumbnail_quality']) : null,
//Check is YouTube single video
public function ytValidateUrl($url)
return (bool) (preg_match('~v=(?:[a-z0-9_\-]+)~i', (string) $url));
//Check is YouTube live video
public function ytValidateLiveUrl($url)
return (bool) (preg_match('/^https?:\/\/(?:www\.)?youtube\.com\/(?:channel\/[\w-]+|@[\w-]+)\/live$/', (string) $url));
//Check is Wistia validate url
public function wistiaValidateUrl($url)
return (bool) (preg_match('#\/medias\\\?\/([a-z0-9]+)\.?#i', (string) $url));
//Check is Wistia validate url
public function vimeoValidateUrl($url)
return (bool) preg_match('/https?:\/\/(www\.)?vimeo\.com\/\d+/', (string) $url);
// Get wistia block attributes
public function get_wistia_block_attributes($attributes)
$embedOptions = new \stdClass;
$embedOptions->videoFoam = false;
$embedOptions->fullscreenButton = (isset($attributes['wfullscreen']) && (bool) $attributes['wfullscreen'] === true);
$embedOptions->playbar = (isset($attributes['playbar']) && (bool) $attributes['playbar'] === true);
$embedOptions->playButton = (isset($attributes['playbutton']) && (bool) $attributes['playbutton'] === true);
$embedOptions->smallPlayButton = (isset($attributes['smallplaybutton']) && (bool) $attributes['smallplaybutton'] === true);
$embedOptions->autoPlay = (isset($attributes['wautoplay']) && (bool) $attributes['wautoplay'] === true);
$embedOptions->resumable = (isset($attributes['resumable']) && (bool) $attributes['resumable'] === true);
if (!empty($attributes['wstarttime'])) {
$embedOptions->time = isset($attributes['wstarttime']) ? $attributes['wstarttime'] : '';
if (is_embedpress_pro_active()) {
$embedOptions->volumeControl = (isset($attributes['volumecontrol']) && (bool) $attributes['volumecontrol'] === true);
$volume = isset($attributes['volume']) ? (float) $attributes['volume'] : 0;
$embedOptions->volume = $volume;
if (isset($attributes['scheme'])) {
$color = $attributes['scheme'];
$embedOptions->playerColor = $color;
// Closed Captions plugin
if ($attributes['captions'] === true) {
$isCaptionsEnabled = ($attributes['captions'] === true);
$isCaptionsEnabledByDefault = ($attributes['captions'] === true);
if ($isCaptionsEnabled) {
$pluginList['captions-v1'] = [
'onByDefault' => $isCaptionsEnabledByDefault,
$embedOptions->captions = $isCaptionsEnabled;
$embedOptions->captionsDefault = $isCaptionsEnabledByDefault;
$embedOptions->plugin = $pluginList;
return json_encode($embedOptions);
public function gutenberg_embed($embedHTML, $attributes)
if (!empty($attributes['url'])) {
$youtube = new Youtube($attributes['url']);
$is_youtube = $youtube->validateUrl($youtube->getUrl(false));
if ($is_youtube && empty($this->ytValidateLiveUrl($attributes['url']))) {
'width' => intval($attributes['width']),
'height' => intval($attributes['height']),
'pagesize' => isset($attributes['pagesize']) ? intval($attributes['pagesize']) : 6,
'columns' => isset($attributes['columns']) ? intval($attributes['columns']) : 3,
'ispagination' => isset($attributes['ispagination']) ? $attributes['ispagination'] : 0,
'gapbetweenvideos' => isset($attributes['gapbetweenvideos']) ? $attributes['gapbetweenvideos'] : 30,
$urlInfo = Shortcode::parseContent($attributes['url'], true, $atts);
if (!empty($urlInfo->embed)) {
$embedHTML = $urlInfo->embed;
if (!empty($attributes['url']) && ($this->ytValidateUrl($attributes['url']) || $this->ytValidateLiveUrl($attributes['url']))) {
'url' => $attributes['url'],
'starttime' => !empty($attributes['starttime']) ? $attributes['starttime'] : '',
'endtime' => !empty($attributes['endtime']) ? $attributes['endtime'] : '',
'autoplay' => !empty($attributes['autoplay']) ? 1 : 0,
'controls' => isset($attributes['controls']) ? $attributes['controls'] : '1',
'fullscreen' => !empty($attributes['fullscreen']) ? 1 : 0,
'videoannotations' => !empty($attributes['videoannotations']) ? 1 : 0,
'progressbarcolor' => !empty($attributes['progressbarcolor']) ? $attributes['progressbarcolor'] : 'red',
'closedcaptions' => !empty($attributes['closedcaptions']) ? 1 : 0,
'modestbranding' => !empty($attributes['modestbranding']) ? $attributes['modestbranding'] : '',
'relatedvideos' => !empty($attributes['relatedvideos']) ? 1 : 0,
'customlogo' => !empty($attributes['customlogo']) ? $attributes['customlogo'] : '',
'logoX' => !empty($attributes['logoX']) ? $attributes['logoX'] : 5,
'logoY' => !empty($attributes['logoY']) ? $attributes['logoY'] : 10,
'customlogoUrl' => !empty($attributes['customlogoUrl']) ? $attributes['customlogoUrl'] : '',
'logoOpacity' => !empty($attributes['logoOpacity']) ? $attributes['logoOpacity'] : 0.6,
$urlInfo = Shortcode::parseContent($attributes['url'], true, $atts);
if (!empty($urlInfo->embed)) {
$embedHTML = $urlInfo->embed;
if (isset($urlInfo->embed) && preg_match('/src=\"(.+?)\"/', $urlInfo->embed, $match)) {
$query = parse_url($url_full, PHP_URL_QUERY);
parse_str($query ?? '', $params);
$params['controls'] = isset($attributes['controls']) ? $attributes['controls'] : '1';
$params['iv_load_policy'] = !empty($attributes['videoannotations']) ? 1 : 0;
$params['fs'] = !empty($attributes['fullscreen']) ? 1 : 0;
$params['rel'] = !empty($attributes['relatedvideos']) ? 1 : 0;
$params['end'] = !empty($attributes['endtime']) ? $attributes['endtime'] : '';
$params['autoplay'] = !empty($attributes['autoplay']) ? 1 : 0;
$params['start'] = !empty($attributes['starttime']) ? $attributes['starttime'] : '';
$params['color'] = !empty($attributes['progressbarcolor']) ? $attributes['progressbarcolor'] : 'red';
$params['modestbranding'] = empty($attributes['modestbranding']) ? 0 : 1; // Reverse the condition value for modestbranding. 0 = display, 1 = do not display
$params['cc_load_policy'] = !empty($attributes['closedcaptions']) ? 0 : 1;
preg_match('/(.+)?\?/', $url_full, $url);
// Reassemble the url with the new variables.
$url_modified = $url . '?';
foreach ($params as $paramName => $paramValue) {
if (array_key_last($params) === $paramName) {
if (isset($paramValue) && $paramValue !== '') {
$url_modified .= $paramName . '=' . $paramValue . $and;
// Replaces the old url with the new one.
$embedHTML = str_replace($url_full, rtrim($url_modified, '&'), $urlInfo->embed);
if (!empty($attributes['url']) && $this->wistiaValidateUrl($attributes['url'])) {
$embedOptions = $this->get_wistia_block_attributes($attributes);
$videoId = $this->getVideoIDFromURL($attributes['url']);
$shortVideoId = substr($videoId, 0, 3);
'wistia_async_' . $videoId
sprintf('id="wistia_%s"', $videoId),
sprintf('class="%s"', join(' ', $class)),
sprintf('style="width:%spx; height:%spx;"', $attributes['width'], $attributes['height'])
'watch_from_beginning' => __('Watch from the beginning', 'embedpress'),
'skip_to_where_you_left_off' => __('Skip to where you left off', 'embedpress'),
'you_have_watched_it_before' => __(
'It looks like you\'ve watched<br />part of this video before!',
$labels = json_encode($labels);
preg_match('/ose-uid-([a-z0-9]*)/', $attributes['embedHTML'], $matches);
$html = "<div class=\"embedpress-wrapper ose-wistia ose-uid-{$uid} responsive\">";
$html .= '<script src="https://fast.wistia.com/assets/external/E-v1.js" async></script>';
$html .= "<script>window.pp_embed_wistia_labels = {$labels};</script>\n";
$html .= "<script>window._wq = window._wq || []; _wq.push({\"{$shortVideoId}\": {$embedOptions}});</script>\n";
$html .= '<div ' . join(' ', $attribs) . "></div>\n";
if (!empty($attributes['url']) && $this->vimeoValidateUrl($attributes['url'])) {
'url' => $attributes['url'],
'vstarttime' => !empty($attributes['vstarttime']) ? $attributes['vstarttime'] : '',
'vscheme' => !empty($attributes['vscheme']) ? $attributes['vscheme'] : 'red',
'vautoplay' => !empty($attributes['vautoplay']) ? 1 : 0,
'vtitle' => !empty($attributes['vtitle']) ? 1 : 0,
'vauthor' => !empty($attributes['vauthor']) ? 1 : 0,
'vavatar' => !empty($attributes['vavatar']) ? 1 : 0,
'vautopause' => !empty($attributes['vautopause']) ? 1 : 0,
'vdnt' => !empty($attributes['vdnt']) ? 1 : 0,
'customlogo' => !empty($attributes['customlogo']) ? $attributes['customlogo'] : '',
'logoX' => !empty($attributes['logoX']) ? $attributes['logoX'] : 5,
'logoY' => !empty($attributes['logoY']) ? $attributes['logoY'] : 10,
'customlogoUrl' => !empty($attributes['customlogoUrl']) ? $attributes['customlogoUrl'] : '',
'logoOpacity' => !empty($attributes['logoOpacity']) ? $attributes['logoOpacity'] : 0.6,
$urlInfo = Shortcode::parseContent($attributes['url'], true, $atts);
if (!empty($urlInfo->embed)) {
$embedHTML = $urlInfo->embed;
if (isset($urlInfo->embed) && preg_match('/src=\"(.+?)\"/', $urlInfo->embed, $match)) {
$query = parse_url($url_full, PHP_URL_QUERY);
parse_str($query, $params);
unset($params['amp;dnt']);
$params['title'] = !empty($attributes['vtitle']) ? 1 : 0;
$params['byline'] = !empty($attributes['vauthor']) ? 1 : 0;
$params['portrait'] = !empty($attributes['vavatar']) ? 1 : 0;
$params['autoplay'] = !empty($attributes['vautoplay']) ? 1 : 0;
$params['loop'] = !empty($attributes['vloop']) ? 1 : 0;
$params['autopause'] = !empty($attributes['vautopause']) ? 1 : 0;
if (empty($attributes['vautopause'])) :
$params['dnt'] = !empty($attributes['vdnt']) ? 1 : 0;
$params['color'] = !empty($attributes['vscheme']) ? str_replace("#", "", $attributes['vscheme']) : '00ADEF';
if (!empty($attributes['vstarttime'])) :
$params['t'] = !empty($attributes['vstarttime']) ? $attributes['vstarttime'] : '';
preg_match('/(.+)?\?/', $url_full, $url);
// Reassemble the url with the new variables.
$url_modified = $url . '?';
// print_r($url_modified);
foreach ($params as $param => $value) {
$url_modified = add_query_arg($param, $value, $url_modified);
$url_modified = str_replace("&t=", "#t=", $url_modified);
// Replaces the old url with the new one.
$embedHTML = str_replace($url_full, rtrim($url_modified, '&'), $urlInfo->embed);
public function elementor_setting_init()
$this->remove_classic_filters();
add_filter('embedpress_elementor_embed', [Elementor_Enhancer::class, 'youtube'], 10, 2);
add_filter('embedpress_elementor_embed', [Elementor_Enhancer::class, 'wistia'], 10, 2);
add_filter('embedpress_elementor_embed', [Elementor_Enhancer::class, 'twitch'], 10, 2);
add_filter('embedpress_elementor_embed', [Elementor_Enhancer::class, 'soundcloud'], 10, 2);
add_filter('embedpress_elementor_embed', [Elementor_Enhancer::class, 'dailymotion'], 10, 2);
add_filter('embedpress_elementor_embed', [Elementor_Enhancer::class, 'spotify'], 10, 2);
add_filter('embedpress_elementor_embed', [Elementor_Enhancer::class, 'vimeo'], 10, 2);
public function remove_classic_filters()
remove_filter('embedpress:onAfterEmbed', [$this, 'enhance_youtube'], 90);
remove_filter('embedpress:onAfterEmbed', [$this, 'enhance_vimeo'], 90);
remove_filter('embedpress:onAfterEmbed', [$this, 'enhance_wistia'], 90);
remove_filter('embedpress:onAfterEmbed', [$this, 'enhance_twitch'], 90);
remove_filter('embedpress:onAfterEmbed', [$this, 'enhance_dailymotion'], 90);
remove_filter('embedpress:onAfterEmbed', [$this, 'enhance_soundcloud'], 90);
public function getOptions($provider = '', $schema = [])
$options = (array) get_option(EMBEDPRESS_PLG_NAME . ':' . $provider, []);
if (empty($options) || (count($options) === 1 && empty($options[0]))) {
foreach ($schema as $fieldSlug => $field) {
$value = isset($field['default']) ? $field['default'] : "";
settype($value, isset($field['type']) && in_array(
strtolower($field['type']),
['bool', 'boolean', 'int', 'integer', 'float', 'string']
) ? $field['type'] : 'string');
if ($fieldSlug === "license_key") {
$options[$fieldSlug] = $value;