: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$rolesToBeRestricted = array();
// selected user roles, which have access to the PB
foreach ($allAvailableWpRoles as $allAvailableWpRole) {
if (isset($allAvailableWpRole['name']) && in_array(lcfirst($allAvailableWpRole['name']), $savedUserRoles)) {
$indexToUnset = lcfirst($allAvailableWpRole['name']);
$rolesToBeRestricted[] = lcfirst($allAvailableWpRole['name']);
'read_private_sgpb_popups',
'edit_others_sgpb_popups',
'edit_published_sgpb_popups',
'delete_published_posts',
'delete_others_sgpb_popups',
'delete_private_sgpb_popups',
'delete_private_sgpb_popup',
'delete_published_sgpb_popups',
'manage_popup_categories_terms'
if ($hook == 'activate') {
$rolesToBeRestricted = $savedUserRoles;
foreach ($rolesToBeRestricted as $roleToBeRestricted) {
if ($roleToBeRestricted == 'administrator' || $roleToBeRestricted == 'admin') {
foreach ($caps as $cap) {
// only for the activation hook we need to add our capabilities back
if ($hook == 'activate') {
$wp_roles->add_cap($roleToBeRestricted, $cap);
$wp_roles->remove_cap($roleToBeRestricted, $cap);
public static function removeUnnecessaryCodeFromPopups()
$alreadyClearded = self::getOption('sgpb-unnecessary-scripts-removed-1');
$postsTableName = $wpdb->prefix.'posts';
$popupsId = $wpdb->get_results( $wpdb->prepare("SELECT id FROM $postsTableName WHERE post_type = %s", SG_POPUP_POST_TYPE), ARRAY_A);
foreach ($popupsId as $popupId) {
if (empty($popupId['id'])) {
$customScripts = get_post_meta($id, 'sg_popup_scripts', true);
if (empty($customScripts)) {
if (isset($customScripts['js'])) {
unset($customScripts['js']);
update_post_meta($id, 'sg_popup_scripts', $customScripts);
self::updateOption('sgpb-unnecessary-scripts-removed-1', 1);
public static function sendTestNewsletter($newsletterData = array())
$mailSubject = $newsletterData['newsletterSubject'];
$fromEmail = $newsletterData['fromEmail'];
$emailMessage = $newsletterData['messageBody'];
$blogInfo = wp_specialchars_decode( get_option( 'blogname' ) );
'From: "'.$blogInfo.'" <'.$fromEmail.'>' ,
'Content-type: text/html; charset=UTF-8'
$emails = get_option('admin_email');
if (!empty($newsletterData['testSendingEmails'])) {
$emails = $newsletterData['testSendingEmails'];
$emails = str_replace(' ', '', $emails);
$receiverEmailsArray = array();
$emails = explode(',', $emails);
foreach ($emails as $mail) {
$receiverEmailsArray[] = $mail;
$emails = $receiverEmailsArray;
$newsletterOptions = get_option('SGPB_NEWSLETTER_DATA');
$allAvailableShortcodes = array();
$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;
$emailMessageCustom = preg_replace($allAvailableShortcodes['patternBlogName'], $newsletterOptions['blogname'], $emailMessage);
$emailMessageCustom = preg_replace($allAvailableShortcodes['patternUserName'], $newsletterOptions['username'], $emailMessageCustom);
$emailMessageCustom = str_replace($allAvailableShortcodes['patternUnsubscribe'], '', $emailMessageCustom);
$mailStatus = wp_mail($emails, $mailSubject, $emailMessageCustom, $headers);
wp_die(esc_html($newsletterData['testSendingStatus']));
public static function getImageAltTextByUrl($imageUrl = '')
$imageId = attachment_url_to_postid($imageUrl);
$altText = get_post_meta($imageId, '_wp_attachment_image_alt', true);
public static function hasBlocks($content)
if (function_exists('has_blocks')) {
return has_blocks($content);
return false !== strpos( (string) $content, '<!-- wp:' );
* Retrieve duplicate post link for post.
* @param int $id Optional. Post ID.
* @param string $context Optional, default to display. How to write the '&', defaults to '&'.
public static function popupGetClonePostLink($id = 0, $context = 'display')
if (!$post = get_post($id)) {
$actionName = "popupSaveAsNew";
if ('display' == $context) {
$action = '?action='.$actionName.'&post='.$post->ID;
$action = '?action='.$actionName.'&post='.$post->ID;
$postTypeObject = get_post_type_object($post->post_type);
return wp_nonce_url(apply_filters('popupGetClonePostLink', admin_url("admin.php".$action), $post->ID, $context), 'duplicate-post_' . $post->ID);
private static function checkIfLicenseIsActive($license, $itemId, $key) {
$transient = 'sgpb-license-key-'.$key.'-requested';
if ( false !== ( $value = get_transient( $transient ) ) ) {
'woo_sl_action' => 'status-check',
'licence_key' => $license,
'product_unique_id' => $itemId,
$requestUri = SGPB_REQUEST_URL.'?'.http_build_query($params);
$response = wp_remote_get($requestUri);
if (!is_wp_error($response) || 200 == wp_remote_retrieve_response_code($response)) {
$licenseData = json_decode(wp_remote_retrieve_body($response));
$status = (isset($licenseData[0]->licence_status) && $licenseData[0]->licence_status === 'active') ? 'valid' : $licenseData[0]->licence_status;
update_option('sgpb-license-status-'.$key, $status);
set_transient($transient, $licenseData[0]->status_code, WEEK_IN_SECONDS);
public static function updatesInit()
if (!class_exists('sgpb\WOOSL_CodeAutoUpdate')) {
// load our custom updater if it doesn't already exist
require_once(SG_POPUP_LIBS_PATH .'WOOSL_CodeAutoUpdate.php');
$licenses = (new License())->getLicenses();
foreach ($licenses as $license) {
$key = isset($license['key']) ?$license['key'] : '';
$itemId = isset($license['itemId']) ? $license['itemId'] : '';
$filePath = isset($license['file']) ? $license['file'] : '';
$pluginMainFilePath = strpos($filePath, SG_POPUP_PLUGIN_PATH) !== 0 ? SG_POPUP_PLUGIN_PATH.$filePath : $filePath;
$licenseKey = trim(get_option('sgpb-license-key-'.$key));
$status = get_option('sgpb-license-status-'.$key);
if ($status == false || $status != 'valid') {
self::checkIfLicenseIsActive($licenseKey, $itemId, $key);
if (defined('SGPB_SOCIAL_POPUP_VERSION')) {
$version = defined('SGPB_SOCIAL_POPUP_VERSION') ? constant('SGPB_SOCIAL_POPUP_VERSION') : '';
$version = defined('SG_VERSION_'.$key) ? constant('SG_VERSION_'.$key) : '';
case 'POPUP_AGE_VERIFICATION':
if (defined('SGPB_AGE_VERIFICATION_POPUP_VERSION')) {
$version = defined('SGPB_AGE_VERIFICATION_POPUP_VERSION') ? constant('SGPB_AGE_VERIFICATION_POPUP_VERSION') : '';
$version = defined('SG_VERSION_'.$key) ? constant('SG_VERSION_'.$key) : '';
case 'POPUP_GAMIFICATION':
if (defined('POPUP_GAMIFICATION')) {
$version = defined('POPUP_GAMIFICATION') ? constant('POPUP_GAMIFICATION') : '';
$version = defined('SG_VERSION_'.$key) ? constant('SG_VERSION_'.$key) : '';
$version = defined('SG_VERSION_'.$key) ? constant('SG_VERSION_'.$key) : '';
// If the version of the extension is not found, update will not possibly be shown
$sgpbUpdater = new WOOSL_CodeAutoUpdate(
public static function allowed_html_tags($allowScript = true)
$allowedPostTags = array();
$allowedPostTags = wp_kses_allowed_html('post');
'aria-disabled' => array(),
'aria-atomic' => array(),
'aria-required' => array(),
'aria-invalid' => array(),
'aria-hidden' => array(),
'aria-valuenow' => array(),
'aria-valuemin' => array(),
'aria-haspopup' => array(),
'aria-expanded' => array(),
'aria-valuemax' => array(),
'aria-labelledby' => array(),
'aria-checked' => array(),
'aria-describedby' => array(),
'aria-valuetext' => array(),
'placeholder' => array(),
'allowfullscreen' => array(),
'autocomplete' => array(),
$allowedPostTags['script'] = $allowed_atts;
$allowed_atts['onclick'] = array();
$allowedPostTags['select'] = $allowed_atts;
$allowedPostTags['optgroup'] = $allowed_atts;
$allowedPostTags['option'] = $allowed_atts;
$allowedPostTags['form'] = $allowed_atts;
$allowedPostTags['fieldset'] = $allowed_atts;
$allowedPostTags['legend'] = $allowed_atts;
$allowedPostTags['label'] = $allowed_atts;
$allowedPostTags['input'] = $allowed_atts;
$allowedPostTags['video'] = $allowed_atts;
$allowedPostTags['source'] = $allowed_atts;
$allowedPostTags['textarea'] = $allowed_atts;
$allowedPostTags['iframe'] = $allowed_atts;
$allowedPostTags['style'] = $allowed_atts;
$allowedPostTags['strong'] = $allowed_atts;
$allowedPostTags['small'] = $allowed_atts;
$allowedPostTags['table'] = $allowed_atts;
$allowedPostTags['span'] = $allowed_atts;
$allowedPostTags['abbr'] = $allowed_atts;
$allowedPostTags['code'] = $allowed_atts;
$allowedPostTags['pre'] = $allowed_atts;
$allowedPostTags['div'] = $allowed_atts;
$allowedPostTags['img'] = $allowed_atts;
$allowedPostTags['h1'] = $allowed_atts;
$allowedPostTags['h2'] = $allowed_atts;
$allowedPostTags['h3'] = $allowed_atts;
$allowedPostTags['h4'] = $allowed_atts;
$allowedPostTags['h5'] = $allowed_atts;
$allowedPostTags['h6'] = $allowed_atts;
$allowedPostTags['ol'] = $allowed_atts;
$allowedPostTags['ul'] = $allowed_atts;
$allowedPostTags['li'] = $allowed_atts;
$allowedPostTags['em'] = $allowed_atts;
$allowedPostTags['hr'] = $allowed_atts;
$allowedPostTags['br'] = $allowed_atts;
$allowedPostTags['tr'] = $allowed_atts;
$allowedPostTags['td'] = $allowed_atts;
$allowedPostTags['p'] = $allowed_atts;
$allowedPostTags['a'] = $allowed_atts;
$allowedPostTags['b'] = $allowed_atts;
$allowedPostTags['i'] = $allowed_atts;
add_filter('safe_style_css', function($styles){
public static function allowed_wrap_html_tags($allowScript = true)
$allowedPostTags = array('span','div','h1','h2' ,'h3' ,'h4' ,'h5' ,'h6','ol' ,'ul' ,'li' ,'em' , 'p', 'a','b' ,'i' , 'button');
public static function sgpbScanCustomJsStr( $quetStrCustomJs)
$scamListMethods = array('register', 'createuser', 'forgotPassword', 'user_login', 'password','eval', 'atob' );
foreach( $scamListMethods as $scan_key)
$pos_scan = strpos($quetStrCustomJs, $scan_key);
if ($pos_scan !== false) {
public static function sgpbScanCustomJsProblem()
$sgpbdetect_flag = false;
// Get all custom JS code on Popups
$popupBuilderPosts = new WP_Query(
'post_type' => SG_POPUP_POST_TYPE,
// We check all the popups one by one to realize whether they might be loaded or not.
while ($popupBuilderPosts->have_posts()) {
$popupBuilderPosts->next_post();
$popupPost = $popupBuilderPosts->post;
$popup = SGPopup::find($popupPost);
if (empty($popup) || !is_object($popup)) {
$alreadySavedCustomData = get_post_meta($popupPost->ID, 'sg_popup_scripts', true);
//Scan each customJS to find insecurity custom JS code
$popup_options = $popup->getOptions();
if ( isset( $popup_options['sgpb-ShouldOpen'] ) && !empty( $popup_options['sgpb-ShouldOpen'] ) ){
if( self::sgpbScanCustomJsStr( $popup_options['sgpb-ShouldOpen'] ) == true )
return array( 'status' => $sgpbdetect_flag , 'marked_code' => admin_url( 'post.php?post='.$popupPost->ID.'&action=edit#customCssJs' ));
if ( isset( $popup_options['sgpb-ShouldClose'] ) && !empty( $popup_options['sgpb-ShouldClose'] ) )
if( self::sgpbScanCustomJsStr( $popup_options['sgpb-ShouldClose'] ) == true )
return array( 'status' => $sgpbdetect_flag , 'marked_code' => admin_url( 'post.php?post='.$popupPost->ID.'&action=edit#customCssJs' ));
if ( isset( $alreadySavedCustomData['js'] ) && !empty( $alreadySavedCustomData['js']['sgpb-ShouldOpen']) )
if( self::sgpbScanCustomJsStr( $alreadySavedCustomData['js']['sgpb-ShouldOpen'] ) == true )
return array( 'status' => $sgpbdetect_flag , 'marked_code' => admin_url( 'post.php?post='.$popupPost->ID.'&action=edit#customCssJs' ));
if ( isset( $alreadySavedCustomData['js'] ) && !empty( $alreadySavedCustomData['js']['sgpb-WillOpen']) )
if( self::sgpbScanCustomJsStr( $alreadySavedCustomData['js']['sgpb-WillOpen'] ) == true )
return array( 'status' => $sgpbdetect_flag , 'marked_code' => admin_url( 'post.php?post='.$popupPost->ID.'&action=edit#customCssJs' ));
if ( isset( $alreadySavedCustomData['js'] ) && !empty( $alreadySavedCustomData['js']['sgpb-DidOpen']) )
if( self::sgpbScanCustomJsStr( $alreadySavedCustomData['js']['sgpb-DidOpen'] ) == true )
return array( 'status' => $sgpbdetect_flag , 'marked_code' => admin_url( 'post.php?post='.$popupPost->ID.'&action=edit#customCssJs' ));
if ( isset( $alreadySavedCustomData['js'] ) && !empty( $alreadySavedCustomData['js']['sgpb-ShouldClose']) )
if( self::sgpbScanCustomJsStr( $alreadySavedCustomData['js']['sgpb-ShouldClose'] ) == true )
return array( 'status' => $sgpbdetect_flag , 'marked_code' => admin_url( 'post.php?post='.$popupPost->ID.'&action=edit#customCssJs' ));
if ( isset( $alreadySavedCustomData['js'] ) && !empty( $alreadySavedCustomData['js']['sgpb-WillClose']) )
if( self::sgpbScanCustomJsStr( $alreadySavedCustomData['js']['sgpb-WillClose'] ) == true )
return array( 'status' => $sgpbdetect_flag , 'marked_code' => admin_url( 'post.php?post='.$popupPost->ID.'&action=edit#customCssJs' ));
if ( isset( $alreadySavedCustomData['js'] ) && !empty( $alreadySavedCustomData['js']['sgpb-DidClose']) )
if( self::sgpbScanCustomJsStr( $alreadySavedCustomData['js']['sgpb-DidClose'] ) == true )
return array( 'status' => $sgpbdetect_flag , 'marked_code' => admin_url( 'post.php?post='.$popupPost->ID.'&action=edit#customCssJs' ));