: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
// load popups data's from popups object
// all loadable popups objects
private $loadablePopups = array();
private $isAdmin = false;
private $scriptsAndStylesForAjax;
private $footerContentAjax;
private static $alreadyLoadedPopups = array();
public function setLoadablePopups($loadablePopups)
$this->loadablePopups = $loadablePopups;
public function getLoadablePopups()
return apply_filters('sgpbLoadablePopups', $this->loadablePopups);
public function setIsAdmin($isAdmin)
$this->isAdmin = $isAdmin;
public function getIsAdmin()
public function setIsAjax($isAjax)
public function getIsAjax()
public function setFooterContentAjax($footerContentAjax)
$this->footerContentAjax = $footerContentAjax;
public function getFooterContentAjax()
return $this->footerContentAjax;
* Get encoded popup options
* @return array|mixed|string $popupOptions
private function getEncodedOptionsFromPopup($popup)
$extraOptions = $popup->getExtraRenderOptions();
$popupOptions = $popup->getOptions();
$popupOptions = apply_filters('sgpbPopupRenderOptions', $popupOptions);
$popupCondition = $popup->getConditions();
$popupOptions = array_merge($popupOptions, $extraOptions);
$popupOptions['sgpbConditions'] = apply_filters('sgpbRenderCondtions', $popupCondition);
//Ted-fix : we stopped the render custom js code into front-end page to fix HACKER attack
//Get DISABLE custom JS setting
if( AdminHelper::getOption('sgpb-disable-custom-js') )
unset($popupOptions['sgpb-ShouldOpen']);
unset($popupOptions['sgpb-WillOpen']);
unset($popupOptions['sgpb-DidOpen']);
unset($popupOptions['sgpb-ShouldClose']);
unset($popupOptions['sgpb-DidClose']);
unset($popupOptions['sgpb-WillClose']);
//Ted-fix : we stopped the render custom js code into front-end page to fix HACKER attack
// JSON_UNESCAPED_UNICODE does not exist since 5.4.0
if (PHP_VERSION < '5.4.0'){
$popupOptions = wp_json_encode($popupOptions);
$popupOptions = wp_json_encode($popupOptions,JSON_UNESCAPED_UNICODE);
return base64_encode($popupOptions);
// load popup scripts and styles and add popup data to the footer
public function loadToFooter($isFromAjax = false)
$popups = $this->getLoadablePopups();
$currentPostType = AdminHelper::getCurrentPostType();
$currentUrl = home_url( $wp->request );
$currentUrl = strpos($currentUrl, '/popupbuilder/');
// during preview wp request is empty that is why we check query_string
$currentUrl = strrpos($wp->query_string, 'popupbuilder');
if ($currentPostType == SG_POPUP_POST_TYPE && $currentUrl === false) {
if ($this->getIsAdmin()) {
foreach ($popups as $popup) {
$isActive = $popup->isActive();
$popupId = $popup->getId();
$popupContent = apply_filters('sgpbPopupContentLoadToPage', $popup->getPopupTypeContent(), $popupId);
$events = $popup->getPopupAllEvents($postId, $popupId, $popup);
// if popup's data has already loaded into the page with the same event
if (isset(self::$alreadyLoadedPopups[$popupId])) {
if (self::$alreadyLoadedPopups[$popupId] == $events) {
foreach ($events as $event) {
if (isset($event['param'])) {
if (isset(self::$alreadyLoadedPopups[$popupId])) {
if (self::$alreadyLoadedPopups[$popupId] == $event['param']) {
if (isset(self::$alreadyLoadedPopups[$popupId])) {
if (false !== array_search($event, array_column(self::$alreadyLoadedPopups[$popupId], 'param'))) {
self::$alreadyLoadedPopups[$popupId] = $events;
$events = wp_json_encode($events);
$currentUseOptions = $popup->getOptions();
$extraContent = apply_filters('sgpbPopupExtraData', $popupId, $currentUseOptions);
$popupOptions = $this->getEncodedOptionsFromPopup($popup);
$popupOptions = apply_filters('sgpbLoadToFooterOptions', $popupOptions);
$footerPopupContent = '<div class="sgpb-main-popup-data-container-'.esc_attr($popupId).'" style="position:fixed;opacity: 0;filter: opacity(0%);transform: scale(0);">
<div class="sg-popup-builder-content" id="sg-popup-content-wrapper-'.esc_attr($popupId).'" data-id="'.esc_attr($popupId).'" data-events="'.esc_attr($events).'" data-options="'.esc_attr($popupOptions).'">
<div class="sgpb-popup-builder-content-'.esc_attr($popupId).' sgpb-popup-builder-content-html">'.$popupContent.'</div>
$footerPopupContent .= $extraContent;
$footerContentAjax .= $footerPopupContent;
add_action('wp_footer', function() use ($popupId, $events, $popupOptions, $popupContent, $extraContent) {
$footerPopupContent = '<div class="sgpb-main-popup-data-container-'.esc_attr($popupId).'" style="position:fixed;opacity: 0;filter: opacity(0%);transform: scale(0);">
<div class="sg-popup-builder-content" id="sg-popup-content-wrapper-'.esc_attr($popupId).'" data-id="'.esc_attr($popupId).'" data-events="'.esc_attr($events).'" data-options="'.esc_attr($popupOptions).'">
<div class="sgpb-popup-builder-content-'.esc_attr($popupId).' sgpb-popup-builder-content-html">'.$popupContent.'</div>
$footerPopupContent .= $extraContent;
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $footerPopupContent;
$this->setFooterContentAjax($footerContentAjax);
public function loadToAdmin()
$popups = $this->getLoadablePopups();
foreach ($popups as $popup) {
$popupId = $popup->getId();
$events = wp_json_encode($events);
$popupOptions = $this->getEncodedOptionsFromPopup($popup);
$popupContent = apply_filters('sgpbPopupContentLoadToPage', $popup->getPopupTypeContent(), $popupId);
add_action('admin_footer', function() use ($popupId, $events, $popupOptions, $popupContent) {
$footerPopupContent = '<div style="position:absolute;top: -999999999999999999999px;">
<div class="sg-popup-builder-content" id="sg-popup-content-wrapper-'.$popupId.'" data-id="'.esc_attr($popupId).'" data-events="'.esc_attr($events).'" data-options="'.esc_attr($popupOptions).'">
<div class="sgpb-popup-builder-content-'.esc_attr($popupId).' sgpb-popup-builder-content-html">'.$popupContent.'</div>
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo $footerPopupContent;
private function includeScripts()
$popups = $this->getLoadablePopups();
$registeredPlugins = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
if (!$registeredPlugins) {
$registeredPlugins = json_decode($registeredPlugins, true);
if (empty($registeredPlugins)) {
foreach ($registeredPlugins as $pluginName => $pluginData) {
if (!is_plugin_active($pluginName)) {
if (empty($pluginData['classPath']) || empty($pluginData['className'])) {
$classPath = $pluginData['classPath'];
$classPath = SG_POPUP_PLUGIN_PATH.$classPath;
if (!file_exists($classPath)) {
require_once($classPath);
$classObj = new $pluginData['className']();
if (!$classObj instanceof \SgpbIPopupExtension) {
$scriptData = $classObj->getFrontendScripts(
$scripts[] = $scriptData;
$this->scriptsAndStylesForAjax['scripts'] = $scripts;
foreach ($scripts as $script) {
if (empty($script['jsFiles'])) {
foreach ($script['jsFiles'] as $jsFile) {
if (empty($jsFile['folderUrl'])) {
if(isset($jsFile['filename'])){
wp_enqueue_script($jsFile['filename']);
$dirUrl = $jsFile['folderUrl'];
$dep = (!empty($jsFile['dep'])) ? $jsFile['dep'] : '';
$ver = (!empty($jsFile['ver'])) ? $jsFile['ver'] : '';
$inFooter = (!empty($jsFile['inFooter'])) ? $jsFile['inFooter'] : '';
ScriptsIncluder::registerScript($jsFile['filename'], array(
ScriptsIncluder::enqueueScript($jsFile['filename']);
if (empty($script['localizeData'])) {
$localizeData = $script['localizeData'];
if (!empty($localizeData[0])) {
foreach ($localizeData as $valueData) {
if (version_compare($wp_version, '4.5', '>')){
/* after wp 4.5 version */
ScriptsIncluder::addInlineScripts($valueData['handle'], 'var '.$valueData['name'].' = ' .wp_json_encode($valueData['data']).';');
/* since wp 4.5 version */
ScriptsIncluder::localizeScript($valueData['handle'], $valueData['name'], $valueData['data']);
private function includeStyles()
$popups = $this->getLoadablePopups();
$registeredPlugins = AdminHelper::getOption(SGPB_POPUP_BUILDER_REGISTERED_PLUGINS);
if (!$registeredPlugins) {
$registeredPlugins = json_decode($registeredPlugins, true);
if (empty($registeredPlugins)) {
foreach ($registeredPlugins as $pluginName => $pluginData) {
if (!is_plugin_active($pluginName)) {
if (empty($pluginData['classPath']) || empty($pluginData['className'])) {
$classPath = $pluginData['classPath'];
$classPath = SG_POPUP_PLUGIN_PATH.$classPath;
if (!file_exists($classPath)) {
require_once($classPath);
$classObj = new $pluginData['className']();
if (!$classObj instanceof \SgpbIPopupExtension) {
$scriptData = $classObj->getFrontendStyles(
$this->scriptsAndStylesForAjax['styles'] = $styles;
foreach ($styles as $style) {
if (empty($style['cssFiles'])) {
foreach ($style['cssFiles'] as $cssFile) {
if (empty($cssFile['folderUrl'])) {
ScriptsIncluder::enqueueStyle($cssFile['filename']);
$dirUrl = $cssFile['folderUrl'];
$dep = (!empty($cssFile['dep'])) ? $cssFile['dep'] : '';
$ver = (!empty($cssFile['ver'])) ? $cssFile['ver'] : '';
$inFooter = (!empty($cssFile['inFooter'])) ? $cssFile['inFooter'] : '';
ScriptsIncluder::registerStyle($cssFile['filename'], array(
ScriptsIncluder::enqueueStyle($cssFile['filename']);
public function getScriptsAndStylesForAjax() {
return $this->scriptsAndStylesForAjax;