: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
public static function getPopupsIdAndTitle($excludesPopups = array())
$allPopups = SGPopup::getAllPopups();
$popupIdTitles = array();
foreach ($allPopups as $popup) {
$title = $popup->getTitle();
$type = $popup->getType();
if (!empty($excludesPopups)) {
foreach ($excludesPopups as $excludesPopupId) {
if ($excludesPopupId != $id) {
$popupIdTitles[$id] = $title.' - '.$type;
$popupIdTitles[$id] = $title.' - '.$type;
* Merge two array and merge same key values to same array
public static function arrayMergeSameKeys($array1, $array2)
foreach ($array1 as $key => $value) {
if (isset($array2[$key]) && is_array($array2[$key])) {
$arrDifference = array_diff($array2[$key], $array1[$key]);
if (empty($arrDifference)) {
$array3[$key] = array_merge($array2[$key], $array1[$key]);
// when there are no values
return $array2 + $array3;
public static function getCurrentUserRole()
if( !function_exists('wp_get_current_user'))
require_once( ABSPATH . '/wp-includes/pluggable.php' );
if (get_current_user_id() !== 0){
$getUsersObj = get_users(
'blog_id' => get_current_blog_id(),
'search' => get_current_user_id()
if (!empty($getUsersObj[0])) {
$roles = $getUsersObj[0]->roles;
if (is_array($roles) && !empty($roles)) {
$role = array_merge($role, $getUsersObj[0]->roles);
if( is_user_logged_in() ) {
$current_user = wp_get_current_user();
if (!empty($current_user)) {
$role = $current_user->roles;
public static function hexToRgba($color, $opacity = false)
//Return default if no color provided
//Sanitize $color if "#" is provided
$color = substr($color, 1);
//Check if color has 6 or 3 characters and get values
if (strlen($color) == 6) {
$hex = array($color[0].$color[1], $color[2].$color[3], $color[4].$color[5]);
else if (strlen($color) == 3) {
$hex = array($color[0].$color[0], $color[1].$color[1], $color[2].$color[2]);
$rgb = array_map('hexdec', $hex);
//Check if opacity is set(rgba or rgb)
if ($opacity !== false) {
$output = 'rgba('.implode(',', $rgb).','.$opacity.')';
$output = 'rgb('.implode(',', $rgb).')';
//Return rgb(a) color string
public static function getAllActiveExtensions()
$extensions = SgpbDataConfig::getOldExtensionsInfo();
foreach ($extensions as $extension) {
if (file_exists(WP_PLUGIN_DIR.'/'.$extension['folderName'])) {
$labels[] = $extension['label'];
public static function renderExtensionsContent()
$extensions = self::getAllActiveExtensions();
<p class="sgpb-extension-notice-close">x</p>
<div class="sgpb-extensions-list-wrapper">
<div class="sgpb-notice-header">
<h3><?php esc_html_e('Popup Builder plugin has been successfully updated', 'popup-builder'); ?></h3>
<h4><?php esc_html_e('The following extensions need to be updated manually', 'popup-builder'); ?></h4>
<ul class="sgpb-extensions-list">
<?php foreach ($extensions as $extensionName): ?>
<a target="_blank" href="https://popup-builder.com/forms/control-panel/"><li><?php echo esc_html($extensionName); ?></li></a>
<p class="sgpb-extension-notice-dont-show"><?php esc_html_e('Don\'t show again', 'popup-builder')?></p>
$content = ob_get_contents();
public static function getReverseConvertIds()
$idsMappingSaved = get_option('sgpbConvertedIds');
public static function getAllFreeExtensions()
$allExtensions = SgpbDataConfig::allFreeExtensionsKeys();
$notActiveExtensions = array();
$activeExtensions = array();
foreach ($allExtensions as $extension) {
if (!is_plugin_active($extension['pluginKey'])) {
$notActiveExtensions[] = $extension;
$activeExtensions[] = $extension;
$divideExtension = array(
'noActive' => $notActiveExtensions,
'active' => $activeExtensions
public static function getAllExtensions()
$allExtensions = SgpbDataConfig::allExtensionsKeys();
$notActiveExtensions = array();
$activeExtensions = array();
foreach ($allExtensions as $extension) {
if (!is_plugin_active($extension['pluginKey'])) {
$notActiveExtensions[] = $extension;
$activeExtensions[] = $extension;
$divideExtension = array(
'noActive' => $notActiveExtensions,
'active' => $activeExtensions
public static function renderAlertProblem()
<div id="welcome-panel" class="update-nag sgpb-alert-problem">
<div class="welcome-panel-content">
<p class="sgpb-problem-notice-close">x</p>
<div class="sgpb-alert-problem-text-wrapper">
<h3><?php esc_html_e('Popup Builder plugin has been updated to the new version 3.', 'popup-builder'); ?></h3>
<h5><?php esc_html_e('A lot of changes and improvements have been made.', 'popup-builder'); ?></h5>
/* translators: Ticket URL */
printf( wp_kses_post( __('In case of any issues, please contact us <a href="%s" target="_blank">here</a>.', 'popup-builder') ) , esc_url( SG_POPUP_TICKET_URL ) );
<p class="sgpb-problem-notice-dont-show"><?php esc_html_e('Don\'t show again', 'popup-builder'); ?></p>
$content = ob_get_clean();
public static function getTaxonomyBySlug($slug = '')
$allTerms = get_terms(array('hide_empty' => false));
foreach ($allTerms as $term) {
if ($term->slug == $slug) {
public static function getCurrentPopupType()
if (!empty($_GET['sgpb_type'])) {
$type = sanitize_text_field($_GET['sgpb_type']);
$currentPostType = self::getCurrentPostType();
if ($currentPostType == SG_POPUP_POST_TYPE && !empty($_GET['post'])) {
$popupObj = SGPopup::find(sanitize_text_field($_GET['post']));
if (is_object($popupObj)) {
$type = $popupObj->getType();
public static function getCurrentPostType()
$currentPostType = $post->post_type;
// in some themes global $post returns null
if (empty($currentPostType)) {
$currentPostType = $post_type;
if (empty($currentPostType) && !empty($_GET['post'])) {
$currentPostType = get_post_type(sanitize_text_field($_GET['post']));
* Get image encoded data from URL
* @param $shouldNotConvertBase64
public static function getImageDataFromUrl($imageUrl, $shouldNotConvertBase64 = false)
$remoteData = wp_remote_get($imageUrl);
if (is_wp_error($remoteData) && $shouldNotConvertBase64) {
return SG_POPUP_IMG_URL.'NoImage.png';
if (!$shouldNotConvertBase64) {
$imageData = wp_remote_retrieve_body($remoteData);
$imageUrl = base64_encode($imageData);
public static function deleteUserFromSubscribers($params = array())
if (isset($params['email'])) {
$email = $params['email'];
if (isset($params['popup'])) {
$popup = $params['popup'];
$subscribersTableName = $wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME;
$res = $wpdb->get_row( $wpdb->prepare("SELECT id FROM $subscribersTableName WHERE email = %s && subscriptionType = %s", $email, $popup), ARRAY_A);
if (!isset($res['id'])) {
$params['subscriberId'] = $res['id'];
$subscriber = self::subscriberExists($params);
if ($subscriber && $noSubscriber) {
self::deleteSubscriber($params);
else if (!$noSubscriber) {
printf( '<span>%s</span>' ,
wp_kses_post(__('Oops, something went wrong, please try again or contact the administrator to check more info.', 'popup-builder') )
public static function subscriberExists($params = array())
$receivedToken = $params['token'];
$realToken = md5($params['subscriberId'].$params['email']);
if ($receivedToken == $realToken) {
public static function deleteSubscriber($params = array())
$homeUrl = get_home_url();
// send email to admin about user unsubscription
self::sendEmailAboutUnsubscribe($params);
$subscribersTableName = $wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME;
$wpdb->query( $wpdb->prepare("UPDATE $subscribersTableName SET unsubscribed = 1 WHERE id = %s ", $params['subscriberId']) );
/* translators: Home page URL */
printf( '<span>%1$s <a href="%2$s">click here</a> %3$s</span>' ,
wp_kses_post(__('You have successfully unsubscribed.', 'popup-builder') ),
wp_kses_post(__(' to go to the home page.', 'popup-builder') )
public static function sendEmailAboutUnsubscribe($params = array())
$newsletterOptions = get_option('SGPB_NEWSLETTER_DATA');
$receiverEmail = get_bloginfo('admin_email');
$userEmail = $params['email'];
$emailTitle = __('Unsubscription', 'popup-builder');
$subscriptionFormId = (int)$newsletterOptions['subscriptionFormId'];
$subscriptionFormTitle = get_the_title($subscriptionFormId);
/* translators: user Email, subscription Form Title */
$message = sprintf( __('User with %1$s email has unsubscribed from %2$s mail list', 'popup-builder'), $userEmail, $subscriptionFormTitle);
$headers = 'MIME-Version: 1.0'."\r\n";
$headers .= 'From: WordPress Popup Builder'."\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8'."\r\n"; //set UTF-8
wp_mail($receiverEmail, $emailTitle, $message, $headers);
public static function addUnsubscribeColumn()
$subscribersTableName = $wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME;
$wpdb->query( "ALTER TABLE $subscribersTableName ADD COLUMN unsubscribed INT NOT NULL DEFAULT 0 " );
public static function isPluginActive($key)
$allExtensions = SgpbDataConfig::allExtensionsKeys();
foreach ($allExtensions as $extension) {
if (isset($extension['key']) && $extension['key'] == $key) {
if (is_plugin_active($extension['pluginKey'])) {
public static function supportBannerNotification()
$content = '<div class="sgpb-support-notification-wrapper sgpb-wrapper"><h4 class="sgpb-support-notification-title">'.__('Need some help?', 'popup-builder').'</h4>';
$content .= '<h4 class="sgpb-support-notification-title">'.__('Let us know what you think.', 'popup-builder').'</h4>';
$content .= '<a class="btn btn-info" target="_blank" href="'.SG_POPUP_RATE_US_URL.'"><span class="dashicons sgpb-dashicons-heart sgpb-info-text-white"></span><span class="sg-info-text">'.__('Rate Us', 'popup-builder').'</span></a>';
$content .= '<a class="btn btn-info" target="_blank" href="'.SG_POPUP_TICKET_URL.'"><span class="dashicons sgpb-dashicons-megaphone sgpb-info-text-white"></span>'.__('Support Portal', 'popup-builder').'</a>';
$content .= '<a class="btn btn-info" target="_blank" href="https://wordpress.org/support/plugin/popup-builder"><span class="dashicons sgpb-dashicons-admin-plugins sgpb-info-text-white"></span>'.__('Support Forum', 'popup-builder').'</a>';
$content .= '<a class="btn btn-info" target="_blank" href="'.SG_POPUP_STORE_URL.'"><span class="dashicons sgpb-dashicons-editor-help sgpb-info-text-white"></span>'.__('LIVE chat', 'popup-builder').'</a>';
$content .= '<a class="btn btn-info" target="_blank" href="mailto:support@popup-builder.com?subject=Hello"><span class="dashicons sgpb-dashicons-email-alt sgpb-info-text-white"></span>'.__('Email', 'popup-builder').'</a></div>';
$content .= '<div class="sgpb-support-notification-dont-show">'.__('Bored of this?').'<a class="sgpb-dont-show-again-support-notification" href="javascript:void(0)">'.__(' Press here ').'</a>'.__('and we will not show it again!').'</div>';
public static function getMaxOpenDaysMessage()
$getUsageDays = self::getPopupUsageDays();
/* translators: Usage Days */