: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Returns separate popup types Free or Pro
* @return array $popupTypesObj
public static function getPopupTypes()
global $SGPB_POPUP_TYPES;
$popupTypesObj = array();
$popupTypes = $SGPB_POPUP_TYPES['typeName'];
foreach ($popupTypes as $popupType => $level) {
$level = SGPB_POPUP_PKG_FREE;
$popupTypeObj = new PopupType();
$popupTypeObj->setName($popupType);
$popupTypeObj->setAccessLevel($level);
if (SGPB_POPUP_PKG >= $level) {
$popupTypeObj->setAvailable(true);
$popupTypesObj[] = $popupTypeObj;
public static function savePopupsFromContentClasses($content, $post)
$clickClassIds = self::getStringNextNumbersByReg($content, 'sg-popup-id-');
if (!empty($clickClassIds)) {
foreach ($clickClassIds as $id) {
$id = apply_filters('sgpbConvertedPopupId', $id);
if (empty($eventsData[$postId][$id])) {
$eventsData[$postId][$id] = array('click');
$eventsData[$postId][$id][] = 'click';
if (empty($targetData[$postId])) {
$targetData[$postId] = array($id);
$targetData[$postId][] = $id;
$iframeClassIs = self::getStringNextNumbersByReg($content, 'sg-iframe-popup-');
if (!empty($iframeClassIs)) {
foreach ($iframeClassIs as $id) {
$id = apply_filters('sgpbConvertedPopupId', $id);
$popupObj = self::find($id);
// this event should work only for iframe popup type
if ($popupObj->getType() != 'iframe') {
if (empty($eventsData[$postId][$id])) {
$eventsData[$postId][$id] = array('iframe');
$eventsData[$postId][$id][] = 'iframe';
if (empty($targetData[$postId])) {
$targetData[$postId] = array($id);
$targetData[$postId][] = $id;
$confirmClassIds = self::getStringNextNumbersByReg($content, 'sg-confirm-popup-');
if (!empty($confirmClassIds)) {
foreach ($confirmClassIds as $id) {
$id = apply_filters('sgpbConvertedPopupId', $id);
if (empty($eventsData[$postId][$id])) {
$eventsData[$postId][$id] = array('confirm');
$eventsData[$postId][$id][] = 'confirm';
if (empty($targetData[$postId])) {
$targetData[$postId] = array($id);
$targetData[$postId][] = $id;
$hoverClassIds = self::getStringNextNumbersByReg($content, 'sg-popup-hover-');
if (!empty($hoverClassIds)) {
foreach ($hoverClassIds as $id) {
$id = apply_filters('sgpbConvertedPopupId', $id);
if (empty($eventsData[$postId][$id])) {
$eventsData[$postId][$id] = array('hover');
$eventsData[$postId][$id][] = 'hover';
if (empty($targetData[$postId])) {
$targetData[$postId] = array($id);
$targetData[$postId][] = $id;
$targetData = apply_filters('sgpbPopupTargetData', $targetData);
$eventsData = apply_filters('sgpbPopupEventsData', $eventsData);
self::saveToTargetFromPage($targetData);
self::saveToEventsFromPage($eventsData);
public static function getStringNextNumbersByReg($content, $key)
preg_match_all("/(?<=$key)(\d+)/", $content, $ids);
private static function saveToTargetAndEvents($popupsShortcodsInPostPage, $postId)
if (empty($popupsShortcodsInPostPage)) {
foreach ($popupsShortcodsInPostPage as $shortcodesData) {
$popupId = apply_filters('sgpbConvertedPopupId', $shortcodesData['id']);
'post_type' => SG_POPUP_POST_TYPE,
'post__in' => array($popupId)
$postById = SGPBConfigDataHelper::getPostTypeData($args);
//When target data does not exist
// collect custom inserted popups
if (empty($customPopups[$postId])) {
$customPopups[$postId] = array($popupId);
$customPopups[$postId][] = $popupId;
// collect custom inserted popups events
if (empty($shortcodesData['event'])) {
$eventName = $shortcodesData['event'];
if ($eventName == 'onload') {
$eventName = 'attr'.$eventName;
$currentEventData = array(
if (empty($customEvents[$postId][$popupId])) {
$customEvents[$postId][$popupId] = array($currentEventData);
$customEvents[$postId][$popupId][] = $currentEventData;
self::saveToTargetFromPage($customPopups);
self::saveToEventsFromPage($customEvents);
public static function getPostPopupCustomEvent($postId, $popupId)
$customEventsData = self::getCustomInsertedPopupEventsByPostId($postId);
if (!empty($customEventsData[$popupId])) {
$events = $customEventsData[$popupId];
* Save popup to custom events from pages
* @param array $customEvents
public static function saveToEventsFromPage($customEvents)
if (empty($customEvents)) {
foreach ($customEvents as $postId => $popupsData) {
$savedCustomEvents = self::getCustomInsertedPopupEventsByPostId($postId);
$result = AdminHelper::arrayMergeSameKeys($popupsData, $savedCustomEvents);
update_post_meta($postId, 'sgpb_popup_events_custom', $result);
public static function getCustomInsertedPopupEventsByPostId($postId)
$postMetaData = get_post_meta($postId, 'sgpb_popup_events_custom', true);
if (!empty($postMetaData)) {
$eventsData = $postMetaData;
* Save popup to custom targets from pages
* @param array $customPopups
public static function saveToTargetFromPage($customPopups)
if (!empty($customPopups)) {
foreach ($customPopups as $postId => $popups) {
$alreadySavedPopups = self::getCustomInsertedDataByPostId($postId);
$popups = array_merge($popups, $alreadySavedPopups);
update_post_meta($postId, 'sg_popup_target_custom', $popups);
* Get popup custom targes form saved data
* @return array $postData
public static function getCustomInsertedDataByPostId($postId)
$postMetaData = get_post_meta($postId, 'sg_popup_target_custom');
if (!empty($postMetaData[0])) {
$postData = $postMetaData[0];
public static function getPopupShortcodeMatchesFromContent($content)
$pattern = get_shortcode_regex();
if (preg_match_all('/'.$pattern.'/s', $content, $matches)
&& array_key_exists( 2, $matches )
&& in_array('sg_popup', $matches[2])
public static function renderPopupContentShortcode($content, $popupId, $event, $args)
if (!empty($args['wrap'])) {
if ($args['wrap'] == $wrap) {
$args['href'] = 'javascript:void(0)';
$wrap = esc_attr( $args['wrap'] );
$attr = AdminHelper::createAttrs($args);
$allowed_html = AdminHelper::allowed_html_tags();
$allowed_wrap_html_tags = AdminHelper::allowed_wrap_html_tags();
if( !in_array( $wrap, $allowed_wrap_html_tags ) )
<<?php echo wp_kses_post($wrap); ?>
<?php if ($wrap == 'a') : ?>
href="javascript:void(0)"
class="sgpb-show-popup <?php echo esc_attr('sgpb-popup-id-'.$popupId); ?>"
data-sgpbpopupid="<?php echo esc_attr($popupId); ?>"
data-popup-event="<?php echo esc_attr($event); ?>"
<?php echo esc_attr($attr); ?>>
<?php echo wp_kses($content, $allowed_html); ?>
</<?php echo esc_attr($wrap); ?>>
$shortcodeContent = ob_get_contents();
return $shortcodeContent;
private static function collectInsidePopupShortcodes($content)
$pattern = get_shortcode_regex();
if (preg_match_all('/'.$pattern.'/s', $content, $matches)
&& array_key_exists( 2, $matches )
&& in_array('sg_popup', $matches[2])
foreach ($matches[0] as $key => $value) {
//return current shortcode all attrs as assoc array
$attrs = shortcode_parse_atts($matches[3][$key]);
if (!empty($attrs['id'])) {
$currentAttrs['id'] = $attrs['id'];
if (!empty($attrs['insidepopup'])) {
$currentAttrs['insidepopup'] = $attrs['insidepopup'];
if (empty($attrs['insidepopup']) || (!empty($attrs['insidepopup']) && $attrs['insidepopup'] != 'on')) {
$options[$currentAttrs['id']] = $value;
return apply_filters('sgpbPopupInsideShortcodes', $options);
* Collect all popups by taxonomy slug
* @param string $popupTermSlug category slug name
* @return array $popupIds random popups id
public static function getPopupsByTermSlug($popupTermSlug)
$termPopups = get_transient(SGPB_TRANSIENT_POPUPS_TERMS);
if ($termPopups === false) {
'post_type' => 'popupbuilder',
'taxonomy' => SG_POPUP_CATEGORY_TAXONOMY,
'terms' => $popupTermSlug
set_transient(SGPB_TRANSIENT_POPUPS_TERMS, $termPopups, SGPB_TRANSIENT_TIMEOUT_WEEK);
if (empty($termPopups)) {
foreach ($termPopups as $termPopup) {
$popupIds[] = $termPopup->ID;
public function boolToChecked($var)
return ($var?'checked':'');
* Delete custom inserted data
* @param int $postId current post page id
public static function deletePostCustomInsertedData($postId)
delete_post_meta($postId, 'sg_popup_target_custom');
* Delete custom inserted events
* @param int $postId current post page id
public static function deletePostCustomInsertedEvents($postId)
delete_post_meta($postId, 'sgpb_popup_events_custom');
* If popup Type does not have getPopupTypeOptions method
* it's tell popup does not have custom options
public function getPopupTypeOptionsView()
* If popup Type does not have getPopupTypeOptions method
* it's tell popup does not have custom options
public function getPopupTypeMainView()