: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
use \SGPBConfigDataHelper;
class ConvertToNewVersion
private $customOptions = array();
public function setContent($content)
$this->content = $content;
public function getContent()
public function setType($type)
if ($type == 'shortcode') {
public function getType()
public function setTitle($title)
public function getTitle()
public function setId($id)
public function setOptions($options)
$this->options = $options;
public function getOptions()
public function setCustomOptions($customOptions)
$this->customOptions = $customOptions;
public function getCustomOptions()
return $this->customOptions;
public static function convert()
public function insertDataToNew()
Installer::registerPlugin();
$popups = $this->getAllSavedPopups();
$this->convertSettings();
$popupPreviewId = get_option('popupPreviewId');
foreach ($popups as $popup) {
// we should not convert preview popup
if ($popup['id'] == $popupPreviewId) {
$popupObj = $this->popupObjectFromArray($popup);
'post_title' => $popupObj->getTitle(),
'post_content' => $popupObj->getContent(),
'post_status' => 'publish',
'post_type' => SG_POPUP_POST_TYPE
$id = $popupObj->getId();
$newOptions = $this->getNewOptionsFormSavedData($popupObj);
$newPopupId = @wp_insert_post($args);
$newOptions['sgpb-post-id'] = $newPopupId;
$this->saveOtherOptions($newOptions);
update_post_meta($newPopupId, 'sg_popup_options', $newOptions);
$idsMapping[$id] = $newPopupId;
$this->convertCounter($idsMapping);
$this->convertSubscribers();
update_option('sgpbConvertedIds', $idsMapping);
public function convertSubscribers()
$oldsubscribersTableName = $wpdb->prefix.'sg_subscribers';
$subscribersTableName = $wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME;
$subscribers = $wpdb->get_results( $wpdb->prepare( "SELECT `id`, `firstName`, `lastName`, `email`, `subscriptionType`, `status` from $oldsubscribersTableName" ), ARRAY_A);
if (empty($subscribers)) {
foreach ($subscribers as $subscriber) {
$subscriber['subscriptionType'] = $this->getPostByTitle($subscriber['subscriptionType']);
$wpdb->query( $wpdb->prepare("INSERT INTO $subscribersTableName (`firstName`, `lastName`, `email`, `cDate`, `subscriptionType`, `unsubscribed`) VALUES (%s, %s, %s, %s, %d, %d) ", $subscriber['firstName'], $subscriber['lastName'], $subscriber['email'], $date, $subscriber['subscriptionType'], 0) );
private function getPostByTitle($pageTitle, $output = OBJECT)
$post = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type='popupbuilder'", $pageTitle));
return get_post($post, $output)->ID;
* Convert settings section saved options to new version
private function convertSettings()
$settings = $wpdb->get_row('SELECT options FROM '.$wpdb->prefix .'sg_popup_settings WHERE id = 1', ARRAY_A);
if (empty($settings['options'])) {
$settings = json_decode($settings['options'], true);
if (!empty($settings['tables-delete-status'])) {
$userRoles = $settings['plugin_users_role'];
if (empty($userRoles) || !is_array($userRoles)) {
$userRoles = array_map(function($role) {
// it's remove sgpb_ keyword from selected values
$role = substr($role, 5, strlen($role)-1);
update_option('sgpb-user-roles', $userRoles);
update_option('sgpb-dont-delete-data', $deleteData);
private function convertCounter($idsMapping)
$oldCounter = get_option('SgpbCounter');
foreach ($oldCounter as $key => $value) {
if (isset($idsMapping[$key])){
$newId = $idsMapping[$key];
$newCounter[$newId] = $value;
update_option('SgpbCounter', $newCounter);
private function getAllSavedPopups()
$oldsg_popupsTableName = $wpdb->prefix.'sg_popup';
$popups = $wpdb->get_results( $wpdb->prepare("SELECT `id`, `type`, `title`, `options` from $oldsg_popupsTableName ORDER BY id" ), ARRAY_A);
public function getNewOptionsFormSavedData($popup)
$options = $popup->getOptions();
$customOptions = $popup->getCustomOptions();
$options = array_merge($options, $customOptions);
// return addons event from add_connections data
$addonsEvent = $this->getAddonsEventFromPopup($popup);
$options = array_merge($options, $addonsEvent);
$options = $this->filterOptions($options);
$names = $this->getNamesMapping();
$type = $popup->getType();
$newData['sgpb-type'] = $type;
foreach ($names as $oldName => $newName) {
if (isset($options[$oldName])) {
$optionName = $this->changeOldValues($oldName, $options[$oldName]);
$newData[$newName] = $optionName;
$newData['sgpb-enable-popup-overlay'] = 'on';
$newData['sgpb-show-background'] = 'on';
private function saveOtherOptions($options)
$popupId = (int)$options['sgpb-post-id'];
$conditions['sgpb-target'] = array(array(array('param' => 'not_rule')));
$conditions['sgpb-conditions'] = array(array());
$eventsInitialData = array(
if (!empty($options['sgpb-option-exit-intent-enable'])) {
$eventsInitialData[0][] = array(
'value' => isset($options['sgpb-option-exit-intent-type']) ? $options['sgpb-option-exit-intent-type'] : '',
'sgpb-exit-intent-expire-time' => isset($options['sgpb-exit-intent-expire-time']) ? $options['sgpb-exit-intent-expire-time'] : '',
'sgpb-exit-intent-cookie-level' => isset($options['sgpb-exit-intent-cookie-level']) ? $options['sgpb-exit-intent-cookie-level'] : '',
'sgpb-exit-intent-soft-from-top' => isset($options['sgpb-exit-intent-soft-from-top']) ? $options['sgpb-exit-intent-soft-from-top'] : ''
else if (!empty($options['sgpb-option-enable-ad-block'])) {
$eventsInitialData[0][] = array(
'value' => $options['sgpb-popup-delay'],
'hiddenOption' => array()
if (!empty($options['sgpb-inactivity-status'])) {
$eventsInitialData[0][] = array(
'value' => isset($options['sgpb-inactivity-timer']) ? $options['sgpb-inactivity-timer'] : '',
'hiddenOption' => array()
if (!empty($options['sgpb-onscroll-status'])) {
$eventsInitialData[0][] = array(
'value' => isset($options['sgpb-onscroll-percentage']) ? $options['sgpb-onscroll-percentage'] : '',
'hiddenOption' => array()
if (empty($eventsInitialData[0])) {
$eventsInitialData[0][] = array('param' => 'load', 'value' => '');
update_post_meta($popupId, 'sg_popup_events', $eventsInitialData);
// by user status (logged in/out)
if (!empty($options['sgpb-by-user-status'])) {
if (isset($options['sgpb-for-logged-in-user']) && $options['sgpb-for-logged-in-user'] === 'false') {
$conditions['sgpb-conditions'][0][] = array(
'param' => 'groups_user_role',
// hide or show on mobile
if (isset($options['sgpb-hide-on-mobile']) && $options['sgpb-hide-on-mobile'] == 'on') {
$conditions['sgpb-conditions'][0][] = array(
'param' => 'groups_devices',
if (isset($options['sgpb-only-on-mobile']) && $options['sgpb-only-on-mobile'] == 'on') {
$conditions['sgpb-conditions'][0][] = array(
'param' => 'groups_devices',
if (isset($options['sgpb-by-country']) && $options['sgpb-by-country'] == 'on') {
if (isset($options['sgpb-allow-countries'])) {
$options['sgpb-allow-countries'] = '!=';
if ($options['sgpb-allow-countries'] == 'allow') {
$options['sgpb-allow-countries'] = '==';
$conditions['sgpb-conditions'][0][] = array(
'param' => 'groups_countries',
'operator' => isset($options['sgpb-allow-countries']) ? $options['sgpb-allow-countries'] : '',
'value' => explode(',', (isset($options['sgpb-countries-iso']) ? $options['sgpb-countries-iso'] : ''))
update_post_meta($popupId, 'sg_popup_target', $conditions);
if (isset($options['sgpb-random-popup']) && $options['sgpb-random-popup'] == 'on') {
$randomPopupCategory = AdminHelper::getTaxonomyBySlug(SG_RANDOM_TAXONOMY_SLUG);
wp_set_object_terms($popupId, SG_RANDOM_TAXONOMY_SLUG, SG_POPUP_CATEGORY_TAXONOMY, true);
$this->saveProTarget($options);
$mailchimpApiKey = get_option("SG_MAILCHIMP_API_KEY");
update_option('SGPB_MAILCHIMP_API_KEY', $mailchimpApiKey);
$aweberAccessToken = get_option('sgAccessToken');
if ($aweberAccessToken) {
$requestTokenSecret = get_option('requestTokenSecret');
$accessTokenSecret = get_option('sgAccessTokenSecret');
update_option('sgpbRequestTokenSecret', $requestTokenSecret);
update_option('sgpbAccessTokenSecret', $accessTokenSecret);
update_option('sgpbAccessToken', $aweberAccessToken);
public function saveProTarget($options)
$popupId = (int)$options['sgpb-post-id'];
// It's got already saved targets for do not override already saved data
$popupSavedTarget = get_post_meta($popupId, 'sg_popup_target');
$target['sgpb-target'] = array();
$target['sgpb-conditions'] = array();
if (!empty($popupSavedTarget[0]['sgpb-conditions'])) {
$target['sgpb-conditions'] = $popupSavedTarget[0]['sgpb-conditions'];
if (!empty($options['allPagesStatus'])) {
if ($options['allPages'] == 'selected') {
$savedPages = isset($options['allSelectedPages']) ? (array)$options['allSelectedPages'] : array();
$savedPagesValues = array_values($savedPages);
// -1 mean saved for home page
if (in_array('-1', $savedPagesValues)) {
'post__in' => $savedPagesValues,
$searchResults = SGPBConfigDataHelper::getPostTypeData($args);
if (!empty($searchResults)) {
$target['sgpb-target'][0][] = array('param' => 'page_selected', 'operator' => '==', 'value' => $searchResults);
$target['sgpb-target'][0][] = array('param' => 'page_all', 'operator' => '==');
if (!empty($options['allPostsStatus'])) {
$allPosts = $options['allPosts'];
if ($allPosts == 'selected') {
$savedPosts = (array)$options['allSelectedPosts'];
$savedPostsValues = array_values($savedPosts);
// -1 mean saved for home page
if (in_array('-1', $savedPostsValues)) {
'post__in' => $savedPostsValues,
$searchResults = SGPBConfigDataHelper::getPostTypeData($args);
if (!empty($searchResults)) {
$target['sgpb-target'][0][] = array('param' => 'post_selected', 'operator' => '==', 'value' => $searchResults);
else if ($allPosts == 'all') {
$target['sgpb-target'][0][] = array('param' => 'post_all', 'operator' => '==');
$selectedPostCategories = array_values($options['posts-all-categories']);
$target['sgpb-target'][0][] = array('param' => 'post_category', 'operator' => '==', 'value' => $selectedPostCategories);
$target['sgpb-target'][0][] = array('param' => 'page_type', 'operator' => '==', 'value' => array('is_home_page', 'is_home'));
if (!empty($options['allCustomPostsStatus'])) {
$customPostTypes = $options['all-custom-posts'];
if (!empty($customPostTypes)) {
$selectedCustomPosts = $options['allSelectedCustomPosts'];
if ($options['showAllCustomPosts'] == 'selected') {
foreach ($customPostTypes as $customPostType) {
'post__in' => array_values($selectedCustomPosts),
'post_type' => $customPostType
$searchResults = SGPBConfigDataHelper::getPostTypeData($args);
if (!empty($searchResults)) {
$target['sgpb-target'][0][] = array('param' => $customPostType.'_selected', 'operator' => '==', 'value' => $searchResults);
$target['sgpb-target'][0][] = array('param' => 'post_type', 'operator' => '==', 'value' => array_values($customPostTypes));
update_post_meta($popupId, 'sg_popup_target', $target);