: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
class SGPBNotificationCenter
private $requestUrl = SG_POPUP_BUILDER_NOTIFICATIONS_URL;
private $cronTimeout = 'daily';
public function __construct()
public function addActions()
add_filter('sgpbCronTimeoutSettings', array($this, 'cronAddMinutes'), 10, 1);
add_action('sgpbGetNotifications', array($this, 'updateNotificationsArray'));
add_action('wp_ajax_sgpb_dismiss_notification', array($this, 'dismissNotification'));
add_action('wp_ajax_sgpb_remove_notification', array($this, 'removeNotification'));
add_action('wp_ajax_sgpb_reactivate_notification', array($this, 'reactivateNotification'));
add_action('admin_head', array($this, 'menuItemCounter'));
public function menuItemCounter()
$count = count(self::getAllActiveNotifications(true));
$hidden = ' sgpb-hide-add-button';
jQuery(document).ready(function() {
jQuery('.sgpb-menu-item-notification').remove();
jQuery('.dashicons-menu-icon-sgpb').next().append('<span class=\"sgpb-menu-item-notification".esc_attr($hidden)."\">".esc_html($count)."</span>');
echo wp_kses($script, AdminHelper::allowed_html_tags());
public function setCronTimeout($cronTimeout)
$this->cronTimeout = $cronTimeout;
public function getCronTimeout()
return $this->cronTimeout;
public function setRequestUrl($requestUrl)
$this->requestUrl = $requestUrl;
public function getRequestUrl()
return $this->requestUrl;
public function updateNotificationsArray()
$requestUrl = $this->getRequestUrl();
$content = AdminHelper::getFileFromURL($requestUrl);
$content = json_decode($content, true);
$content = apply_filters('sgpbExtraNotifications', $content);
update_option('sgpb-all-dismissed-notifications', array());
$content = wp_json_encode($content);
update_option('sgpb-all-notifications-data', $content);
public function sortNotifications($allNotifications)
$allNotifications = json_decode($allNotifications, true);
if (empty($allNotifications)) {
$allNotifications = array();
$dismissed = self::getAllDismissedNotifications();
// for the first time dismissed and active arrays should be empty
if (empty($dismissed) && empty($active)) {
$notifications = array();
foreach ($allNotifications as $notification) {
$id = $notification['id'];
$notifications[$id] = $id;
update_option('sgpb-all-active-notifications', wp_json_encode($notifications));
public function cronAddMinutes($schedules)
$schedules['sgpb_notifications'] = array(
'interval' => SGPB_NOTIFICATIONS_CRON_REPEAT_INTERVAL * 3600,
'display' => __('Twice Daily', 'popup-builder')
public static function getAllActiveNotifications($hideDismissed = false)
$activeNotifications = array();
$notifications = get_option('sgpb-all-notifications-data');
$notifications = json_decode($notifications, true);
if (empty($notifications)) {
$dismissedNotifications = get_option('sgpb-all-dismissed-notifications');
$dismissedNotifications = json_decode($dismissedNotifications, true);
$extensions = AdminHelper::getAllExtensions();
$extensionsKeys = wp_list_pluck($extensions['active'], 'key');
foreach ($notifications as $notification) {
$id = isset($notification['id']) ? $notification['id'] : '';
if (isset($notification['hideFor'])) {
$hideForExtensions = explode(',', $notification['hideFor']);
$arraysIntersect = array_intersect($extensionsKeys, $hideForExtensions);
// If only one condition -> free, single extension, bundle
if (count($hideForExtensions) == 1) {
if ($notification['hideFor'] == SGPB_POPUP_PKG_FREE && empty($extensionsKeys) && !class_exists('SGPBActivatorPlugin')) {
else if (in_array($notification['hideFor'], $extensionsKeys)) {
// Pro, if it is a free user
else if ($notification['hideFor'] == 'pro' && count($extensionsKeys) >= 1) {
else if ($notification['hideFor'] == 'bundle') {
if (class_exists('SGPBActivatorPlugin') || count($extensionsKeys) >= 10) {
// if there is even one detected extension, don’t show notification
else if (count($arraysIntersect) > 0) {
if ($hideDismissed && isset($dismissedNotifications[$id])) {
$activeNotifications[] = $notification;
$removedNotifications = get_option('sgpb-all-removed-notifications');
$removedNotifications = json_decode($removedNotifications, true);
if (empty($removedNotifications)) {
return $activeNotifications;
foreach ($removedNotifications as $removedNotificationId) {
foreach ($activeNotifications as $key => $activeNotification) {
if ($activeNotification['id'] == $removedNotificationId) {
unset($activeNotifications[$key]);
return $activeNotifications;
public static function getAllDismissedNotifications()
$notifications = get_option('sgpb-all-dismissed-notifications');
if (empty($notifications)) {
return json_decode($notifications, true);
public static function getAllRemovedNotifications()
$notifications = get_option('sgpb-all-removed-notifications');
if (empty($notifications)) {
return json_decode($notifications, true);
public static function displayNotifications($withoutWrapper = false)
$allNotifications = self::getAllActiveNotifications();
if (empty($allNotifications)) {
$count = count(self::getAllActiveNotifications(true));
foreach ($allNotifications as $notification) {
$newNotification = new Notification();
$newNotification->setId($notification['id']);
$newNotification->setType($notification['type']);
$newNotification->setPriority($notification['priority']);
$newNotification->setMessage($notification['message']);
$content .= $newNotification->render();
$count = '(<span class="sgpb-notifications-count-span">'.$count.'</span>)';
$content = self::prepareHtml($content, $count);
public static function prepareHtml($content = '', $count = 0)
$content = '<div class="sgpb-each-notification-wrapper-js">'.$content.'</div>';
$content = '<div class="sgpb-notification-center-wrapper">
<h3><span class="dashicons dashicons-flag"></span> Notifications '.$count.'</h3>'.$content.'
public function dismissNotification()
check_ajax_referer(SG_AJAX_NONCE, 'nonce');
$notificationId = isset($_POST['id']) ? sanitize_text_field($_POST['id']) : '';
$allDismissedNotifications = self::getAllDismissedNotifications();
$allDismissedNotifications[$notificationId] = $notificationId;
$allDismissedNotifications = wp_json_encode($allDismissedNotifications);
update_option('sgpb-all-dismissed-notifications', $allDismissedNotifications);
$result['content'] = self::displayNotifications(true);
$result['count'] = count(self::getAllActiveNotifications(true));
public function removeNotification()
check_ajax_referer(SG_AJAX_NONCE, 'nonce');
if (!isset($_POST['id'])){
$notificationId = sanitize_text_field($_POST['id']);
$allRemovedNotifications = self::getAllRemovedNotifications();
$allRemovedNotifications[$notificationId] = $notificationId;
$allRemovedNotifications = wp_json_encode($allRemovedNotifications);
update_option('sgpb-all-removed-notifications', $allRemovedNotifications);
public function reactivateNotification()
check_ajax_referer(SG_AJAX_NONCE, 'nonce');
if (!isset($_POST['id'])){
$notificationId = sanitize_text_field($_POST['id']);
$allDismissedNotifications = self::getAllDismissedNotifications();
if (isset($allDismissedNotifications[$notificationId])) {
unset($allDismissedNotifications[$notificationId]);
$allDismissedNotifications = wp_json_encode($allDismissedNotifications);
update_option('sgpb-all-dismissed-notifications', $allDismissedNotifications);
$result['content'] = self::displayNotifications(true);
$result['count'] = count(self::getAllActiveNotifications(true));
public function activateCron()
if (!wp_next_scheduled('sgpbGetNotifications')) {
wp_schedule_event(time(), 'daily', 'sgpbGetNotifications');
new SGPBNotificationCenter();