: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* @copyright Copyright (c) 2023, Code Atlantic LLC
if ( ! defined( 'ABSPATH' ) ) {
* Handles processing of data migration & upgrade routines.
class PUM_Utils_Upgrades {
* @var PUM_Upgrade_Registry
* Popup Maker upgraded from version.
public static $upgraded_from;
* Popup Maker initial version.
public static $initial_version;
* Popup Maker db version.
public static $db_version;
* Popup Maker install date.
public static $installed_on;
* Gets everything going with a singleton instance.
public static function instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new self();
* Sets up the Upgrades class instance.
public function __construct() {
// Update stored plugin version info.
self::update_plugin_version();
// Render upgrade admin notices.
add_filter( 'pum_alert_list', [ $this, 'upgrade_alert' ] );
// Add Upgrade tab to Tools page when upgrades available.
add_filter( 'pum_tools_tabs', [ $this, 'tools_page_tabs' ] );
// Render tools page upgrade tab content.
add_action( 'pum_tools_page_tab_upgrades', [ $this, 'tools_page_tab_content' ] );
add_action( 'wp_ajax_pum_process_upgrade_request', [ $this, 'process_upgrade_request' ] );
// Register core upgrades.
add_action( 'pum_register_upgrades', [ $this, 'register_processes' ] );
// Initiate the upgrade registry. Must be done after versions update for proper comparisons.
$this->registry = PUM_Upgrade_Registry::instance();
public static function update_plugin_version() {
self::$version = get_option( 'pum_ver' );
self::$upgraded_from = get_option( 'pum_ver_upgraded_from' );
self::$initial_version = get_option( 'pum_initial_version' );
self::$db_version = get_option( 'pum_db_ver' );
self::$installed_on = get_option( 'pum_installed_on' );
* If no version set check if a deprecated one exists.
if ( empty( self::$version ) ) {
$deprecated_ver = get_site_option( 'popmake_version' );
// set to the deprecated version or last version that didn't have the version option set
self::$version = $deprecated_ver ? $deprecated_ver : Popup_Maker::$VER; // Since we had versioning in v1 if there isn't one stored its a new install.
update_option( 'pum_ver', self::$version );
* Back fill the initial version with the oldest version we can detect.
if ( ! self::$initial_version ) {
$oldest_known = Popup_Maker::$VER;
if ( self::$version && version_compare( self::$version, $oldest_known, '<' ) ) {
$oldest_known = self::$version;
if ( self::$upgraded_from && version_compare( self::$upgraded_from, $oldest_known, '<' ) ) {
$oldest_known = self::$upgraded_from;
$deprecated_ver = get_site_option( 'popmake_version' );
if ( $deprecated_ver && version_compare( $deprecated_ver, $oldest_known, '<' ) ) {
$oldest_known = $deprecated_ver;
$dep_upgraded_from = get_option( 'popmake_version_upgraded_from' );
if ( $dep_upgraded_from && version_compare( $dep_upgraded_from, $oldest_known, '<' ) ) {
$oldest_known = $dep_upgraded_from;
self::$initial_version = $oldest_known;
// Only set this value if it doesn't exist.
update_option( 'pum_initial_version', $oldest_known );
if ( version_compare( self::$version, Popup_Maker::$VER, '<' ) ) {
// Allow processing of small core upgrades
do_action( 'pum_update_core_version', self::$version );
// Save Upgraded From option
update_option( 'pum_ver_upgraded_from', self::$version );
update_option( 'pum_ver', Popup_Maker::$VER );
self::$upgraded_from = self::$version;
self::$version = Popup_Maker::$VER;
// Reset JS/CSS assets for regeneration.
} elseif ( ! self::$upgraded_from || 'false' === self::$upgraded_from ) {
// Here to prevent constant extra queries.
self::$upgraded_from = '0.0.0';
update_option( 'pum_ver_upgraded_from', self::$upgraded_from );
// If no current db version, but prior install detected, set db version correctly.
// Here for backward compatibility.
if ( ! self::$db_version || self::$db_version < Popup_Maker::$DB_VER ) {
self::$db_version = Popup_Maker::$DB_VER;
update_option( 'pum_db_ver', self::$db_version );
* Back fill the initial version with the oldest version we can detect.
if ( ! self::$installed_on ) {
$installed_on = current_time( 'mysql' );
$review_installed_on = get_option( 'pum_reviews_installed_on' );
if ( ! empty( $review_installed_on ) ) {
$installed_on = $review_installed_on;
self::$installed_on = $installed_on;
update_option( 'pum_installed_on', self::$installed_on );
* @param PUM_Upgrade_Registry $registry
public function register_processes( PUM_Upgrade_Registry $registry ) {
version_compare( self::$initial_version, '1.7', '<' ),
'class' => 'PUM_Upgrade_v1_7_Popups',
'file' => Popup_Maker::$DIR . 'includes/batch/upgrade/class-upgrade-v1_7-popups.php',
version_compare( self::$initial_version, '1.7', '<' ),
'class' => 'PUM_Upgrade_v1_7_Settings',
'file' => Popup_Maker::$DIR . 'includes/batch/upgrade/class-upgrade-v1_7-settings.php',
$this->needs_v1_8_theme_upgrade(),
'class' => 'PUM_Upgrade_v1_8_Themes',
'file' => Popup_Maker::$DIR . 'includes/batch/upgrade/class-upgrade-v1_8-themes.php',
public function needs_v1_8_theme_upgrade() {
if ( pum_has_completed_upgrade( 'core-v1_8-themes' ) ) {
$needs_upgrade = get_transient( 'pum_needs_1_8_theme_upgrades' );
if ( false === $needs_upgrade ) {
'post_type' => 'popup_theme',
'key' => 'popup_theme_data_version',
'compare' => 'NOT EXISTS',
'value' => 'deprecated', // Here for WP 3.9 or less.
'key' => 'popup_theme_data_version',
$needs_upgrade = $query->post_count;
if ( $needs_upgrade <= 0 ) {
pum_set_upgrade_complete( 'core-v1_8-themes' );
delete_transient( 'pum_needs_1_8_theme_upgrades' );
set_transient( 'pum_needs_1_8_theme_upgrades', $needs_upgrade );
return (bool) $needs_upgrade;
* Registers a new upgrade routine.
* @param string $upgrade_id Upgrade ID.
* Arguments for registering a new upgrade routine.
* @type array $rules Array of true/false values.
* @type string $class Batch processor class to use.
* @type string $file File containing the upgrade processor class.
* @return bool True if the upgrade routine was added, otherwise false.
public function add_routine( $upgrade_id, $args ) {
return $this->registry->add_upgrade( $upgrade_id, $args );
* Displays upgrade notices.
public function upgrade_notices() {
if ( ! $this->has_uncomplete_upgrades() || ! current_user_can( 'manage_options' ) ) {
// Enqueue admin JS for the batch processor.
wp_enqueue_script( 'pum-admin-batch' );
wp_enqueue_style( 'pum-admin-batch' ); ?>
<div class="notice notice-info is-dismissible">
<?php $this->render_upgrade_notice(); ?>
<?php $this->render_form(); ?>
public function upgrade_alert( $alerts = [] ) {
if ( ! $this->has_uncomplete_upgrades() || ! current_user_can( 'manage_options' ) ) {
// Enqueue admin JS for the batch processor.
wp_enqueue_script( 'pum-admin-batch' );
wp_enqueue_style( 'pum-admin-batch' );
$this->render_upgrade_notice();
'code' => 'upgrades_required',
* Renders the upgrade notification message.
public function render_upgrade_notice() {
$resume_upgrade = $this->maybe_resume_upgrade();
<p class="pum-upgrade-notice">
if ( empty( $resume_upgrade ) ) {
<strong><?php _e( 'The latest version of Popup Maker requires changes to the Popup Maker settings saved on your site.', 'popup-maker' ); ?></strong>
_e( 'Popup Maker needs to complete a the update of your settings that was previously started.', 'popup-maker' );
* Renders the upgrade processing form for reuse.
public function render_form() {
'upgrade_id' => $this->get_current_upgrade_id(),
$resume_upgrade = $this->maybe_resume_upgrade();
if ( $resume_upgrade && is_array( $resume_upgrade ) ) {
$args = wp_parse_args( $resume_upgrade, $args );
<form method="post" class="pum-form pum-batch-form pum-upgrade-form" data-ays="<?php _e( 'This can sometimes take a few minutes, are you ready to begin?', 'popup-maker' ); ?>" data-upgrade_id="<?php echo $args['upgrade_id']; ?>" data-step="<?php echo (int) $args['step']; ?>" data-nonce="<?php echo esc_attr( wp_create_nonce( 'pum_upgrade_ajax_nonce' ) ); ?>">
<div class="pum-field pum-field-button pum-field-submit">
<small><?php _e( 'The button below will process these changes automatically for you.', 'popup-maker' ); ?></small>
<?php submit_button( ! empty( $resume_upgrade ) ? __( 'Finish Upgrades', 'popup-maker' ) : __( 'Process Changes', 'popup-maker' ), 'secondary', 'submit', false ); ?>
<div class="pum-batch-progress">
<progress class="pum-overall-progress" max="100">
<div class="progress-bar"><span></span></div>
<progress class="pum-task-progress" max="100">
<div class="progress-bar"><span></span></div>
<div class="pum-upgrade-messages"></div>
* For use when doing 'stepped' upgrade routines, to see if we need to start somewhere in the middle
* @return false|array When nothing to resume returns false, otherwise starts the upgrade where it left off
public function maybe_resume_upgrade() {
$doing_upgrade = get_option( 'pum_doing_upgrade', [] );
if ( empty( $doing_upgrade ) ) {
return (array) $doing_upgrade;
* Retrieves an upgrade routine from the registry.
* @param string $upgrade_id Upgrade ID.
* @return array|false Upgrade entry from the registry, otherwise false.
public function get_routine( $upgrade_id ) {
return $this->registry->get( $upgrade_id );
* Get all upgrade routines.
public function get_routines() {
return $this->registry->get_upgrades();
* Adds an upgrade action to the completed upgrades array
* @param string $upgrade_id The action to add to the competed upgrades array
* @return bool If the function was successfully added
public function set_upgrade_complete( $upgrade_id = '' ) {
if ( empty( $upgrade_id ) ) {
$completed_upgrades = $this->get_completed_upgrades();
if ( ! in_array( $upgrade_id, $completed_upgrades ) ) {
$completed_upgrades[] = $upgrade_id;
do_action( 'pum_set_upgrade_complete', $upgrade_id );
// Remove any blanks, and only show uniques
$completed_upgrades = array_unique( array_values( $completed_upgrades ) );
return update_option( 'pum_completed_upgrades', $completed_upgrades );
* Get's the array of completed upgrade actions
* @return array The array of completed upgrades
public function get_completed_upgrades() {
$completed_upgrades = get_option( 'pum_completed_upgrades' );
if ( false === $completed_upgrades ) {
$completed_upgrades = [];
update_option( 'pum_completed_upgrades', $completed_upgrades );
return get_option( 'pum_completed_upgrades', [] );
* Check if the upgrade routine has been run for a specific action
* @param string $upgrade_id The upgrade action to check completion for
* @return bool If the action has been added to the completed actions array
public function has_completed_upgrade( $upgrade_id = '' ) {