: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
public function popupMediaButton()
if (!$this->mediaButton) {
$this->mediaButton = true;
self::enqueueScriptsForPageBuilders();
if (function_exists('get_current_screen')) {
$screen = get_current_screen();
echo wp_kses(new MediaButton(), AdminHelper::allowed_html_tags());
public function editorButton($plugins)
if (empty($this->mediaButton)) {
$this->mediaButton = true;
$currentPostType = AdminHelper::getCurrentPostType();
add_action('admin_footer', function() use ($currentPostType) {
self::enqueueScriptsForPageBuilders();
if (!empty($currentPostType) && $currentPostType == SG_POPUP_POST_TYPE) {
require_once(SG_POPUP_VIEWS_PATH.'htmlCustomButtonElement.php');
public static function enqueueScriptsForPageBuilders()
require_once(ABSPATH.'wp-admin/includes/screen.php');
if (function_exists('get_current_screen')) {
$screen = get_current_screen();
if ((!empty($screen->id) && $screen->id == SG_POPUP_POST_TYPE) || !empty($post)) {
if (!isset($_GET['fl_builder'])) {
Javascript::enqueueScripts('post-new.php');
Style::enqueueStyles('post-new.php');
else if (isset($_GET['fl_builder'])) {
Javascript::enqueueScripts('post-new.php');
Style::enqueueStyles('post-new.php');
public function userRolesCaps()
$userSavedRoles = get_option('sgpb-user-roles');
$userSavedRoles = array('administrator');
array_push($userSavedRoles, 'administrator');
foreach ($userSavedRoles as $theRole) {
$role = get_role($theRole);
$role->add_cap('read_post');
$role->add_cap('read_private_sgpb_popups');
$role->add_cap('edit_sgpb_popup');
$role->add_cap('edit_sgpb_popups');
$role->add_cap('edit_others_sgpb_popups');
$role->add_cap('edit_published_sgpb_popups');
$role->add_cap('publish_sgpb_popups');
$role->add_cap('delete_sgpb_popups');
$role->add_cap('delete_published_posts');
$role->add_cap('delete_others_sgpb_popups');
$role->add_cap('delete_private_sgpb_popups');
$role->add_cap('delete_private_sgpb_popup');
$role->add_cap('delete_published_sgpb_popups');
// For popup builder sub-menus and terms
$role->add_cap('sgpb_manage_options');
$role->add_cap('manage_popup_terms');
$role->add_cap('manage_popup_categories_terms');
$role = apply_filters('sgpbUserRoleCap', $role);
public function pluginActivated()
if (!get_option('sgpbActivateExtensions') && SGPB_POPUP_PKG != SGPB_POPUP_PKG_FREE) {
$obj = new PopupExtensionActivator();
update_option('sgpbActivateExtensions', 1);
public function sgpbPopupShortcode($args, $content)
if (empty($args) || empty($args['id'])) {
$oldShortcode = isset($args['event']) && $args['event'] === 'onload';
$isInherit = isset($args['event']) && $args['event'] == 'inherit';
$argsId = $popupId = (int)$args['id'];
if (function_exists('sgpb\sgpGetCorrectPopupId')) {
$popupId = sgpGetCorrectPopupId($popupId);
$popup = SGPopup::find($popupId);
$popup = apply_filters('sgpbShortCodePopupObj', $popup);
$event = preg_replace('/on/', '', (isset($args['event']) ? $args['event'] : ''));
// when popup does not exists or popup post status it's not publish ex when popup in trash
if (empty($popup) || (!is_object($popup) && $popup != 'publish')) {
$isActive = $popup->isActive();
$alreadySavedEvents = $popup->getEvents();
$loadableMode = $popup->getLoadableModes();
if (!isset($args['event']) && isset($args['insidepopup'])) {
unset($args['insidepopup']);
$insideShortcodeKey = $popupId.$event;
// for prevent infinity chain
if (is_array($this->insideShortcodes) && in_array($insideShortcodeKey, $this->insideShortcodes)) {
$shortcodeContent = SGPopup::renderPopupContentShortcode($content, $argsId, $event, $args);
return $shortcodeContent;
$this->insideShortcodes[] = $insideShortcodeKey;
// if no event attribute is set, or old shortcode
if (!isset($args['event']) || $oldShortcode || $isInherit) {
$loadableMode = $popup->getLoadableModes();
$alreadySavedEvents = false;
// for old popup, after the update, there aren't any events
if (empty($alreadySavedEvents)) {
if (!empty($args['event'])) {
$event = preg_replace('/on/', '', $event);
$popup->setEvents(array($event));
if (empty($loadableMode)) {
$loadableMode['option_event'] = true;
$event = preg_replace('/on/', '', $event);
$popup->setEvents(array($event));
$popup->setLoadableModes($loadableMode);
$groupObj = new PopupGroupFilter();
$groupObj->setPopups(array($popup));
$loadablePopups = $groupObj->filter();
$scriptsLoader = new ScriptsLoader();
$scriptsLoader->setLoadablePopups($loadablePopups);
$scriptsLoader->loadToFooter();
$matches = SGPopup::getPopupShortcodeMatchesFromContent($content);
foreach ($matches[0] as $key => $value) {
$attrs = shortcode_parse_atts($matches[3][$key]);
if (empty($attrs['id'])) {
$shortcodeContent = SGPopup::renderPopupContentShortcode($content, $attrs['id'], $attrs['event'], $attrs);
if (isset($event) && $event != 'onload' && !empty($content)) {
$shortcodeContent = SGPopup::renderPopupContentShortcode($content, $argsId, $event, $args);
$shortcodeContent = apply_filters('sgpbPopupShortCodeContent', $shortcodeContent);
return do_shortcode($shortcodeContent);
public function deleteSubscribersWithPopup($postId)
if ($post_type == SG_POPUP_POST_TYPE) {
AdminHelper::deleteSubscriptionPopupSubscribers($postId);
public function cronAddMinutes($schedules)
$schedules['sgpb_newsletter_send_every_minute'] = array(
'interval' => SGPB_CRON_REPEAT_INTERVAL * 60,
'display' => __('Once Every Minute', 'popup-builder')
$schedules['sgpb_banners'] = array(
'interval' => SGPB_TRANSIENT_TIMEOUT_WEEK,
'display' => __('Once Every Week', 'popup-builder')
$schedules = apply_filters('sgpbCronTimeoutSettings', $schedules);
public function newsletterSendEmail()
$newsletterOptions = get_option('SGPB_NEWSLETTER_DATA');
if (empty($newsletterOptions)) {
wp_clear_scheduled_hook('sgpb_send_newsletter');
$subscriptionFormId = (int)$newsletterOptions['subscriptionFormId'];
$subscriptionFormTitle = get_the_title($subscriptionFormId);
$emailsInFlow = (int)$newsletterOptions['emailsInFlow'];
$mailSubject = $newsletterOptions['newsletterSubject'];
$fromEmail = $newsletterOptions['fromEmail'];
$emailMessage = $newsletterOptions['messageBody'];
$allAvailableShortcodes = array();
$allAvailableShortcodes['patternFirstName'] = '/\[First name]/';
$allAvailableShortcodes['patternLastName'] = '/\[Last name]/';
$allAvailableShortcodes['patternBlogName'] = '/\[Blog name]/';
$allAvailableShortcodes['patternUserName'] = '/\[User name]/';
$allAvailableShortcodes['patternUnsubscribe'] = '';
$pattern = "/\[(\[?)(Unsubscribe)(?![\w-])([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]\*+(?:\[(?!\/\2\])[^\[]\*+)\*+)\[\/\2\])?)(\]?)/";
preg_match($pattern, $emailMessage, $matches);
$title = __('Unsubscribe', 'popup-builder');
$patternUnsubscribe = $matches[0];
// If user didn't change anything inside the [unsubscribe] shortcode $matches[2] will be equal to 'Unsubscribe'
if ($matches[2] == 'Unsubscribe') {
$pattern = '/\s(\w+?)="(.+?)"]/';
preg_match($pattern, $matches[0], $matchesTitle);
if (!empty($matchesTitle[2])) {
$title = AdminHelper::removeAllNonPrintableCharacters($matchesTitle[2], 'Unsubscribe');
$allAvailableShortcodes['patternUnsubscribe'] = $patternUnsubscribe;
// When email is not valid we don't continue
if (!preg_match('/^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+.[a-zA-Z0-9-.]+$/', $fromEmail)) {
wp_clear_scheduled_hook('sgpb_send_newsletter');
$table_subscription = $wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME;
$selectionQuery = "SELECT id FROM $table_subscription WHERE";
$selectionQuery = apply_filters('sgpbUserSelectionQuery', $selectionQuery);
$result = $wpdb->get_row( $wpdb->prepare("$selectionQuery and subscriptionType = %d limit 1", $subscriptionFormId), ARRAY_A);//db call ok
$currentStateEmailId = (int)$result['id'];
$table_subscription = $wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME;
$totalSubscribers = $wpdb->get_var( $wpdb->prepare("SELECT count(*) FROM $table_subscription WHERE unsubscribed = 0 and subscriptionType = %d", $subscriptionFormId) );
// $currentStateEmailId == 0 when all emails status = 1
if ($currentStateEmailId == 0) {
$headers = 'MIME-Version: 1.0'."\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8'."\r\n";
$successTotal = get_option('SGPB_NEWSLETTER_'.$subscriptionFormId);
$failedTotal = $totalSubscribers - $successTotal;
/* translators: subscription Form Title, success Total ,total Subscribers, failed Total . */
$emailMessageCustom = __('Your mail list %1$s delivered successfully!
%2$d of the %3$d emails succeeded, %4$d failed.
For more details, please download log file inside the plugin.
This email was generated via Popup Builder plugin.', 'popup-builder');
$emailMessageCustom = sprintf($emailMessageCustom, $subscriptionFormTitle, $successTotal, $totalSubscribers, $failedTotal);
wp_mail($fromEmail, $subscriptionFormTitle.' list has been successfully delivered!', $emailMessageCustom, $headers);
delete_option('SGPB_NEWSLETTER_'.$subscriptionFormId);
wp_clear_scheduled_hook('sgpb_send_newsletter');
$getAllDataSql = 'SELECT id, firstName, lastName, email FROM '.$wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME.' WHERE';
$getAllDataSql = apply_filters('sgpbUserSelectionQuery', $getAllDataSql);
$subscribers = $wpdb->get_results( $wpdb->prepare( "$getAllDataSql and id >= %d and subscriptionType = %s limit %d", $currentStateEmailId, $subscriptionFormId, $emailsInFlow), ARRAY_A);
$subscribers = apply_filters('sgpNewsletterSendingSubscribers', $subscribers);
$blogInfo = wp_specialchars_decode( get_bloginfo() );
'From: "'.$blogInfo.'" <'.$fromEmail.'>' ,
'Content-type: text/html; charset=UTF-8'
foreach ($subscribers as $subscriber) {
$replacementId = $subscriber['id'];
$allAvailableShortcodes = apply_filters('sgpbNewsletterShortcodes', $allAvailableShortcodes, $subscriptionFormId, $replacementId);
$replacementFirstName = $subscriber['firstName'];
$replacementLastName = $subscriber['lastName'];
$replacementBlogName = $newsletterOptions['blogname'];
$replacementUserName = $newsletterOptions['username'];
$replacementEmail = $subscriber['email'];
$replacementUnsubscribe = get_home_url();
$replacementUnsubscribe .= '?sgpbUnsubscribe='.md5($replacementId.$replacementEmail);
$replacementUnsubscribe .= '&email='.$subscriber['email'];
$replacementUnsubscribe .= '&popup='.$subscriptionFormId;
$replacementUnsubscribe = '<br><a href="'.$replacementUnsubscribe.'">'.$title.'</a>';
// Replace First name and Last name from email message
$emailMessageCustom = preg_replace($allAvailableShortcodes['patternFirstName'], $replacementFirstName, $emailMessage);
$emailMessageCustom = preg_replace($allAvailableShortcodes['patternLastName'], $replacementLastName, $emailMessageCustom);
$emailMessageCustom = preg_replace($allAvailableShortcodes['patternBlogName'], $replacementBlogName, $emailMessageCustom);
$emailMessageCustom = preg_replace($allAvailableShortcodes['patternUserName'], $replacementUserName, $emailMessageCustom);
$emailMessageCustom = str_replace($allAvailableShortcodes['patternUnsubscribe'], $replacementUnsubscribe, $emailMessageCustom);
if (!empty($allAvailableShortcodes['extraShortcodesWithValues'])) {
$customFields = $allAvailableShortcodes['extraShortcodesWithValues'];
foreach ($customFields as $customFieldKey => $customFieldValue) {
$finalShortcode = '/\['.$customFieldKey.']/';
$emailMessageCustom = preg_replace($finalShortcode, $customFieldValue, $emailMessageCustom);
$emailMessageCustom = stripslashes($emailMessageCustom);
$emailMessageCustom = apply_filters('sgpNewsletterSendingMessage', $emailMessageCustom);
$mailStatus = wp_mail($subscriber['email'], $mailSubject, $emailMessageCustom, $headers);
$table_sgpb_subscription_error_log = $wpdb->prefix.SGPB_SUBSCRIBERS_ERROR_TABLE_NAME;
$wpdb->query( $wpdb->prepare("INSERT INTO $table_sgpb_subscription_error_log (`popupType`, `email`, `date`) VALUES (%s, %s, %s)", $subscriptionFormId, $subscriber['email'], gmdate('Y-m-d H:i')) );continue;
$successCount = get_option('SGPB_NEWSLETTER_'.$subscriptionFormId);
update_option('SGPB_NEWSLETTER_'.$subscriptionFormId, 1);
update_option('SGPB_NEWSLETTER_'.$subscriptionFormId, ++$successCount);
// Update the status of all the sent mails
$table_sgpb_subscription = $wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME;
$wpdb->query( $wpdb->prepare("UPDATE $table_sgpb_subscription SET status = 1 where id >= %d and subscriptionType = %d limit %d", $currentStateEmailId, $subscriptionFormId, $emailsInFlow) );
private function unsubscribe($params = array())
AdminHelper::deleteUserFromSubscribers($params);
public function enqueuePopupBuilderScripts()
if (get_option('SGPB_POPUP_VERSION')) {
ConvertToNewVersion::saveCustomInserted();
$popupLoaderObj = PopupLoader::instance();
if (is_object($popupLoaderObj)) {
$popupLoaderObj->loadPopups();
public function adminLoadPopups($hook)
$allowedPages = apply_filters('sgpbAdminLoadedPages', $allowedPages);
if (!empty($allowedPages) && is_array($allowedPages) && in_array($hook, $allowedPages)) {
$scriptsLoader = new ScriptsLoader();
$scriptsLoader->setIsAdmin(true);
$scriptsLoader->loadToFooter();
public function postTypeInit()
* We only allow administrator to do this action
if ( ! current_user_can( 'manage_options' ) ) {
if (isset($_GET['page']) && sanitize_text_field($_GET['page']) == 'PopupBuilder') {
/* translators: Link to edit Popup item, location. */
esc_html__('Popup Builder plugin has been successfully updated. Please %1$s to go to the new Dashboard of the plugin.', 'popup-builder'),
/* translators: admin Url, Popup Post type. */
'<a href="%1$sedit.php?post_type=%2$s">click here</a>',
esc_html__( 'popupbuilder', 'text-domain' )
AdminHelper::removeUnnecessaryCodeFromPopups();
* We only allow administrator to do this action
if (isset($_POST['sgpb-is-preview']) && $_POST['sgpb-is-preview'] == 1 && isset($_POST['post_ID'])) {
$nonce = isset( $_POST['_wpnonce'] ) ? sanitize_text_field( $_POST['_wpnonce'] ) : '';
$postId = sanitize_text_field($_POST['post_ID']);
if ( empty( $nonce ) || !wp_verify_nonce( $nonce, 'update-post_'.$postId ) ) {
$post = get_post($postId);
* We only allow administrator to do this action
$this->savePost($postId, $post, false);
public function callUnsubcribeUserByEmail()
* We collect GET parameters for Unsubscriber such as 'sgpbUnsubscribe', 'email', 'popup ID'.
* This happens when User wants to unsubcibe on the Subscription Popup through Link in email.
$unsubscribeArgs = $this->collectUnsubscriberArgs();
if (!empty($unsubscribeArgs)) {
$this->unsubscribe($unsubscribeArgs);
// This should call with init hook to register new post type popup
$this->customPostTypeObj = new RegisterPostType();
public function collectUnsubscriberArgs()
if (!isset($_GET['sgpbUnsubscribe'])) {
if (isset($_GET['sgpbUnsubscribe'])) {
$args['token'] = sanitize_text_field($_GET['sgpbUnsubscribe']);
if (isset($_GET['email'])) {
$args['email'] = sanitize_email($_GET['email']);
if (isset($_GET['popup'])) {
$args['popup'] = sanitize_text_field($_GET['popup']);
public function addSubMenu()
// We need to check license keys and statuses before adding new menu "License" item
$this->customPostTypeObj->addSubMenu();