: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* @author EmbedPress <help@embedpress.com>
* @copyright Copyright (C) 2023 EmbedPress. All rights reserved.
* @license GPLv2 or later
// function equivalent to jquery ready()
if (document.readyState !== 'loading') {
document.addEventListener('DOMContentLoaded', fn);
let selector = document.querySelectorAll('.embedpress-embed-document-pdf');
selector.forEach((function (value, index, thisArg) {
let id = value.dataset['emid'];
let src = value.dataset['emsrc'];
PDFObject?.embed(src, "." + id, option);
if (typeof epGlobals.youtubeChannelGallery === 'function') {
epGlobals.youtubeChannelGallery();
* Make embeds responsive so they don't overflow their container.
* Add max-width & max-height to <iframe> elements, depending on their width & height props.
function embedPressResponsiveEmbeds() {
var proportion, parentWidth;
document.querySelectorAll('iframe').forEach(function (iframe) {
// Only continue if the iframe has a width & height defined.
if (iframe.width && iframe.height) {
// Calculate the proportion/ratio based on the width & height.
proportion = parseFloat(iframe.width) / parseFloat(iframe.height);
// Get the parent element's width.
parentWidth = parseFloat(window.getComputedStyle(iframe.parentElement, null).width.replace('px', ''));
// Set the max-width & height.
iframe.style.maxWidth = '100%';
iframe.style.maxHeight = Math.round(parentWidth / proportion).toString() + 'px';
epGlobals.handlePosterImageLoad = function () {
var posterImages = document.querySelectorAll(".plyr__poster");
posterImages.forEach(function (posterImage) {
var videoWrappers = document.querySelectorAll("[data-playerid]");
videoWrappers.forEach(function (videoWrapper) {
var observer = new MutationObserver(function (mutationsList, observer) {
var posterImageStyle = window.getComputedStyle(posterImage);
if (posterImageStyle.getPropertyValue('background-image') !== 'none') {
videoWrapper.style.opacity = "1";
observer.observe(posterImage, { attributes: true, attributeFilter: ['style'] });
embedPressResponsiveEmbeds();
window.onresize = embedPressResponsiveEmbeds;
function hasClass(ele, cls) {
return !!ele.className.match(new RegExp("(\\s|^)" + cls + "(\\s|$)"));
function addClass(ele, cls) {
if (!hasClass(ele, cls)) ele.className += " " + cls;
function removeClass(ele, cls) {
if (hasClass(ele, cls)) {
var reg = new RegExp("(\\s|^)" + cls + "(\\s|$)");
ele.className = ele.className.replace(reg, " ");
if (!Element.prototype.matches) {
Element.prototype.matches =
Element.prototype.matchesSelector ||
Element.prototype.webkitMatchesSelector ||
Element.prototype.mozMatchesSelector ||
Element.prototype.msMatchesSelector ||
Element.prototype.oMatchesSelector ||
var matches = (this.document || this.ownerDocument).querySelectorAll(s),
while (--i >= 0 && matches.item(i) !== this) { }
var delegate = function (el, evt, sel, handler) {
el.addEventListener(evt, function (event) {
while (t && t !== this) {
function sendRequest(url, postData, callback) {
var req = createXMLHTTPObject();
var method = postData ? "POST" : "GET";
req.open(method, url, true);
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
req.onreadystatechange = function () {
if (req.readyState != 4) return;
if (req.status != 200 && req.status != 304) {
if (req.readyState == 4) return;
return new XMLHttpRequest();
return new ActiveXObject("Msxml3.XMLHTTP");
return new ActiveXObject("Msxml2.XMLHTTP.6.0");
return new ActiveXObject("Msxml2.XMLHTTP.3.0");
return new ActiveXObject("Msxml2.XMLHTTP");
return new ActiveXObject("Microsoft.XMLHTTP");
function createXMLHTTPObject() {
for (var i = 0; i < XMLHttpFactories.length; i++) {
xmlhttp = XMLHttpFactories[i]();
epGlobals.youtubeChannelGallery = function () {
var playerWraps = document.getElementsByClassName("ep-player-wrap");
if (playerWraps && playerWraps.length) {
for (var i = 0, im = playerWraps.length; im > i; i++) {
youtubeChannelEvents(playerWraps[i])
function youtubeChannelEvents(playerWrap) {
delegate(playerWrap, "click", ".item", function (event) {
var embed = "https://www.youtube.com/embed/";
var vid = this.getAttribute("data-vid");
var iframe = playerWrap.getElementsByTagName("iframe");
var vidSrc = iframe[0].src.replace(/(.*\/embed\/)([^\?&"'>]+)(.+)?/, `\$1${vid}\$3`);
if (vidSrc.indexOf('autoplay') > 0) {
vidSrc = vidSrc.replace('autoplay=0', 'autoplay=1');
playerWrap.scrollIntoView();
let nearestEpContentId = playerWrap.querySelector('.ep-youtube__content__block').getAttribute('data-unique-id');
delegate(playerWrap, "click", ".ep-next, .ep-prev", function (event) {
const totalPages = event.target.closest('.ose-youtube').getAttribute('data-total-pages');
const closestClass = event.target.closest('.ose-youtube').classList;
const activePage = document.querySelector(`.${closestClass[1]} .embedpress-page-active`);
document.querySelector(`.${closestClass[1]} .embedpress-page-active`).classList.remove('embedpress-page-active');
var isNext = this.classList.contains("ep-next");
action: "youtube_rest_api",
playlistid: this.getAttribute("data-playlistid"),
pagetoken: this.getAttribute("data-pagetoken"),
pagesize: this.getAttribute("data-pagesize"),
for (var property in data) {
var encodedKey = encodeURIComponent(property);
var encodedValue = encodeURIComponent(data[property]);
formBody.push(encodedKey + "=" + encodedValue);
formBody = formBody.join("&");
var galleryWrapper = playerWrap.getElementsByClassName(
"ep-youtube__content__block"
playerWrap.setAttribute('data-current-page', currentPage);
sendRequest("/wp-admin/admin-ajax.php", formBody, function (request) {
if (galleryWrapper && galleryWrapper[0] && request.responseText) {
var response = JSON.parse(request.responseText);
galleryWrapper[0].outerHTML = response.html;
galleryWrapper[0].getElementsByClassName("current-page");
if (currentPageNode && currentPageNode[0]) {
currentPageNode[0].textContent = currentPage;
const intervalID = setInterval(() => {
if (playerWrap.querySelector('.ep-youtube__content__block')) {
const newNearestEpContentId = playerWrap
.querySelector('.ep-youtube__content__block')
.getAttribute('data-unique-id');
if (newNearestEpContentId !== nearestEpContentId && playerWrap.querySelector(`[data-page="${currentPage}"]`)) {
playerWrap.querySelector(`[data-page="${currentPage}"]`).classList.add('embedpress-page-active');
nearestEpContentId = newNearestEpContentId;
clearInterval(intervalID);
clearInterval(intervalID);
//Load more for OpenaSea collection
const epLoadMore = () => {
$('.embedpress-gutenberg-wrapper .ep-nft-gallery-wrapper').each(function () {
let selctorEl = `[data-nftid='${$(this).data('nftid')}']`;
let loadmorelabel = $(selctorEl).data('loadmorelabel');
let iconcolor = $(selctorEl + " .nft-loadmore").data('iconcolor');
let spinicon = `<svg width="18" height="18" fill="${iconcolor || '#fff'}" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><style>.spinner_GuJz{transform-origin:center;animation:spinner_STY6 1.5s linear infinite}@keyframes spinner_STY6{100%{transform:rotate(360deg)}}</style><g class="spinner_GuJz"><circle cx="3" cy="12" r="2"/><circle cx="21" cy="12" r="2"/><circle cx="12" cy="21" r="2"/><circle cx="12" cy="3" r="2"/><circle cx="5.64" cy="5.64" r="2"/><circle cx="18.36" cy="18.36" r="2"/><circle cx="5.64" cy="18.36" r="2"/><circle cx="18.36" cy="5.64" r="2"/></g></svg>`;
$(selctorEl + ` .ep_nft_item`).slice(0, $(selctorEl).data('itemparpage')).show();
$('.embedpress-gutenberg-wrapper .ep-nft-gallery-wrapper .ep-loadmore-wrapper button').css('display', 'flex');
$(selctorEl + " .nft-loadmore").click(function (e) {
//change the text of the button
$(this).html(loadmorelabel + spinicon);
$(this).prop("disabled", true);
$(selctorEl + " .nft-loadmore").text(loadmorelabel);
$(selctorEl + " .nft-loadmore").prop("disabled", false);
$(selctorEl + " .ep_nft_item:hidden").slice(0, $(selctorEl).data('itemparpage')).fadeIn("slow");
if ($(selctorEl + " .ep_nft_item:hidden").length == 0) {
$(selctorEl + " .nft-loadmore").fadeOut("slow");
if ($('.embedpress-gutenberg-wrapper .ep-nft-gallery-wrapper').length > 0) {
// Content protection system function
const unlockSubmitHander = (perentSel, that) => {
var ep_client_id = jQuery(that).closest('form').find('input[name="ep_client_id"]').val();
var password = jQuery(`input[name="pass_${ep_client_id}"]`).val();
var post_id = jQuery(`input[name="post_id"]`).val();
const buttonText = jQuery(that).closest('.password-form-container').find('input[type="submit"]').val();
const unlokingText = jQuery(that).data('unlocking-text');
'action': 'lock_content_form_handler',
'client_id': ep_client_id,
jQuery('#' + perentSel + '-' + ep_client_id + ' .password-form input[type="submit"]').val(unlokingText);
jQuery.post(eplocalize.ajaxurl, data, function (response) {
if (!response.embedHtml) {
jQuery('#' + perentSel + '-' + ep_client_id + ' .password-form input[type="submit"]').val(buttonText);
jQuery('#' + perentSel + '-' + ep_client_id + ' .password-form input[type="password"]').val('');
jQuery(that).closest('.password-form-container').find('.error-message').removeClass('hidden');
jQuery('#' + perentSel + '-' + ep_client_id + ' .ep-embed-content-wraper').html(response.embedHtml);
if (jQuery('#' + perentSel + '-' + ep_client_id + ' .ose-youtube').length > 0) {
epGlobals.youtubeChannelGallery();
if ($('.embedpress-gutenberg-wrapper .ep-nft-gallery-wrapper').length > 0) {
// Custom player initialization when content protection enabled
document.querySelector('#' + perentSel + '-' + ep_client_id + ' .ep-embed-content-wraper').classList.remove('plyr-initialized');
initPlayer(document.querySelector('#' + perentSel + '-' + ep_client_id + ' .ep-embed-content-wraper'));
if (eplocalize.is_pro_plugin_active) {
const adIdEl = document.querySelector('#' + perentSel + '-' + ep_client_id + ' [data-sponsored-id]');
adInitialization(adIdEl, adIdEl?.getAttribute('data-ad-index'));
jQuery('#password-error_' + ep_client_id).html(response.form);
jQuery('#password-error_' + ep_client_id).show();
// unlockSubmitHander called for gutentberg
jQuery('.ep-gutenberg-content .password-form').submit(function (e) {
e.preventDefault(); // Prevent the default form submission
unlockSubmitHander('ep-gutenberg-content', this);
window.addEventListener('load', function (e) {
const urlParams = new URLSearchParams(window.location.search);
const hash = urlParams.get('hash');
// find the element with the matching id
const element = document.getElementById(hash);
element.scrollIntoView({ behavior: 'smooth' });
// Get the insta-gallery container element
const getPopupTemplate = (instPost, hashtag = '', accountType) => {
let instaPostData = JSON.parse(instPost);
let likeIcon = '<svg aria-label="Like" class="x1lliihq x1n2onr6" color="#262626" fill="#262626" height="24" viewBox="0 0 24 24" width="24"><path d="M16.792 3.904A4.989 4.989 0 0 1 21.5 9.122c0 3.072-2.652 4.959-5.197 7.222-2.512 2.243-3.865 3.469-4.303 3.752-.477-.309-2.143-1.823-4.303-3.752C5.141 14.072 2.5 12.167 2.5 9.122a4.989 4.989 0 0 1 4.708-5.218 4.21 4.21 0 0 1 3.675 1.941c.84 1.175.98 1.763 1.12 1.763s.278-.588 1.11-1.766a4.17 4.17 0 0 1 3.679-1.938m0-2a6.04 6.04 0 0 0-4.797 2.127 6.052 6.052 0 0 0-4.787-2.127A6.985 6.985 0 0 0 .5 9.122c0 3.61 2.55 5.827 5.015 7.97.283.246.569.494.853.747l1.027.918a44.998 44.998 0 0 0 3.518 3.018 2 2 0 0 0 2.174 0 45.263 45.263 0 0 0 3.626-3.115l.922-.824c.293-.26.59-.519.885-.774 2.334-2.025 4.98-4.32 4.98-7.94a6.985 6.985 0 0 0-6.708-7.218Z"/></svg>';
if (instaPostData.like_count > 0) {
likeIcon = '<svg aria-label="Unlike" class="x1lliihq x1n2onr6" color="#FF3040" fill="#FF3040" height="24" viewBox="0 0 48 48" width="24"><path d="M34.6 3.1c-4.5 0-7.9 1.8-10.6 5.6-2.7-3.7-6.1-5.5-10.6-5.5C6 3.1 0 9.6 0 17.6c0 7.3 5.4 12 10.6 16.5.6.5 1.3 1.1 1.9 1.7l2.3 2c4.4 3.9 6.6 5.9 7.6 6.5.5.3 1.1.5 1.6.5s1.1-.2 1.6-.5c1-.6 2.8-2.2 7.8-6.8l2-1.8c.7-.6 1.3-1.2 2-1.7C42.7 29.6 48 25 48 17.6c0-8-6-14.5-13.4-14.5z"/></svg>';
const commentsIcon = '<svg aria-label="Comment" class="x1lliihq x1n2onr6" color="#000" height="24" viewBox="0 0 24 24" width="24"><path d="M20.656 17.008a9.993 9.993 0 1 0-3.59 3.615L22 22Z" fill="none" stroke="currentColor" stroke-linejoin="round" stroke-width="2"/></svg>';
const shareIcon = '<svg width="20" height="20" viewBox="0 0 0.6 0.6" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg"><path stroke-width="1" d="m.543.282-.2-.2A.025.025 0 0 0 .3.1v.089a.275.275 0 0 0-.25.274V.5a.025.025 0 0 0 .045.015.3.3 0 0 1 .197-.101L.3.413V.5a.025.025 0 0 0 .043.018l.2-.2a.025.025 0 0 0 0-.035M.35.44V.388A.025.025 0 0 0 .325.363L.286.365a.35.35 0 0 0-.185.074.225.225 0 0 1 .224-.201A.025.025 0 0 0 .35.213V.16L.49.3Z"/></svg>';
const instaIcon = '<svg width="18" height="18" viewBox="0 0 0.338 0.338" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M.248.079H.27M.102.012h.135a.09.09 0 0 1 .09.09v.135a.09.09 0 0 1-.09.09H.102a.09.09 0 0 1-.09-.09V.102a.09.09 0 0 1 .09-.09ZM.17.237a.068.068 0 1 1 0-.135.068.068 0 0 1 0 .135Z" stroke="#000" stroke-width=".032"/></svg>';
const instaUserInfo = instPost.user_info;
let getDate = new Date(instaPostData.timestamp);
getDate = getDate.toLocaleString('en-US', { day: 'numeric', month: 'short', year: 'numeric' });
let getTime = new Date(instaPostData.timestamp);
getTime = getTime.toLocaleString('en-US', { hour12: false, hour: 'numeric', minute: 'numeric', second: 'numeric' });
let captionText = instaPostData.caption ? instaPostData.caption : '';
const tagRegex = /(#\w+)/g;
const wrapTag = (match) => {
const tag = match.substring(1); // Remove the '#' character
const tagUrl = `https://www.instagram.com/explore/tags/${tag}`;
return `<span class="tag-wrapper"><a target="_blank" href="${tagUrl}">${match}</a></span>`;
captionText = captionText.replace(tagRegex, wrapTag);
let carouselTemplate = '';
if (instaPostData.media_type === 'CAROUSEL_ALBUM') {
carouselTemplate += `<div class="popup-carousel"><div class="cg-carousel__track js-carousel__track">`;
instaPostData.children.data?.map((item) => {
if (item.media_type?.toLowerCase() === 'video') {
carouselTemplate += `<video width="630" class="popup-media-image cg-carousel__slide js-carousel__slide" controls src="${item.media_url || ''}" alt="${item.caption || ''}" controlsList="nodownload"></video>`;
carouselTemplate += `<img width="630" class="popup-media-image cg-carousel__slide js-carousel__slide" src="${item.media_url || ''}" alt="${item.caption || ''}" />`;
carouselTemplate += `</div></div>`;
carouselTemplate += `<div class="cg-carousel__btns">
<button class="cg-carousel__btn js-carousel__prev-1"><svg width="20" height="30" viewBox="-5 0 23 23" xmlns="http://www.w3.org/2000/svg"><path d="M11.24.29.361 10.742l-.06.054a.97.97 0 0 0-.301.642v.124a.97.97 0 0 0 .3.642l.054.044L11.239 22.71a1.061 1.061 0 0 0 1.459 0 .964.964 0 0 0 0-1.402l-10.15-9.746 10.15-9.87a.964.964 0 0 0 0-1.402 1.061 1.061 0 0 0-1.459 0Z" fill="#fff"/></svg></button>
<button class="cg-carousel__btn js-carousel__next-1"><svg width="20" height="30" viewBox="-5 0 23 23" xmlns="http://www.w3.org/2000/svg"><path d="m1.76.29 10.879 10.452.06.054a.97.97 0 0 1 .301.642v.124a.97.97 0 0 1-.3.642l-.054.044L1.761 22.71a1.061 1.061 0 0 1-1.459 0 .964.964 0 0 1 0-1.402l10.15-9.746-10.15-9.87a.964.964 0 0 1 0-1.402 1.061 1.061 0 0 1 1.459 0Z" fill="#fff"/></svg></button>
if (instaPostData.media_type?.toLowerCase() === 'video') {
carouselTemplate += `<video width="630" class="popup-media-image" controls src="${instaPostData.media_url || ''}" alt="${instaPostData.caption || ''}"></video>`;
carouselTemplate += `<img width="630" class="popup-media-image" src="${instaPostData.media_url || ''}" alt="${instaPostData.caption || ''}" />`;
let srcUrl = `https://www.instagram.com/${instaPostData.username}/`;
instaPostData.username = '#' + hashtag;
srcUrl = `https://www.instagram.com/explore/tags/${hashtag}/`;
if (eplocalize.is_pro_plugin_active && accountType === 'business') {