: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
public function supportLinks()
if (SGPB_POPUP_PKG == SGPB_POPUP_PKG_FREE) {
if (method_exists($this->customPostTypeObj, 'supportLinks')) {
$this->customPostTypeObj->supportLinks();
public function popupMetaboxes()
$this->customPostTypeObj->addPopupMetaboxes();
public function savePost($postId = 0, $post = array(), $update = false)
if ($post->post_type !== SG_POPUP_POST_TYPE) {
if( !isset( $_POST['sgpb-type'] ) )
$nonce = isset( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : '';
if ( empty( $nonce ) || !wp_verify_nonce( $nonce, 'update-post_'.$postId ) ) {
$allowToAction = AdminHelper::userCanAccessTo();
Functions::clearAllTransients();
// Do not processing the whole input
$sgpb_postData = array_filter(
function ($key) { return preg_match('/sgpb-*/', $key) === 1;},
$postData = SGPopup::parsePopupDataFromData($sgpb_postData);
$postData['sgpb-post-id'] = $postId;
if (isset($postData['sgpb-is-preview']) && $postData['sgpb-is-preview'] == 1) {
SgpbPopupConfig::popupTypesInit();
if ($post->post_status != 'draft') {
$popupContent = $post->post_content;
'post_parent' => $postId,
'post_type' => 'revision',
'post_status' => 'inherit'
$query = apply_filters('sgpbSavePostQuery', $query);
while ($query->have_posts()) {
$popupContent = $popup->post_content;
if ($post->post_status == 'draft') {
/* In preview mode saveMode should be true*/
if ((!empty($post) && $post->post_type == SG_POPUP_POST_TYPE) || $saveMode || (empty($post) && !$saveMode)) {
wp_redirect(get_home_url());
if (!empty($postData['sgpb-type'])) {
$popupType = $postData['sgpb-type'];
$popupClassName = SGPopup::getPopupClassNameFormType($popupType);
$popupClassPath = SGPopup::getPopupTypeClassPath($popupType);
require_once($popupClassPath.$popupClassName.'.php');
$popupClassName = __NAMESPACE__.'\\'.$popupClassName;
$popupClassName::create($postData, $saveMode, 1);
$content = get_post_field('post_content', $postId);
SGPopup::deletePostCustomInsertedData($postId);
SGPopup::deletePostCustomInsertedEvents($postId);
/*We detect all the popups that were inserted as a custom ones, in the content.*/
SGPopup::savePopupsFromContentClasses($content, $post);
* Check Popup is satisfy for popup condition
public function conditionsSatisfy($args = array())
if (isset($args['status']) && $args['status'] === false) {
$args['status'] = PopupChecker::checkOtherConditionsActions($args);
public function popupsTableColumnsValues($column, $postId)
$postId = (int)sanitize_text_field($postId);// Convert to int for security reasons
$args['status'] = array('publish', 'draft', 'pending', 'private', 'trash');
$popup = SGPopup::find($postId, $args);
if (empty($popup) && $post_type == SG_POPUP_POST_TYPE) {
if ($column == 'shortcode') {
$shortcodeInput = '<input type="text" onfocus="this.select();" readonly value="[sg_popup id='.esc_attr($postId).']" class="large-text code">';
echo wp_kses($shortcodeInput, AdminHelper::allowed_html_tags());
if ($column == 'className') {
$className = '<input type="text" onfocus="this.select();" readonly value="sg-popup-id-'.esc_attr($postId).'" class="large-text code">';
echo wp_kses($className, AdminHelper::allowed_html_tags());
else if ($column == 'counter') {
$count = $popup->getPopupOpeningCountById($postId);
$counter = '<div ><span>'.$count.'</span>'.'<input onclick="SGPBBackend.resetCount('.esc_attr($postId).', true);" type="button" name="" class="sgpb-btn sgpb-btn-dark-outline" value="'.__('reset', 'popup-builder').'"></div>';
echo wp_kses($counter, AdminHelper::allowed_html_tags());
else if ($column == 'type') {
global $SGPB_POPUP_TYPES;
$type = $popup->getType();
if (isset($SGPB_POPUP_TYPES['typeLabels'][$type])) {
$type = $SGPB_POPUP_TYPES['typeLabels'][$type];
else if ($column == 'onOff') {
$popupPostStatus = get_post_status($postId);
if ($popupPostStatus == 'publish' || $popupPostStatus == 'draft'|| $popupPostStatus == 'private') {
$isActive = $popup->getOptionValue('sgpb-is-active', true);
$checked = isset($isActive) && $isActive ? 'checked' : '';
$switcher = '<label class="sgpb-switch">
<input class="sg-switch-checkbox sgpb-popup-status-js" value="1" data-switch-id="'.esc_attr($postId).'" type="checkbox" '.esc_attr($checked).'>
<div class="sgpb-slider sgpb-round"></div>
echo wp_kses($switcher, AdminHelper::allowed_html_tags());
else if ($column == 'sgpbIsRandomEnabled') {
$showValues = apply_filters('sgpbAddRandomTableColumnValues', $postId);
echo wp_kses($showValues, AdminHelper::allowed_html_tags());
else if ($column == 'options') {
$cloneUrl = AdminHelper::popupGetClonePostLink($postId);
$actionButtons = '<div class="icon icon_blue">
<img src="'.SG_POPUP_PUBLIC_URL.'icons/iconEdit.png" title="Edit" alt="Edit" class="icon_edit" onclick="location.href=\''.get_edit_post_link($postId).'\'">
$actionButtons .= '<div class="icon icon_blue">
<img src="'.SG_POPUP_PUBLIC_URL.'icons/iconClone.png" title="Clone" alt="Clone" class="icon_clone" onclick="location.href=\''.esc_url($cloneUrl).'\'">
$actionButtons .= '<div class="icon icon_pink">
<img src="'.SG_POPUP_PUBLIC_URL.'icons/recycle-bin.svg" title="Remove" alt="Remove" class="icon_remove" onclick="location.href=\''.get_delete_post_link($postId).'\'">
echo wp_kses($actionButtons, AdminHelper::allowed_html_tags());
* This function calls the creation of a new copy of the selected post (by default preserving the original publish status)
* then redirects to the post list
public function popupSaveAsNew($status = '')
* We only allow administrator to do this action
if ( ! current_user_can( 'manage_options' ) ) {
wp_die(esc_html__('You do not have permission to clone the popup!', 'popup-builder'));
$nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( $_REQUEST['_wpnonce'] ) : '';
$postId = (int) sanitize_text_field($_REQUEST['post']);
if ( empty( $nonce ) || !wp_verify_nonce( $nonce, 'duplicate-post_'.$postId ) ) {
wp_die(esc_html__('You do not have permission to clone the popup!', 'popup-builder'));
if (!(isset($_GET['post']) || isset($_POST['post']) || (isset($_REQUEST['action']) && 'popupSaveAsNew' == sanitize_text_field($_REQUEST['action'])))) {
wp_die(esc_html__('No post to duplicate has been supplied!', 'popup-builder'));
$id = (isset($_GET['post']) ? sanitize_text_field($_GET['post']) : sanitize_text_field($_POST['post']));
check_admin_referer('duplicate-post_'.$id);
// Copy the post and insert it
if (isset($post) && $post != null) {
$newId = $this->popupCreateDuplicate($post, $status);
$postType = $post->post_type;
$sendBack = wp_get_referer();
strpos($sendBack, 'post.php') !== false ||
strpos($sendBack, 'post-new.php') !== false) {
if ('attachment' == $postType) {
$sendBack = admin_url('upload.php');
$sendBack = admin_url('edit.php');
$sendBack = add_query_arg('post_type', $postType, $sendBack);
$sendBack = remove_query_arg(array('trashed', 'untrashed', 'deleted', 'cloned', 'ids'), $sendBack);
// Redirect to the post list screen
wp_redirect(add_query_arg(array('cloned' => 1, 'ids' => $post->ID), $sendBack));
// Redirect to the edit screen for the new draft post
wp_redirect(add_query_arg(array('cloned' => 1, 'ids' => $post->ID), admin_url('post.php?action=edit&post='.$newId)));
/* translators: ID of original. */
wp_die( sprintf( wp_kses_post( __('Copy creation failed, could not find original: %d','popup-builder') ), esc_html( $id ) ) );
* Create a duplicate from a post
public function popupCreateDuplicate($post, $status = '', $parent_id = '')
$newPostStatus = (empty($status))? $post->post_status: $status;
if ($post->post_type != 'attachment') {
$title = $post->post_title;
$title = __('(no title) (clone)');
$title .= ' '.__('(clone)');
if ('publish' == $newPostStatus || 'future' == $newPostStatus) {
// check if the user has the right capability
if (is_post_type_hierarchical($post->post_type)) {
if (!current_user_can('publish_pages')) {
$newPostStatus = 'pending';
if (!current_user_can('publish_posts')) {
$newPostStatus = 'pending';
$newPostAuthor = wp_get_current_user();
$newPostAuthorId = $newPostAuthor->ID;
// check if the user has the right capability
if (is_post_type_hierarchical($post->post_type)) {
if (current_user_can('edit_others_pages')) {
$newPostAuthorId = $post->post_author;
if (current_user_can('edit_others_posts')) {
$newPostAuthorId = $post->post_author;
'menu_order' => $post->menu_order,
'comment_status' => $post->comment_status,
'ping_status' => $post->ping_status,
'post_author' => $newPostAuthorId,
'post_content' => $post->post_content,
'post_content_filtered' => $post->post_content_filtered,
'post_excerpt' => $post->post_excerpt,
'post_mime_type' => $post->post_mime_type,
'post_parent' => $newPostParent = empty($parent_id)? $post->post_parent : $parent_id,
'post_password' => $post->post_password,
'post_status' => $newPostStatus,
'post_type' => $post->post_type,
$newPost['post_date'] = $newPostDate = $post->post_date;
$newPost['post_date_gmt'] = get_gmt_from_date($newPostDate);
$newPostId = wp_insert_post(wp_slash($newPost));
// If the copy is published or scheduled, we have to set a proper slug.
if ($newPostStatus == 'publish' || $newPostStatus == 'future') {
$postName = $post->post_name;
$postName = wp_unique_post_slug($postName, $newPostId, $newPostStatus, $post->post_type, $newPostParent);
$newPost['ID'] = $newPostId;
$newPost['post_name'] = $postName;
// Update the post into the database
wp_update_post(wp_slash($newPost));
// If you have written a plugin which uses non-WP database tables to save
// information about a post you can hook this action to dupe that data.
if ($post->post_type == 'page' || is_post_type_hierarchical($post->post_type)) {
do_action('dp_duplicate_page', $newPostId, $post, $status);
do_action('sgpb_duplicate_post', $newPostId, $post, $status);
delete_post_meta($newPostId, '_sgpb_original');
add_post_meta($newPostId, '_sgpb_original', $post->ID);
* Copy the meta information of a post to another post
public function popupCopyPostMetaInfo($newId, $post)
$postMetaKeys = get_post_custom_keys($post->ID);
if (empty($postMetaKeys) || !is_array($postMetaKeys)) {
$metaBlacklist = explode(',', $metaBlacklist);
$metaBlacklist = array_filter($metaBlacklist);
$metaBlacklist = array_map('trim', $metaBlacklist);
$metaBlacklist[] = '_edit_lock';
$metaBlacklist[] = '_edit_last';
$metaBlacklist[] = '_wp_page_template';
$metaBlacklist[] = '_thumbnail_id';
$metaBlacklist = apply_filters('duplicate_post_blacklist_filter' , $metaBlacklist);
$metaBlacklistString = '('.implode(')|(',$metaBlacklist).')';
if (strpos($metaBlacklistString, '*') !== false) {
$metaBlacklistString = str_replace(array('*'), array('[a-zA-Z0-9_]*'), $metaBlacklistString);
foreach ($postMetaKeys as $metaKey) {
if (!preg_match('#^'.$metaBlacklistString.'$#', $metaKey)) {
$metaKeys = array_diff($postMetaKeys, $metaBlacklist);
$metaKeys = apply_filters('duplicate_post_meta_keys_filter', $metaKeys);
foreach ($metaKeys as $metaKey) {
$metaValues = get_post_custom_values($metaKey, $post->ID);
foreach ($metaValues as $metaValue) {
$metaValue = maybe_unserialize($metaValue);
if (is_array($metaValue)) {
$metaValue['sgpb-post-id'] = $newId;
add_post_meta($newId, $metaKey, $this->popupWpSlash($metaValue));
public function popupAddSlashesDeep($value)
if (function_exists('map_deep')) {
return map_deep($value, array($this, 'popupAddSlashesToStringsOnly'));
public function popupAddSlashesToStringsOnly($value)
return is_string($value) ? addslashes($value) : $value;
public function popupWpSlash($value)
return $this->popupAddSlashesDeep($value);
public function removePostPermalink($args)
if ($post_type == SG_POPUP_POST_TYPE && is_admin()) {
// hide permalink for popupbuilder post type
// remove link ( e.g.: (View post) ), from popup updated/published message
public function popupPublishedMessage($messages)
if ($post_type == SG_POPUP_POST_TYPE) {
if (isset($messages['post'][1])) {
$messages['post'][1] = __('Popup updated.', 'popup-builder');
if (isset($messages['post'][6])) {
$messages['post'][6] = __('Popup published.', 'popup-builder');
$messages = apply_filters('sgpbPostUpdateMessage', $messages);
private function subscriberFields() {
return array('id', 'firstName', 'lastName', 'email', 'cDate', 'subscriptionType');
public function getSubscribersCsvFile()
$allowToAction = AdminHelper::userCanAccessTo();
wp_redirect(get_home_url());
$fields = $this->subscriberFields();
$query = AdminHelper::subscribersRelatedQuery();
if (isset($_GET['orderby']) && !empty($_GET['orderby'])) {
$orderBy = sanitize_text_field($_GET['orderby']);
if (!in_array($orderBy, $fields)){
wp_redirect(get_home_url());
if (isset($_GET['order']) && !empty($_GET['order'])) {
$order = array('ASC', 'DESC');
if (!in_array(sanitize_text_field($_GET['order']), $order)){
wp_redirect(get_home_url());
$query .= ' ORDER BY '.$orderBy.' '.sanitize_text_field($_GET['order']);
$rows = array('first name', 'last name', 'email', 'date', 'popup');