: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
use sgpbsubscriptionplus\SubscriptionPlusAdminHelper;
* Get extension options data which are included inside the free version
* @return assoc array $extensionOptions
public static function getExtensionAvaliabilityOptions()
$extensionOptions = array();
// advanced closing option
$extensionOptions[SGPB_POPUP_ADVANCED_CLOSING_PLUGIN_KEY] = array(
'sgpb-close-after-page-scroll',
'sgpb-enable-popup-overlay',
'sgpb-disable-popup-closing'
$extensionOptions[SGPB_POPUP_SCHEDULING_EXTENSION_KEY] = array(
'otherConditionsMetaBoxView'
// geo targeting extension
$extensionOptions[SGPB_POPUP_GEO_TARGETING_EXTENSION_KEY] = array(
// advanced targeting extension
$extensionOptions[SGPB_POPUP_ADVANCED_TARGETING_EXTENSION_KEY] = array(
return $extensionOptions;
public static function getPopupTypesPageURL()
return admin_url('edit.php?post_type='.SG_POPUP_POST_TYPE.'&page='.SG_POPUP_POST_TYPE);
public static function getSettingsURL($args = array())
$url = admin_url('/edit.php?post_type='.SG_POPUP_POST_TYPE.'&page='.SG_POPUP_SETTINGS_PAGE);
return self::addArgsToURl($url, $args);
public static function getPopupExportURL()
$exportURL = admin_url('export.php');
$url = add_query_arg(array(
'content' => SG_POPUP_POST_TYPE,
public static function addArgsToURl($url, $args = array())
$resultURl = add_query_arg($args, $url);
public static function buildCreatePopupUrl($popupType)
$isAvailable = $popupType->isAvailable();
$name = $popupType->getName();
$popupUrl = SG_POPUP_ADMIN_URL.'post-new.php?post_type='.SG_POPUP_POST_TYPE.'&sgpb_type='.$name;
$popupUrl = SG_POPUP_PRO_URL;
public static function getPopupThumbClass($popupType)
$isAvailable = $popupType->isAvailable();
$name = $popupType->getName();
$popupTypeClassName = $name.'-popup';
$popupTypeClassName .= '-pro';
return $popupTypeClassName;
public static function createSelectBox($data, $selectedValue, $attrs)
$selectBoxCloseTag = '</select>';
if (!empty($attrs) && isset($attrs)) {
foreach ($attrs as $attrName => $attrValue) {
$attrString .= ''.$attrName.'="'.$attrValue.'" ';
$selectBox = '<select '.$attrString.'>';
if (empty($data) || !is_array($data)) {
$selectBox .= $selectBoxCloseTag;
foreach ($data as $value => $label) {
if (is_array($selectedValue)) {
$isSelected = in_array($value, $selectedValue);
else if ($selectedValue == $value) {
else if (is_array($value) && in_array($selectedValue, $value)) {
$selectBox .= '<optgroup label="'.$value.'">';
foreach ($label as $key => $optionLabel) {
if (is_array($selectedValue)) {
$isSelected = in_array($key, $selectedValue);
else if ($selectedValue == $key) {
else if (is_array($key) && in_array($selectedValue, $key)) {
$selectBox .= '<option value="'.$key.'" '.$selected.'>'.$optionLabel.'</option>';
$selectBox .= '</optgroup>';
$selectBox .= '<option value="'.$value.'" '.$selected.'>'.$label.'</option>';
$selectBox .= $selectBoxCloseTag;
public static function createInput($data, $selectedValue, $attrs)
if (isset($selectedValue) && $selectedValue !== '') {
$savedData = $selectedValue;
if (!empty($attrs) && isset($attrs)) {
foreach ($attrs as $attrName => $attrValue) {
if ($attrName == 'class') {
$attrString .= ''.$attrName.'="'.$attrValue.'" ';
$input = "<input $attrString value=\"".esc_attr($savedData)."\">";
public static function createCheckBox($data, $selectedValue, $attrs)
if (!empty($selectedValue)) {
if (!empty($attrs) && isset($attrs)) {
foreach ($attrs as $attrName => $attrValue) {
$attrString .= ''.$attrName.'="'.$attrValue.'" ';
$input = "<input $attrString $checked>";
public static function createRadioButtons($elements, $name, $selectedInput, $lineMode = false, $extraHtmlAfterInput = '')
$allowed_html = self::allowed_html_tags();
foreach ($elements as $key => $element) {
if (isset($element['value'])) {
$value = $element['value'];
if (isset($element['label_class'])) {
$labelClasses = 'class="'.$element['label_class'].'"';
$stringLabel = '<span class="sgpb-margin-bottom-10">'.esc_attr($value).'</span>';
if (is_array($element) && $element['value'] == $selectedInput) {
else if (!is_array($element) && $element == $selectedInput) {
if (isset($element['data-attributes'])) {
foreach ($element['data-attributes'] as $attrKey => $dataValue) {
$attrStr .= $attrKey.'="'.esc_attr($dataValue).'" ';
if (!empty($extraHtmlAfterInput)) {
if ($extraHtmlAfterInput == 'img') {
$extraHtmlAfterInput = '<img src="">';
else if ($extraHtmlAfterInput == 'bg_img') {
$extraHtmlAfterInput = '<span class="sgpb-popup-theme-img sgpb-margin-x-7"></span>';
if (!empty($extraHtmlAfterInput)) {
$str .= '<label '.$labelClasses.'><input type="radio" name="'.esc_attr($name).'" value="'.esc_attr($value).'" '.$checked.' '.$attrStr.'>'.$extraHtmlAfterInput.$stringLabel.'</label>';
$str .= '<input type="radio" name="'.esc_attr($name).'" value="'.esc_attr($value).'" '.$checked.' '.$attrStr.'>';
$str .= '<div class="row form-group">';
$str .= '<label class="col-md-5 control-label">'.sprintf( '%s', esc_html( $element['title'] )).'</label>';
$str .= '<div class="col-sm-7"><input type="radio" name="'.esc_attr($name).'" value="'.esc_attr($value).'" '.$checked.' autocomplete="off">'.$extraHtmlAfterInput.'</div>';
echo wp_kses($str, $allowed_html);
public static function getDateObjFromDate($dueDate, $timezone = 'America/Los_Angeles', $format = 'Y-m-d H:i:s')
$dateObj = new DateTime($dueDate, new DateTimeZone($timezone));
$dateObj->format($format);
* @return string $serializedData
public static function serializeData($data = array())
$serializedData = serialize($data);
* Get correct size to use it safely inside CSS rules
* @param string $dimension
public static function getCSSSafeSize($dimension)
$size = (int)$dimension.'px';
// If user write dimension in px or % we give that dimension to target otherwise the default value will be px
if (strpos($dimension, '%') || strpos($dimension, 'px')) {
public static function deleteSubscriptionPopupSubscribers($popupId)
$subscribersTableName = $wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME;
$wpdb->query( $wpdb->prepare("DELETE FROM $subscribersTableName WHERE subscriptionType = %s", $popupId) );
public static function subscribersRelatedQuery($query = '', $additionalColumn = '')
$subscribersTablename = $wpdb->prefix.SGPB_SUBSCRIBERS_TABLE_NAME;
$postsTablename = $wpdb->prefix.SGPB_POSTS_TABLE_NAME;
$query = 'SELECT firstName, lastName, email, cDate, '.$additionalColumn.' '.$postsTablename.'.post_title AS subscriptionTitle FROM '.$subscribersTablename.' ';
$array_mapping_search = [];
$searchQuery = ' unsubscribed <> %d';
$array_mapping_search[] = 1;
$query .= ' LEFT JOIN '.$postsTablename.' ON '.$postsTablename.'.ID='.$subscribersTablename.'.subscriptionType';
if (isset($_GET['sgpb-subscription-popup-id']) && !empty($_GET['sgpb-subscription-popup-id'])) {
$filterCriteria = sanitize_text_field($_GET['sgpb-subscription-popup-id']);
if ($filterCriteria != 'all') {
$searchQuery .= " AND (subscriptionType = %s)";
$array_mapping_search[] = esc_sql((int)$filterCriteria);
if ($filterCriteria != '' && $filterCriteria != 'all' && isset($_GET['s']) && !empty($_GET['s'])) {
if (isset($_GET['s']) && !empty($_GET['s'])) {
$searchCriteria = sanitize_text_field($_GET['s']);
$lastPartOfTheQuery = substr($searchQuery, -5);
if (strpos($lastPartOfTheQuery, 'AND') <= 0) {
$searchCriteria = "%" . esc_sql($wpdb->esc_like( $searchCriteria )) . "%";
$searchQuery .= "(firstName LIKE %s or lastName LIKE %s or email LIKE %s or $postsTablename.post_title LIKE %s)";
$array_mapping_search[] = $searchCriteria;
$array_mapping_search[] = $searchCriteria;
$array_mapping_search[] = $searchCriteria;
$array_mapping_search[] = $searchCriteria;
if (isset($_GET['sgpb-subscribers-date']) && !empty($_GET['sgpb-subscribers-date'])) {
$filterCriteriaDate = sanitize_text_field($_GET['sgpb-subscribers-date']);
if ($filterCriteriaDate != 'all') {
if ($searchQuery != '') {
$searchQuery .= " cDate LIKE %s ";
$array_mapping_search[] = esc_sql( $wpdb->esc_like($filterCriteriaDate)).'%';
if ($searchQuery != '') {
$query .= " WHERE $searchQuery";
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- No applicable variables for this query.
return $wpdb->prepare( $query, $array_mapping_search );
public static function themeRelatedSettings($popupId, $buttonPosition, $theme)
if ($theme == 'sgpb-theme-1' || $theme == 'sgpb-theme-4' || $theme == 'sgpb-theme-5') {
if (!isset($buttonPosition)) {
$buttonPosition = 'bottomRight';
else if ($theme == 'sgpb-theme-2' || $theme == 'sgpb-theme-3' || $theme == 'sgpb-theme-6') {
if (!isset($buttonPosition)) {
$buttonPosition = 'topRight';
if ($theme == 'sgpb-theme-1' || $theme == 'sgpb-theme-4' || $theme == 'sgpb-theme-5') {
$buttonPosition = 'bottomRight';
else if ($theme == 'sgpb-theme-2' || $theme == 'sgpb-theme-3' || $theme == 'sgpb-theme-6') {
$buttonPosition = 'topRight';
/* by default set position for the first theme */
$buttonPosition = 'bottomRight';
* @return string $attrStr
public static function createAttrs($attrs)
foreach ($attrs as $attrKey => $attrValue) {
$attrStr .= $attrKey.'="'.$attrValue.'" ';
public static function getFormattedDate($date)
$date = strtotime($date);
$month = gmdate('F', $date);
$year = gmdate('Y', $date);
public static function defaultButtonImage($theme, $closeImage = '')
$currentPostType = self::getCurrentPopupType();
if (defined('SGPB_POPUP_TYPE_RECENT_SALES') && $currentPostType == SGPB_POPUP_TYPE_RECENT_SALES) {
// if no image, set default by theme
if ($theme == 'sgpb-theme-1' || !$theme) {
$closeImage = SG_POPUP_IMG_URL.'theme_1/close.png';
else if ($theme == 'sgpb-theme-2') {
$closeImage = SG_POPUP_IMG_URL.'theme_2/close.png';
else if ($theme == 'sgpb-theme-3') {
$closeImage = SG_POPUP_IMG_URL.'theme_3/close.png';
else if ($theme == 'sgpb-theme-5') {
$closeImage = SG_POPUP_IMG_URL.'theme_5/close.png';
else if ($theme == 'sgpb-theme-6') {
$closeImage = SG_POPUP_IMG_URL.'theme_6/close.png';
$closeImage = self::getImageDataFromUrl($closeImage);
public static function getPopupPostAllowedUserRoles()
$userSavedRoles = get_option('sgpb-user-roles');
if (empty($userSavedRoles) || !is_array($userSavedRoles)) {
$userSavedRoles = array('administrator');
array_push($userSavedRoles, 'administrator');
public static function showMenuForCurrentUser()
return self::userCanAccessTo();