: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
use \SgpbPopupExtensionRegister;
public static function createTables($tables, $blogId = '')
foreach ($tables as $table) {
$pbsgTableName = $wpdb->prefix.$blogId.$table;
$wpdb->query( $wpdb->prepare( "CREATE TABLE IF NOT EXISTS $pbsgTableName") );
private static function getAllNeededTables()
global $SGPB_POPUP_TYPES;
$popupTypes = $SGPB_POPUP_TYPES['typeName'];
if (empty($popupTypes)) {
foreach ($popupTypes as $popupTypeKey => $popupTypeLevel) {
if (SGPB_POPUP_PKG >= $popupTypeLevel) {
$className = ucfirst($popupTypeKey).'Popup';
if (file_exists(SG_POPUP_CLASSES_POPUPS_PATH.$className.'.php')) {
require_once(SG_POPUP_CLASSES_POPUPS_PATH.$className.'.php');
$className = __NAMESPACE__.'\\'.$className;
$popupTables = $className::getTablesSql();
if (empty($popupTables)) {
foreach ($popupTables as $tableSql) {
public static function install()
$tables = self::getAllNeededTables();
$filteredTables = apply_filters('sgpbTablesInstall', $tables);
if (get_option('sgpb-dont-delete-data') === false) {
update_option('sgpb-dont-delete-data', 1);
self::createTables($filteredTables);
self::setupInstallationsDateConfig($filteredTables);
// get_current_blog_id() == 1 When plugin activated inside the child of multisite instance
if (is_multisite() && get_current_blog_id() == 1) {
if ($wp_version > '4.6.0') {
foreach ($sites as $site) {
if ($wp_version > '4.6.0') {
$blogId = $site->blog_id.'_';
$blogId = $site['blog_id'].'_';
// blog Id 1 for multisite main site
self::createTables($filteredTables, $blogId);
if (SGPB_POPUP_PKG != SGPB_POPUP_PKG_FREE) {
$obj = new PopupExtensionActivator();
public static function setupInstallationsDateConfig()
update_option('sgpbUnsubscribeColumnFixed', 1);
$usageDays = get_option('SGPBUsageDays');
update_option('SGPBUsageDays', 0);
$timeDate = new \DateTime('now');
$installTime = strtotime($timeDate->format('Y-m-d H:i:s'));
update_option('SGPBInstallDate', $installTime);
$timeDate->modify('+'.SGPB_REVIEW_POPUP_PERIOD.' day');
$timeNow = strtotime($timeDate->format('Y-m-d H:i:s'));
update_option('SGPBOpenNextTime', $timeNow);
$maxPopupCount = get_option('SGPBMaxOpenCount');
update_option('SGPBMaxOpenCount', SGPB_ASK_REVIEW_POPUP_COUNT);
public static function uninstall()
delete_option('sgpb-user-roles');
// When don't delete data if don't delete data option was unchecked
if (!get_option('sgpb-dont-delete-data')) {
delete_option('sgpb-dont-delete-data');
delete_option('sgpb-new-subscriber');
delete_option('sgpbUnsubscribeColumnFixed');
delete_option('sgpbActivateExtensions');
delete_option('sgpbExtensionsInfo');
delete_option('sgpb-enable-debug-mode');
delete_option('sgpb-disable-analytics-general');
delete_option('sgpb-disable-disable-custom-js');
// Trigger popup data delete action
do_action('sgpbDeletePopupData');
self::deleteCustomTables();
if ($wp_version > '4.6.0') {
foreach ($sites as $site) {
if ($wp_version > '4.6.0') {
$blogId = $site->blog_id.'_';
$blogId = $site['blog_id'].'_';
self::deleteCustomTables($blogId);
* Delete Taxonomy by name
* @param string $taxonomy
public static function deleteCustomTerms($taxonomy)
$terms = $wpdb->get_results( $wpdb->prepare( "SELECT t.name, t.term_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = %s" , esc_sql($taxonomy) ) );
$terms = apply_filters('sgpbDeleteTerms', $terms);
foreach ($terms as $term) {
wp_delete_term($term->term_id, $taxonomy);
* Delete all popup builder post types posts
private static function deletePopups()
'post_type' => SG_POPUP_POST_TYPE,
$popups = apply_filters('sgpbDeletePopups', $popups);
foreach ($popups as $popup) {
wp_delete_post($popup->ID, true);
private static function deleteCustomTables($blogId = '')
$allTableNames = self::getAllTableNames();
if (empty($allTableNames)) {
foreach ($allTableNames as $tableName) {
$deleteTable = $wpdb->prefix.$blogId.$tableName;
$wpdb->query( "DROP TABLE $deleteTable" );
* It's acquire all popup types installed table names
* @return array $popup types table names
private static function getAllTableNames()
global $SGPB_POPUP_TYPES;
$popupTypes = $SGPB_POPUP_TYPES['typeName'];
if (empty($popupTypes)) {
require_once(SG_POPUP_CONFIG_PATH.'configPackage.php');
foreach ($popupTypes as $popupTypeKey => $popupTypeLevel) {
if (SGPB_POPUP_PKG >= $popupTypeLevel) {
$className = ucfirst($popupTypeKey).'Popup';
if (file_exists(SG_POPUP_CLASSES_POPUPS_PATH.$className.'.php')) {
require_once(SG_POPUP_CLASSES_POPUPS_PATH.$className.'.php');
$className = __NAMESPACE__.'\\'.$className;
$popupTables = $className::getTableNames();
if (empty($popupTables)) {
foreach ($popupTables as $tableName) {
public static function registerPlugin()
$pluginName = SGPB_POPUP_FILE_NAME;
$classPath = SG_POPUP_EXTENSION_PATH.'SgpbPopupExtension.php';
$className = 'SgpbPopupExtension';
if (SGPB_POPUP_PKG != SGPB_POPUP_PKG_FREE) {
'storeURL' => SG_POPUP_STORE_URL,
'file' => SGPB_POPUP_FILE_NAME,
'itemId' => SGPB_ITEM_ID,
'itemName' => __('Popup Builder', 'popup-builder'),
'autor' => SG_POPUP_AUTHOR,
'boxLabel' => __('Popup Builder License', 'popup-builder')
$options = apply_filters('sgpbRegisterOptions', $options);
@SgpbPopupExtensionRegister::register($pluginName, $classPath, $className, $options);