: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
use \SGPBConfigDataHelper;
* Popup checker class to check if the popup must be loaded on the current page
private static $instance;
private $isGeoAjaxModeEnabled;
public static function instance()
if (!isset(self::$instance)) {
self::$instance = new self;
public function setPopup($popup)
public function getPopup()
public function setPost($post)
public function getPost()
public function setPopupGeoAjaxModeActive($ajaxMode)
$this->isGeoAjaxModeEnabled = $ajaxMode;
public function getPopupGeoAjaxMode()
return $this->isGeoAjaxModeEnabled;
public function setIsAjaxCall($isAjax)
$this->isAjaxCall = $isAjax;
public function getIsAjaxCall()
return $this->isAjaxCall;
* It checks whether popup should be loaded on the current page.
* @param int $popupId popup id
* @param object $post page post data
public function isLoadable($popup, $post, $isAjax = false)
$this->setPopupGeoAjaxModeActive($popup->getOptionValue('sgpb-enable-geo-ajax-mode'));
$this->setIsAjaxCall($isAjax);
$popupOptions = $popup->getOptions();
$isActive = $popup->getOptionValue('sgpb-is-active', true);
$saveMode = $popup->getSaveMode();
$allowToLoad = $this->allowToLoad();
$allowToLoad['option_event'] = false;
if (isset($popupOptions['sgpb-is-active'])) {
$isActive = $popupOptions['sgpb-is-active'];
$popup->setReportData($popup->getId());
$allowToLoad['option_event'] = false;
* Decides whether popup data should be loaded or not
private function allowToLoad()
$isCustomInserted = $this->isCustomInserted();
$insertedModes['attr_event'] = true;
$target = $this->divideTargetData();
$isPostInForbidden = $this->isPostInForbidden($target);
if ($isPostInForbidden) {
if (!empty($target['forbidden']) && empty($target['permissive'])) {
$conditions = $this->divideConditionsData();
$conditions = apply_filters('sgpbFilterDividedConditions', $conditions);
$isSatisfyForConditions = $this->isSatisfyForConditions($conditions);
if ($isSatisfyForConditions === false) {
if ($this->isSatisfyForOtherConditions() === false) {
$insertedModes['option_event'] = true;
$isPermissive = $this->isPermissive($target);
//If permissive for current page check conditions
$conditions = $this->divideConditionsData();
$conditions = apply_filters('sgpbFilterDividedConditions', $conditions);
$isSatisfyForConditions = $this->isSatisfyForConditions($conditions);
if ($isSatisfyForConditions === false) {
if ($this->isSatisfyForOtherConditions() === false) {
$insertedModes['option_event'] = $isPermissive;
* check is Satisfy popup conditions
* @param array $conditions assoc array
private function isSatisfyForConditions($conditions)
// this case when selected IS NOT operator
$forbiddenConditions = $conditions['forbidden'];
if (!empty($forbiddenConditions)) {
if (!$this->getIsAjaxCall() && $this->getPopupGeoAjaxMode()) {
foreach ($forbiddenConditions as $forbiddenCondition) {
$isForbiddenConditions = $this->isSatisfyForConditionsOptions($forbiddenCondition);
if ($isForbiddenConditions) {
// this case when selected IS operator
$permissiveOptions = $conditions['permissive'];
if (!empty($permissiveOptions)) {
if (!$this->getIsAjaxCall() && $this->getPopupGeoAjaxMode()) {
foreach ($permissiveOptions as $permissiveOption) {
$isPermissiveConditions = $this->isSatisfyForConditionsOptions($permissiveOption);
return $isPermissiveConditions;
if ($this->getIsAjaxCall() && $this->getPopupGeoAjaxMode()) {
private function isSatisfyForConditionsOptions($option)
$paramName = $option['param'];
$isAllowedConditionFilters = array();
if ($paramName == 'select_role') {
if (!$defaultStatus && do_action('isAllowedForConditions', $option, $post)) {
$isAllowedConditionFilters = apply_filters('isAllowedConditionFilters', array($option));
if (isset($isAllowedConditionFilters['status']) && $isAllowedConditionFilters['status'] === true) {
* Check is popup inserted via short code or class attribute
private function isCustomInserted()
$customInsertData = $this->getCustomInsertedData();
$popup = $this->getPopup();
// When popup object is empty it's mean popup is not custom inserted
$popupId = $popup->getId();
return in_array($popupId, $customInsertData);
* Should load data in the current page
* @param array $target popup saved target data
* @return bool $isPermissive true => allow false => don't allow
private function isPermissive($target)
if (empty($target['permissive'])) {
foreach ($target['permissive'] as $targetData) {
if ($this->isSatisfyForParam($targetData)) {
* Check whether the target data disallows loading the popup data on the current page
* @param array $target popup saved target data
* @return bool $isForbidden true => don't allow false => allow
private function isPostInForbidden($target)
if (empty($target['forbidden'])) {
foreach ($target['forbidden'] as $targetData) {
if ($this->isSatisfyForParam($targetData)) {
* Check whether the current page is corresponding to the saved target data
* @param array $targetData popup saved target data
* @return bool $isSatisfy
private function isSatisfyForParam($targetData)
if ($this->getIsAjaxCall()){
$popup = $this->getPopup();
$postId = $popup->getCurrentPageIdForAjax();
$postId = get_queried_object_id();
if (empty($targetData['param'])) {
$targetParam = $targetData['param'];
$post = $this->getPost();
if (isset($post) && empty($postId)) {
if ($targetParam == 'everywhere') {
if (strpos($targetData['param'], '_all')) {
$endIndex = strpos($targetData['param'], '_all');
$postType = substr($targetData['param'], 0, $endIndex);
$currentPostType = get_post_type($postId);
if ($postType == $currentPostType) {
else if (strpos($targetData['param'], '_archive')) {
$currentPostType = get_post_type();
if ($targetData['param'] == $currentPostType.'_archive') {
if (is_post_type_archive($currentPostType)) {
else if (strpos($targetData['param'], '_selected')) {
if (!empty($targetData['value'])) {
$values = array_keys($targetData['value']);
if (in_array($postId, $values)) {
else if (strpos($targetData['param'], '_categories')) {
if (!empty($targetData['value'])) {
$values = array_values($targetData['value']);
// get current all taxonomies of the current post
$taxonomies = get_post_taxonomies($post);
foreach ($taxonomies as $taxonomy) {
// get current post all categories
$terms = get_the_terms($post->ID, $taxonomy);
foreach ($terms as $term) {
if (in_array($term->term_id, $values)) {
else if ($targetData['param'] == 'post_type' && !empty($targetData['value'])) {
$selectedCustomPostTypes = array_values($targetData['value']);
$currentPostType = get_post_type($postId);
if (in_array($currentPostType, $selectedCustomPostTypes)) {
else if ($targetData['param'] == 'post_category' && !empty($targetData['value'])) {
$values = $targetData['value'];
$currentPostCategories = get_the_category($postId);
$currentPostType = get_post_type($postId);
if (empty($currentPostCategories) && $currentPostType == 'product') {
$currentPostCategories = get_the_terms($postId, 'product_cat');
foreach ($currentPostCategories as $categoryName) {
if (in_array($categoryName->term_id, $values) || in_array($categoryName->term_id, array_keys($values))) {
else if ($targetData['param'] == 'page_type' && !empty($targetData['value'])) {
$postTypes = $targetData['value'];
foreach ($postTypes as $postType) {
if ($postType == 'is_home_page') {
if (is_front_page() && is_home()) {
} else if ( is_front_page() ) {
else if (function_exists($postType) && $postType()) {
else if ($targetData['param'] == 'page_template' && !empty($targetData['value'])) {
$currentPageTemplate = basename(get_page_template());
if (in_array($currentPageTemplate, $targetData['value'])) {
else if ($targetData['param'] == 'post_tags') {
else if ($targetData['param'] == 'post_tags_ids') {
$tagsObj = wp_get_post_tags($postId);
$postTagsValues = isset($targetData['value']) ? (array)$targetData['value'] : array();
$selectedTags = array_values($postTagsValues);
foreach ($tagsObj as $tagObj) {
if (in_array($tagObj->slug, $selectedTags) || in_array($tagObj->slug, array_keys($postTagsValues))) {
if (!$isSatisfy && do_action('isAllowedForTarget', $targetData, $post)) {
* Divide conditions data to Permissive and Forbidden
* @return array $popupTargetData
private function divideConditionsData()
$popup = $this->getPopup();
$conditions = $popup->getConditions();
$conditions = $this->divideIntoPermissiveAndForbidden($conditions);