first commit

This commit is contained in:
2026-03-05 13:07:40 +01:00
commit 64ba0721ee
25709 changed files with 4691006 additions and 0 deletions

View File

@@ -0,0 +1,97 @@
<?php
/**
* Upgrade Routine 2
*
* @package PUM
* @subpackage Admin/Upgrades
* @copyright Copyright (c) 2023, Code Atlantic LLC
* @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
* @since 1.4
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'PUM_Admin_Upgrade_Routine' ) ) {
require_once POPMAKE_DIR . 'includes/admin/upgrades/class-pum-admin-upgrade-routine.php';
}
/**
* Class PUM_Admin_Upgrade_Routine_2
*/
final class PUM_Admin_Upgrade_Routine_2 extends PUM_Admin_Upgrade_Routine {
public static function description() {
return __( 'Update your popups settings.', 'popup-maker' );
}
public static function run() {
if ( ! current_user_can( PUM_Admin_Upgrades::instance()->required_cap ) ) {
wp_die( __( 'You do not have permission to do upgrades', 'popup-maker' ), __( 'Error', 'popup-maker' ), [ 'response' => 403 ] );
}
ignore_user_abort( true );
if ( ! pum_is_func_disabled( 'set_time_limit' ) ) {
@set_time_limit( 0 );
}
self::process_popups();
self::cleanup_old_data();
}
public static function process_popups() {
$popups = get_posts(
[
'post_type' => 'popup',
'post_status' => [ 'any', 'trash' ],
'posts_per_page' => - 1,
]
);
$popup_groups = [
'display' => popmake_popup_display_defaults(),
'close' => popmake_popup_close_defaults(),
'click_open' => popmake_popup_click_open_defaults(),
'auto_open' => popmake_popup_auto_open_defaults(),
'admin_debug' => popmake_popup_admin_debug_defaults(),
];
foreach ( $popups as $popup ) {
foreach ( $popup_groups as $group => $defaults ) {
$values = array_merge( $defaults, popmake_get_popup_meta_group( $group, $popup->ID ) );
update_post_meta( $popup->ID, "popup_{$group}", $values );
}
}
}
public static function cleanup_old_data() {
global $wpdb;
$popup_groups = [
'display',
'close',
'click_open',
'auto_open',
'admin_debug',
];
$popup_fields = [];
foreach ( $popup_groups as $group ) {
foreach ( apply_filters( 'popmake_popup_meta_field_group_' . $group, [] ) as $field ) {
$popup_fields[] = 'popup_' . $group . '_' . $field;
}
}
$popup_fields = implode( "','", $popup_fields );
$wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key IN('$popup_fields');" );
}
}

View File

@@ -0,0 +1,196 @@
<?php
/**
* Upgrade Routine 3
*
* @package PUM
* @subpackage Admin/Upgrades
* @copyright Copyright (c) 2023, Code Atlantic LLC
* @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
* @since 1.4
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'PUM_Admin_Upgrade_Routine' ) ) {
require_once POPMAKE_DIR . 'includes/admin/upgrades/class-pum-admin-upgrade-routine.php';
}
/**
* Class PUM_Admin_Upgrade_Routine_3
*/
final class PUM_Admin_Upgrade_Routine_3 extends PUM_Admin_Upgrade_Routine {
/**
* Returns a description.
*
* @return mixed|void
*/
public static function description() {
return __( 'Upgrade popup triggers &amp; cookies.', 'popup-maker' );
}
/**
* Upgrade popup triggers & cookies.
*
* - Convert Auto Open
* - Convert Click Open
*/
public static function run() {
if ( ! current_user_can( PUM_Admin_Upgrades::instance()->required_cap ) ) {
wp_die( __( 'You do not have permission to do upgrades', 'popup-maker' ), __( 'Error', 'popup-maker' ), [ 'response' => 403 ] );
}
ignore_user_abort( true );
if ( ! pum_is_func_disabled( 'set_time_limit' ) ) {
@set_time_limit( 0 );
}
$upgrades = PUM_Admin_Upgrades::instance();
$completed = $upgrades->get_arg( 'completed' );
$total = $upgrades->get_arg( 'total' );
// Set the correct total.
if ( $total <= 1 ) {
$popups = wp_count_posts( 'popup' );
$total = 0;
foreach ( $popups as $status ) {
$total += $status;
}
$upgrades->set_arg( 'total', $total );
}
$popups = pum_get_popups(
[
'number' => $upgrades->get_arg( 'number' ),
'page' => $upgrades->get_arg( 'step' ),
'status' => [ 'any', 'trash', 'auto-draft' ],
'order' => 'ASC',
]
);
if ( $popups ) {
foreach ( $popups as $popup ) {
$_cookies = $cookies = [];
$_triggers = $triggers = [];
// Convert Click Open Triggers.
$click_open = popmake_get_popup_meta_group( 'click_open', $popup->ID );
$_triggers[] = [
'type' => 'click_open',
'settings' => [
'extra_selectors' => ! empty( $click_open['extra_selectors'] ) ? $click_open['extra_selectors'] : '',
'cookie' => [
'name' => null,
],
],
];
// If auto open enabled create a new trigger.
$auto_open = popmake_get_popup_meta_group( 'auto_open', $popup->ID );
if ( isset( $auto_open['enabled'] ) && $auto_open['enabled'] ) {
// Set the new cookie name.
$cookie_name = 'popmake-auto-open-' . $popup->ID;
// Append the cookie key if set.
if ( ! empty( $auto_open['cookie_key'] ) ) {
$cookie_name .= '-' . $auto_open['cookie_key'];
}
// Store cookie_trigger for reuse.
$cookie_trigger = $auto_open['cookie_trigger'];
// Create empty trigger cookie in case of disabled trigger.
$trigger_cookie = null;
// If cookie trigger not disabled create a new cookie and add it to the auto open trigger.
if ( 'disabled' !== $cookie_trigger ) {
// Add the new cookie to the auto open trigger.
$trigger_cookie = [ $cookie_name ];
// Set the event based on the original option.
switch ( $cookie_trigger ) {
case 'close':
$event = 'on_popup_close';
break;
case 'open':
$event = 'on_popup_close';
break;
default:
$event = $cookie_trigger;
break;
}
// Add the new cookie to the cookies array.
$_cookies[] = [
'event' => $event,
'settings' => [
'name' => $cookie_name,
'key' => '',
'time' => $auto_open['cookie_time'],
'path' => isset( $auto_open['cookie_path'] ) ? 1 : 0,
'session' => isset( $auto_open['session_cookie'] ) ? 1 : 0,
],
];
}
// Add the new auto open trigger to the triggers array.
$_triggers[] = [
'type' => 'auto_open',
'settings' => [
'delay' => ! empty( $auto_open['delay'] ) ? absint( $auto_open['delay'] ) : 500,
'cookie' => [
'name' => $trigger_cookie,
],
],
];
}
foreach ( $_cookies as $cookie ) {
$cookie['settings'] = PUM_Cookies::instance()->validate_cookie( $cookie['event'], $cookie['settings'] );
$cookies[] = $cookie;
}
foreach ( $_triggers as $trigger ) {
$trigger['settings'] = PUM_Triggers::instance()->validate_trigger( $trigger['type'], $trigger['settings'] );
$triggers[] = $trigger;
}
update_post_meta( $popup->ID, 'popup_triggers', $triggers );
update_post_meta( $popup->ID, 'popup_cookies', $cookies );
$completed ++;
}
if ( $completed < $total ) {
$upgrades->set_arg( 'completed', $completed );
self::next_step();
}
}
self::done();
}
/**
* Returns the auto open meta of a popup.
*
* @since 1.1.0
* @deprecated 1.4
*
* @param int $popup_id ID number of the popup to retrieve a auto open meta for
*
* @return mixed array|string of the popup auto open meta
*/
public static function get_auto_open( $popup_id = null, $key = null, $default = null ) {
return popmake_get_popup_meta( 'auto_open', $popup_id, $key, $default );
}
}

View File

@@ -0,0 +1,351 @@
<?php
/**
* Upgrade Routine 4
*
* @package PUM
* @subpackage Admin/Upgrades
* @copyright Copyright (c) 2023, Code Atlantic LLC
* @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
* @since 1.4
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'PUM_Admin_Upgrade_Routine' ) ) {
require_once POPMAKE_DIR . 'includes/admin/upgrades/class-pum-admin-upgrade-routine.php';
}
/**
* Class PUM_Admin_Upgrade_Routine_4
*/
final class PUM_Admin_Upgrade_Routine_4 extends PUM_Admin_Upgrade_Routine {
/**
* Returns a description.
*
* @return mixed|void
*/
public static function description() {
return __( 'Upgrade popup targeting conditions.', 'popup-maker' );
}
/**
* Upgrade popup targeting conditions.
*
* - Convert Conditions
* - Default popups with no conditions to draft
*/
public static function run() {
if ( ! current_user_can( PUM_Admin_Upgrades::instance()->required_cap ) ) {
wp_die( __( 'You do not have permission to do upgrades', 'popup-maker' ), __( 'Error', 'popup-maker' ), [ 'response' => 403 ] );
}
ignore_user_abort( true );
if ( ! pum_is_func_disabled( 'set_time_limit' ) ) {
@set_time_limit( 0 );
}
$upgrades = PUM_Admin_Upgrades::instance();
$completed = $upgrades->get_arg( 'completed' );
$total = $upgrades->get_arg( 'total' );
// Set the correct total.
if ( $total <= 1 ) {
$popups = wp_count_posts( 'popup' );
$total = 0;
foreach ( $popups as $status ) {
$total += $status;
}
$upgrades->set_arg( 'total', $total );
}
$popups = pum_get_popups(
[
'number' => $upgrades->get_arg( 'number' ),
'page' => $upgrades->get_arg( 'step' ),
'status' => [ 'any', 'trash', 'auto-draft' ],
'order' => 'ASC',
]
);
if ( $popups ) {
foreach ( $popups as $popup ) {
$_conditions = $conditions = [];
// Convert Conditions
$targeting_conditions = popmake_get_popup_meta_group( 'targeting_condition', $popup->ID );
if ( empty( $targeting_conditions ) ) {
if ( 'publish' === $popup->post_status ) {
// Default popups with no conditions to draft
self::change_post_status( $popup->ID, 'draft' );
}
update_post_meta( $popup->ID, 'popup_conditions', $conditions );
$completed ++;
continue;
}
$sitewide = false;
if ( array_key_exists( 'on_entire_site', $targeting_conditions ) ) {
$sitewide = true;
$targeting_conditions = self::filter_excludes( $targeting_conditions );
} else {
$targeting_conditions = self::filter_includes( $targeting_conditions );
}
$targeting_conditions = self::parse_conditions( $targeting_conditions );
$_group = [];
foreach ( $targeting_conditions as $condition ) {
// If sitewide is enabled then all conditions use the not_operand.
$condition['not_operand'] = $sitewide ? 1 : 0;
// Add a new AND condition group.
if ( $sitewide ) {
$_conditions[] = [ $condition ];
} // Add a new OR condition to the group.
else {
$_group[] = $condition;
}
}
if ( ! $sitewide && ! empty( $_group ) ) {
$_conditions[] = $_group;
}
foreach ( $_conditions as $group_key => $group ) {
foreach ( $group as $condition_key => $condition ) {
$validated = PUM_Conditions::instance()->validate_condition( $condition );
if ( ! is_wp_error( $validated ) ) {
$conditions[ $group_key ][ $condition_key ] = $validated;
}
}
}
update_post_meta( $popup->ID, 'popup_conditions', $conditions );
$completed ++;
}
if ( $completed < $total ) {
$upgrades->set_arg( 'completed', $completed );
self::next_step();
}
}
self::done();
}
/**
* Converts old condition keys into new condition arrays.
*
* @param array $targeting_conditions
*
* @return array
*/
public static function parse_conditions( $targeting_conditions = [] ) {
$conditions = [];
$targeting_conditions = array_keys( $targeting_conditions );
foreach ( $targeting_conditions as $index => $key ) {
$condition = null;
// Front Page
if ( strpos( $key, 'on_home' ) !== false ) {
$condition = [
'target' => 'is_front_page',
];
} // Blog Index
elseif ( strpos( $key, 'on_blog' ) !== false ) {
$condition = [
'target' => 'is_home',
];
} // Search Pages
elseif ( strpos( $key, 'on_search' ) !== false ) {
$condition = [
'target' => 'is_search',
];
} // 404 Pages
elseif ( strpos( $key, 'on_404' ) !== false ) {
$condition = [
'target' => 'is_404',
];
} // WooCommerce Pages
elseif ( strpos( $key, 'on_woocommerce' ) !== false ) {
$condition = [
'target' => 'is_woocommerce',
];
} // WooCommerce Shop Pages
elseif ( strpos( $key, 'on_shop' ) !== false ) {
$condition = [
'target' => 'is_shop',
];
}
if ( $condition ) {
unset( $targeting_conditions[ $index ] );
$conditions[] = $condition;
}
}
foreach ( get_post_types( [ 'public' => true ], 'objects' ) as $name => $post_type ) {
$pt_conditions = self::filter_conditions( $targeting_conditions, '_' . $name );
if ( empty( $pt_conditions ) ) {
continue;
}
if ( in_array( "on_{$name}s", $pt_conditions ) && ! in_array( "on_specific_{$name}s", $pt_conditions ) ) {
$conditions[] = [
'target' => $name . '_all',
];
continue;
}
// Remove non ID keys
unset( $pt_conditions[ "on_{$name}s" ] );
unset( $pt_conditions[ "on_specific_{$name}s" ] );
$ids = [];
// Convert the rest of the keys to post IDs.
foreach ( $pt_conditions as $key ) {
$id = intval( preg_replace( '/[^0-9]+/', '', $key ), 10 );
if ( $id > 0 ) {
$ids[] = $id;
}
}
// Create a new post_type_selected condition with the ids.
$conditions[] = [
'target' => $name . '_selected',
'selected' => $ids,
];
}
foreach ( get_taxonomies( [ 'public' => true ], 'objects' ) as $tax_name => $taxonomy ) {
$tax_conditions = self::filter_conditions( $targeting_conditions, '_' . $tax_name );
if ( empty( $tax_conditions ) ) {
continue;
}
if ( in_array( "on_{$tax_name}s", $tax_conditions ) && ! in_array( "on_specific_{$tax_name}s", $tax_conditions ) ) {
$conditions[] = [
'target' => 'tax_' . $tax_name . '_all',
];
continue;
}
// Remove non ID keys
unset( $tax_conditions[ "on_{$tax_name}s" ] );
unset( $tax_conditions[ "on_specific_{$tax_name}s" ] );
$ids = [];
// Convert the rest of the keys to post IDs.
foreach ( $tax_conditions as $key ) {
$id = intval( preg_replace( '/[^0-9]+/', '', $key ), 10 );
if ( $id > 0 ) {
$ids[] = $id;
}
}
// Create a new post_type_selected condition with the ids.
$conditions[] = [
'target' => 'tax_' . $tax_name . '_selected',
'selected' => $ids,
];
}
return $conditions;
}
/**
* Filters conditions for substrings and removes keys from original array.
*
* @param $targeting_conditions
* @param $string
*
* @return array
*/
public static function filter_conditions( &$targeting_conditions, $string ) {
$conditions = [];
foreach ( $targeting_conditions as $index => $key ) {
if ( $string === '_post' && strpos( $key, '_post_tag' ) !== false ) {
continue;
}
if ( strpos( $key, $string ) !== false ) {
$key = str_replace( 'exclude_', '', $key );
$conditions[ $key ] = $key;
unset( $targeting_conditions[ $index ] );
}
}
return $conditions;
}
/**
* Change a post status for a specified post_id.
*
* @param $post_id
* @param $status
*/
public static function change_post_status( $post_id, $status ) {
$current_post = get_post( $post_id, 'ARRAY_A' );
$current_post['post_status'] = $status;
wp_update_post( $current_post );
}
/**
* Filters out only inclusionary conditions.
*
* @param array $conditions
*
* @return array
*/
public static function filter_includes( $conditions = [] ) {
$includes = [];
foreach ( $conditions as $condition => $value ) {
if ( strpos( $condition, 'on_' ) === 0 ) {
$includes[ $condition ] = $condition;
}
}
return $includes;
}
/**
* Filters out only exclusionary conditions.
*
* @param array $conditions
*
* @return array
*/
public static function filter_excludes( $conditions = [] ) {
$excludes = [];
foreach ( $conditions as $condition => $value ) {
if ( strpos( $condition, 'exclude_on_' ) === 0 ) {
$excludes[ $condition ] = $condition;
}
}
return $excludes;
}
}

View File

@@ -0,0 +1,163 @@
<?php
/**
* Upgrade Routine 5 - Initialize popup analytics.
*
* @package PUM
* @subpackage Admin/Upgrades
* @copyright Copyright (c) 2023, Code Atlantic LLC
* @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
* @since 1.4
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'PUM_Admin_Upgrade_Routine' ) ) {
require_once POPMAKE_DIR . 'includes/admin/upgrades/class-pum-admin-upgrade-routine.php';
}
/**
* Class PUM_Admin_Upgrade_Routine_5
*/
final class PUM_Admin_Upgrade_Routine_5 extends PUM_Admin_Upgrade_Routine {
/**
* @return mixed|void
*/
public static function description() {
return __( 'Initialize popup analytics.', 'popup-maker' );
}
/**
*
*/
public static function run() {
if ( ! current_user_can( PUM_Admin_Upgrades::instance()->required_cap ) ) {
wp_die( __( 'You do not have permission to do upgrades', 'popup-maker' ), __( 'Error', 'popup-maker' ), [ 'response' => 403 ] );
}
ignore_user_abort( true );
if ( ! pum_is_func_disabled( 'set_time_limit' ) ) {
@set_time_limit( 0 );
}
$upgrades = PUM_Admin_Upgrades::instance();
$completed = $upgrades->get_arg( 'completed' );
$total = $upgrades->get_arg( 'total' );
// Set the correct total.
if ( $total <= 1 ) {
$popups = wp_count_posts( 'popup' );
$total = 0;
foreach ( $popups as $status ) {
$total += $status;
}
$upgrades->set_arg( 'total', $total );
}
$popups = pum_get_popups(
[
'number' => $upgrades->get_arg( 'number' ),
'page' => $upgrades->get_arg( 'step' ),
'status' => [ 'any', 'trash', 'auto-draft' ],
'order' => 'ASC',
]
);
if ( $popups ) {
foreach ( $popups as $popup ) {
/**
* Initialize the popup meta values for core analytics.
*/
self::initialize_analytics( $popup->ID );
$completed ++;
}
if ( $completed < $total ) {
$upgrades->set_arg( 'completed', $completed );
self::next_step();
}
}
// Check for popup analytics extension and import those stats if available.
$total_open_count = get_option( 'popup_analytics_total_opened_count', 0 );
// Set the sites total open count.
update_option( 'pum_total_open_count', $total_open_count );
// If is multisite add this blogs total to the site totals.
if ( function_exists( 'is_multisite' ) && is_multisite() ) {
$site_total_open_count = get_site_option( 'pum_site_total_open_count', 0 );
update_site_option( 'pum_site_total_open_count', $site_total_open_count + $total_open_count );
}
/**
* TODO Move this to v1.5 routines.
*/
/*
// Check for popup analytics extension and import those stats if available.
$total_conversion_count = get_site_option( 'popup_analytics_total_conversion_count', 0 );
// Set the sites total open count.
update_site_option( 'pum_total_conversion_count', $total_conversion_count );
*/
self::done();
}
/**
* Imports Popup Analytic data if available and initializes all popup analytic meta data.
*
* @param $popup_id
*/
public static function initialize_analytics( $popup_id ) {
// Open Count
$open_count = get_post_meta( $popup_id, 'popup_analytic_opened_count', true );
if ( ! $open_count ) {
$open_count = 0;
}
// Last Open
$last_open = get_post_meta( $popup_id, 'popup_analytic_last_opened', true );
if ( ! $last_open ) {
$last_open = 0;
}
// Add the meta.
update_post_meta( $popup_id, 'popup_open_count', absint( $open_count ) );
update_post_meta( $popup_id, 'popup_open_count_total', absint( $open_count ) );
update_post_meta( $popup_id, 'popup_last_opened', absint( $last_open ) );
/**
* TODO Move this to v1.5 routines.
*/
/*
// Conversion Count
$conversion_count = get_post_meta( $popup_id, 'popup_analytic_conversion_count', true );
if ( ! $conversion_count ) {
$conversion_count = 0;
}
// Last Conversion
$last_conversion = get_post_meta( $popup_id, 'popup_analytic_last_conversion', true );
if ( ! $last_conversion ) {
$last_conversion = 0;
}
// Calculate and set the conversion rate.
$conversion_rate = $conversion_count / $open_count * 100;
// Add the meta.
update_post_meta( $popup_id, 'popup_conversion_count', $conversion_count );
update_post_meta( $popup_id, 'popup_last_conversion', $last_conversion );
update_post_meta( $popup_id, 'popup_conversion_rate', $conversion_rate );
*/
}
}

View File

@@ -0,0 +1,215 @@
<?php
/**
* Upgrade Routine 6 - Clean up old data and verify data integrity.
*
* @package PUM
* @subpackage Admin/Upgrades
* @copyright Copyright (c) 2023, Code Atlantic LLC
* @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
* @since 1.4
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'PUM_Admin_Upgrade_Routine' ) ) {
require_once POPMAKE_DIR . 'includes/admin/upgrades/class-pum-admin-upgrade-routine.php';
}
/**
* Class PUM_Admin_Upgrade_Routine_6
*/
final class PUM_Admin_Upgrade_Routine_6 extends PUM_Admin_Upgrade_Routine {
/**
* @var null
*/
public static $valid_themes = null;
/**
* @var null
*/
public static $default_theme = null;
/**
* Returns the description.
*
* @return mixed|void
*/
public static function description() {
return __( 'Clean up old data and verify data integrity.', 'popup-maker' );
}
/**
* Run the update.
*/
public static function run() {
if ( ! current_user_can( PUM_Admin_Upgrades::instance()->required_cap ) ) {
wp_die( __( 'You do not have permission to do upgrades', 'popup-maker' ), __( 'Error', 'popup-maker' ), [ 'response' => 403 ] );
}
ignore_user_abort( true );
if ( ! pum_is_func_disabled( 'set_time_limit' ) ) {
@set_time_limit( 0 );
}
$upgrades = PUM_Admin_Upgrades::instance();
$completed = $upgrades->get_arg( 'completed' );
$total = $upgrades->get_arg( 'total' );
// Install new themes
pum_install_built_in_themes();
// Refresh CSS transients
pum_reset_assets();
// Set the correct total.
if ( $total <= 1 ) {
$popups = wp_count_posts( 'popup' );
$total = 0;
foreach ( $popups as $status ) {
$total += $status;
}
$upgrades->set_arg( 'total', $total );
}
$popups = pum_get_popups(
[
'number' => $upgrades->get_arg( 'number' ),
'page' => $upgrades->get_arg( 'step' ),
'status' => [ 'any', 'trash', 'auto-draft' ],
'order' => 'ASC',
]
);
self::setup_valid_themes();
// Delete All old meta keys.
self::delete_all_old_meta_keys();
// Delete All orphaned meta keys.
self::delete_all_orphaned_meta_keys();
self::process_popup_cats_tags();
if ( $popups ) {
foreach ( $popups as $popup ) {
// Check that each popup has a valid theme id
if ( ! array_key_exists( $popup->get_theme_id(), self::$valid_themes ) ) {
// Set a valid theme.
update_post_meta( $popup->ID, 'popup_theme', self::$default_theme );
}
$completed ++;
}
if ( $completed < $total ) {
$upgrades->set_arg( 'completed', $completed );
self::next_step();
}
}
self::done();
}
/**
* Create a list of valid popup themes.
*/
public static function setup_valid_themes() {
self::$valid_themes = [];
foreach ( pum_get_all_themes() as $theme ) {
self::$valid_themes[ $theme->ID ] = $theme;
if ( pum_get_default_theme_id() === $theme->ID ) {
self::$default_theme = $theme->ID;
}
}
if ( ! self::$default_theme ) {
reset( self::$valid_themes );
self::$default_theme = self::$valid_themes[ key( self::$valid_themes ) ]->ID;
}
}
/**
* Delete orphaned post meta keys.
*/
public static function delete_all_orphaned_meta_keys() {
global $wpdb;
$wpdb->query(
"
DELETE pm
FROM $wpdb->postmeta pm
LEFT JOIN $wpdb->posts wp ON wp.ID = pm.post_id
WHERE wp.ID IS NULL
AND pm.meta_key LIKE 'popup_%'"
);
}
/**
* Delete all no longer meta keys to clean up after ourselves.
*
* @return false|int
*/
public static function delete_all_old_meta_keys() {
global $wpdb;
$query = $wpdb->query(
"
DELETE FROM $wpdb->postmeta
WHERE meta_key LIKE 'popup_display_%'
OR meta_key LIKE 'popup_close_%'
OR meta_key LIKE 'popup_auto_open_%'
OR meta_key LIKE 'popup_click_open_%'
OR meta_key LIKE 'popup_targeting_condition_%'
OR meta_key LIKE 'popup_loading_condition_%'
OR meta_key = 'popup_admin_debug'
OR meta_key = 'popup_defaults_set'
OR meta_key LIKE 'popup_display_%'
OR meta_key = 'popup_auto_open'
OR meta_key = 'popup_click_open'
OR meta_key LIKE 'popup_theme_overlay_%'
OR meta_key LIKE 'popup_theme_container_%'
OR meta_key LIKE 'popup_theme_title_%'
OR meta_key LIKE 'popup_theme_content_%'
OR meta_key LIKE 'popup_theme_close_%'
OR meta_key = 'popmake_default_theme'
OR meta_key = 'popup_theme_defaults_set'
"
);
return $query;
}
/**
* Checks for popup taxonomy counts and disables popup taxonomies if none are found.
*/
public static function process_popup_cats_tags() {
global $popmake_options;
// Setup the Popup Taxonomies
popmake_setup_taxonomies( true );
$categories = wp_count_terms( 'popup_category', [ 'hide_empty' => true ] );
$tags = wp_count_terms( 'popup_tag', [ 'hide_empty' => true ] );
if ( is_wp_error( $tags ) ) {
$tags = 0;
}
if ( is_wp_error( $categories ) ) {
$categories = 0;
}
$popmake_options['disable_popup_category_tag'] = 0 === $categories && 0 === $tags;
update_option( 'popmake_settings', $popmake_options );
}
}

View File

@@ -0,0 +1,103 @@
<?php
/**
* Upgrade Routine Class
*
* @package PUM
* @subpackage Admin/Upgrades
* @copyright Copyright (c) 2023, Code Atlantic LLC
* @license http://opensource.org/licenses/gpl-3.0.php GNU Public License
* @since 1.4
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Class PUM_Admin_Upgrade_Routine
*/
class PUM_Admin_Upgrade_Routine {
/**
* Describe the upgrade routine.
*
* @return string
*/
public static function description() {
return '';
}
/**
* Run the upgrade routine.
*
* @return void
*/
public static function run() {
}
/**
* Properly redirects or returns redirect url if DOING_AJAX.
*
* @param string $redirect
*/
public static function redirect( $redirect = '' ) {
wp_safe_redirect( $redirect );
exit;
}
/**
* Generate the next step ajax response or redirect.
*/
public static function next_step() {
$upgrades = PUM_Admin_Upgrades::instance();
$upgrades->step_up();
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
echo wp_json_encode(
[
'status' => sprintf( __( 'Step %1$d of approximately %2$d running', 'popup-maker' ), $upgrades->get_arg( 'step' ), $upgrades->get_arg( 'steps' ) ),
'next' => $upgrades->get_args(),
]
);
exit;
} else {
$redirect = add_query_arg( $upgrades->get_args(), admin_url() );
self::redirect( $redirect );
}
}
public static function done() {
$upgrades = PUM_Admin_Upgrades::instance();
delete_option( 'pum_doing_upgrade' );
$upgrades->set_upgrade_complete( $upgrades->current_routine() );
$upgrades->set_pum_db_ver( $upgrades->get_arg( 'pum-upgrade' ) );
$next_routine = $upgrades->next_routine();
if ( $upgrades->has_upgrades() && $next_routine && $upgrades->get_upgrade( $next_routine ) ) {
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
$upgrades->set_arg( 'step', 1 );
$upgrades->set_arg( 'completed', 0 );
$upgrades->set_arg( 'pum-upgrade', $next_routine );
echo wp_json_encode(
[
'status' => sprintf( '<strong>%s</strong>', $upgrades->get_upgrade( $next_routine ) ),
'next' => $upgrades->get_args(),
]
);
exit;
}
}
}
}