: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* @copyright Copyright (c) 2023, Code Atlantic LLC
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
public static function activate_plugin( $network_wide ) {
self::do_multisite( $network_wide, [ __CLASS__, 'activate_site' ] );
public static function deactivate_plugin( $network_wide ) {
self::do_multisite( $network_wide, [ __CLASS__, 'deactivate_site' ] );
public static function uninstall_plugin() {
self::do_multisite( true, [ __CLASS__, 'uninstall_site' ] );
private static function do_multisite( $network_wide, $method, $args = [] ) {
if ( is_multisite() && $network_wide ) {
$activated = get_site_option( 'pum_activated', [] );
$blog_ids = $wpdb->get_col( "SELECT blog_id FROM {$wpdb->blogs}" );
// Try to reduce the chances of a timeout with a large number of sites.
if ( count( $blog_ids ) > 2 ) {
ignore_user_abort( true );
if ( ! pum_is_func_disabled( 'set_time_limit' ) ) {
foreach ( $blog_ids as $blog_id ) {
switch_to_blog( $blog_id );
call_user_func_array( $method, [ $args ] );
update_site_option( 'pum_activated', $activated );
call_user_func_array( $method, [ $args ] );
public static function activate_site() {
// Add default values where needed.
get_option( 'popmake_settings', [] ),
'disable_popup_category_tag' => 1,
// Setup some default options.
add_option( 'popmake_settings', $options );
add_option( 'pum_version', Popup_Maker::$VER );
// Setup the Popup & Theme Custom Post Type.
// PUM_Types::register_post_types();.
// Setup the Popup Taxonomies.
// PUM_Types::register_taxonomies( true );.
// Updates stored values for versioning.
// PUM_Utils_Upgrades::update_plugin_version();.
// We used transients before, but since the check for this option runs every admin page load it means 2 queries after its cleared.
// To prevent that we flipped it, now we delete the following option, and check for it.
// If its missing then we know its a fresh install.
delete_option( '_pum_installed' );
// Prepare to redirect to welcome screen, if not seen before.
if ( false === get_option( 'pum_seen_welcome' ) ) {
set_transient( 'pum_activation_redirect', 1, 60 );
pum_get_default_theme_id();
pum_install_built_in_themes();
pum_install_example_popups();
// Reset JS/CSS assets for regeneration.
public static function get_option( $key, $default = false ) {
if ( function_exists( 'pum_get_option' ) ) {
return pum_get_option( $key, $default );
return PUM_Utils_Options::get( $key, $default );
* Run when Popup Maker is deactivated. Completely deletes all data if complete_uninstall is set to true.
public static function deactivate_site() {
* Process complete uninstall
if ( self::get_option( 'complete_uninstall' ) ) {
// Delete all popups and associated meta.
$wpdb->query( "DELETE a,b,c FROM $wpdb->posts a LEFT JOIN $wpdb->term_relationships b ON (a.ID = b.object_id) LEFT JOIN $wpdb->postmeta c ON (a.ID = c.post_id) WHERE a.post_type IN ('popup', 'popup_theme')" );
$wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key LIKE 'popup_%'" );
/** Delete All the Taxonomies */
foreach ( [ 'popup_category', 'popup_tag' ] as $taxonomy ) {
// Prepare & excecute SQL, Delete Terms.
$wpdb->get_results( $wpdb->prepare( "DELETE t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ('%s')", $taxonomy ) );
$wpdb->delete( $wpdb->term_taxonomy, [ 'taxonomy' => $taxonomy ], [ '%s' ] );
$wpdb->query( "DELETE FROM $wpdb->options WHERE option_name LIKE 'popmake%' OR option_name LIKE '_pum_%' OR option_name LIKE 'pum_%' OR option_name LIKE 'popup_analytics_%'" );
// Delete all Popup Maker related user meta.
$wpdb->query( "DELETE FROM $wpdb->usermeta WHERE meta_key LIKE '_pum_%' OR meta_key lIKE 'pum_%'" );
// Delete subscribers table.
$wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}pum_subscribers" );
PUM_Utils_Logging::instance()->clear_log();
// Reset JS/CSS assets for regeneration.
// # TODO Delete AssetCache files and folder.
do_action( 'pum_uninstall' );
public static function uninstall_site() {
* Returns an activation failure flag if one exists.
public static function get_activation_flag() {
if ( version_compare( PHP_VERSION, Popup_Maker::$MIN_PHP_VER, '<' ) ) {
} elseif ( version_compare( $wp_version, Popup_Maker::$MIN_WP_VER, '<' ) ) {
* Checks if Popup Maker can activate safely.
public static function meets_activation_requirements() {
return self::get_activation_flag() === null;
* Gets activation failure notice message.
public static function get_activation_failure_notice() {
$flag = self::get_activation_flag();
$version = 'PHP' === $flag ? Popup_Maker::$MIN_PHP_VER : Popup_Maker::$MIN_WP_VER;
return sprintf( __( 'The %4$s %1$s %5$s plugin requires %2$s version %3$s or greater.', 'popup-maker' ), Popup_Maker::$NAME, $flag, $version, '<strong>', '</strong>' );
public static function activation_failure_admin_notice() {
<div class="notice notice-error is-dismissible">
<p><?php esc_html_e( self::get_activation_failure_notice() ); ?></p>
* Plugin Activation hook function to check for Minimum PHP and WordPress versions
* Cannot use static:: in case php 5.2 is used.
public static function activation_check() {
if ( self::meets_activation_requirements() ) {
// Deactivate automatically due to insufficient PHP or WP Version.
deactivate_plugins( basename( __FILE__ ) );
$notice = self::get_activation_failure_notice();
__( 'Plugin Activation Error', 'popup-maker' ),