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,33 @@
<?php
/**
* Functions for Theme Conditionals
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Checks if the $theme is valid.
*
* @param mixed|PUM_Model_Theme $theme
*
* @return bool
*/
function pum_is_theme( $theme ) {
return is_object( $theme ) && is_numeric( $theme->ID ) && $theme->is_valid();
}
/**
* Tests a given value to see if its a valid Theme model.
*
* @param mixed|PUM_Model_Theme $theme
*
* @return bool
*/
function pum_is_theme_object( $theme ) {
return is_a( $theme, 'PUM_Model_Theme' );
}

View File

@@ -0,0 +1,483 @@
<?php
/**
* Functions for Deprecated Themes
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* @deprecated 1.8.0 use pum_get_theme_generated_styles
*
* @param int $popup_theme_id
*
* @return array
*/
function popmake_generate_theme_styles( $popup_theme_id = 0 ) {
return pum_get_theme_generated_styles( $popup_theme_id );
}
/**
* Get theme meta defaults from data model 1.
*
* @since 1.8.0
*
* @param null|string $group
*
* @return array|bool|mixed
*/
function pum_get_theme_v1_meta_defaults() {
}
// TODO LEFT OFF HERE
// REFACTOR v1 meta getter & defaults.
// CONTINUE PURGING CODE.
/**
* Fetches theme meta group data from v1 data format.
*
* @deprecated 1.1.0
* @since 1.8.0
*
* @param $group
* @param null $popup_theme_id
* @param null $key
* @param null $default
*
* @return mixed
*/
function pum_get_theme_v1_meta( $group, $popup_theme_id = null, $key = null, $default = null ) {
if ( ! $popup_theme_id ) {
$popup_theme_id = get_the_ID();
}
$post_meta = get_post_custom( $popup_theme_id );
if ( ! is_array( $post_meta ) ) {
$post_meta = [];
}
$default_check_key = 'popup_theme_defaults_set';
if ( ! in_array( $group, [ 'overlay', 'close', 'display', 'targeting_condition' ] ) ) {
$default_check_key = "popup_{$group}_defaults_set";
}
$group_values = array_key_exists( $default_check_key, $post_meta ) ? [] : apply_filters( "popmake_popup_theme_{$group}_defaults", [] );
foreach ( $post_meta as $meta_key => $value ) {
if ( strpos( $meta_key, "popup_theme_{$group}_" ) !== false ) {
$new_key = str_replace( "popup_theme_{$group}_", '', $meta_key );
if ( count( $value ) === 1 ) {
$group_values[ $new_key ] = $value[0];
} else {
$group_values[ $new_key ] = $value;
}
}
}
if ( $key ) {
$key = str_replace( '.', '_', $key );
if ( ! isset( $group_values[ $key ] ) ) {
$value = $default;
} else {
$value = $group_values[ $key ];
}
return apply_filters( "popmake_get_popup_theme_{$group}_$key", $value, $popup_theme_id );
} else {
return apply_filters( "popmake_get_popup_theme_{$group}", $group_values, $popup_theme_id );
}
}
/**
* Get theme meta defaults from data model 2.
*
* @since 1.8.0
*
* @param null|string $group
*
* @return array|bool|mixed
*/
function pum_get_theme_v2_meta_defaults( $group = null ) {
$defaults = [
'overlay' => [
'background_color' => '#ffffff',
'background_opacity' => 100,
],
'container' => [
'padding' => 18,
'background_color' => '#f9f9f9',
'background_opacity' => 100,
'border_style' => 'none',
'border_color' => '#000000',
'border_width' => 1,
'border_radius' => 0,
'boxshadow_inset' => 'no',
'boxshadow_horizontal' => 1,
'boxshadow_vertical' => 1,
'boxshadow_blur' => 3,
'boxshadow_spread' => 0,
'boxshadow_color' => '#020202',
'boxshadow_opacity' => 23,
],
'title' => [
'font_color' => '#000000',
'line_height' => 36,
'font_size' => 32,
'font_family' => 'inherit',
'font_weight' => 'inherit',
'font_style' => 'normal',
'text_align' => 'left',
'textshadow_horizontal' => 0,
'textshadow_vertical' => 0,
'textshadow_blur' => 0,
'textshadow_color' => '#020202',
'textshadow_opacity' => 23,
],
'content' => [
'font_color' => '#8c8c8c',
'font_family' => 'inherit',
'font_weight' => 'inherit',
'font_style' => 'normal',
],
'close' => [
'text' => __( 'CLOSE', 'popup-maker' ),
'location' => 'topright',
'position_top' => 0,
'position_left' => 0,
'position_bottom' => 0,
'position_right' => 0,
'padding' => 8,
'height' => 0,
'width' => 0,
'background_color' => '#00b7cd',
'background_opacity' => 100,
'font_color' => '#ffffff',
'line_height' => 14,
'font_size' => 12,
'font_family' => 'inherit',
'font_weight' => 'inherit',
'font_style' => 'normal',
'border_style' => 'none',
'border_color' => '#ffffff',
'border_width' => 1,
'border_radius' => 0,
'boxshadow_inset' => 'no',
'boxshadow_horizontal' => 0,
'boxshadow_vertical' => 0,
'boxshadow_blur' => 0,
'boxshadow_spread' => 0,
'boxshadow_color' => '#020202',
'boxshadow_opacity' => 23,
'textshadow_horizontal' => 0,
'textshadow_vertical' => 0,
'textshadow_blur' => 0,
'textshadow_color' => '#000000',
'textshadow_opacity' => 23,
],
];
// Here for backward compatibility with extensions.
foreach ( $defaults as $key => $values ) {
$defaults[ $key ] = apply_filters( "popmake_popup_theme_{$key}_defaults", $values );
}
return isset( $group ) ? ( isset( $defaults[ $group ] ) ? $defaults[ $group ] : false ) : $defaults;
}
/**
* Fetch themes v2 meta as a single array.
*
* @param null|int $theme_id
*
* @return array|bool
*/
function pum_get_theme_v2_meta( $theme_id = null ) {
$theme = pum_get_theme( $theme_id );
if ( ! pum_is_theme( $theme ) ) {
return false;
}
$defaults = pum_get_theme_v2_meta_defaults();
$values = [
'overlay' => $theme->get_meta( 'popup_theme_overlay' ),
'container' => $theme->get_meta( 'popup_theme_container' ),
'title' => $theme->get_meta( 'popup_theme_title' ),
'content' => $theme->get_meta( 'popup_theme_content' ),
'close' => $theme->get_meta( 'popup_theme_close' ),
];
foreach ( array_keys( $values ) as $array_key ) {
$values[ $array_key ] = wp_parse_args( $values[ $array_key ], $defaults[ $array_key ] );
}
return $values;
}
/**
* Fetches theme meta group data from v2 data format.
*
* @deprecated 1.3.0
* @since 1.8.0
*
* @param string $meta_group
* @param null|int $theme_id
* @param null|string $option_key
* @param null|mixed $default
*
* @return mixed
*/
function pum_get_theme_v2_meta_group( $meta_group, $theme_id = null, $option_key = null, $default = null ) {
$theme_meta = pum_get_theme_v2_meta( $theme_id );
if ( ! $theme_meta ) {
return false;
}
$group_meta = ! empty( $theme_meta[ $meta_group ] ) ? $theme_meta[ $meta_group ] : false;
if ( ! $group_meta ) {
return $default;
}
if ( isset( $option_key ) ) {
$value = isset( $group_meta[ $option_key ] ) ? $group_meta[ $option_key ] : $default;
return apply_filters( "popmake_get_popup_theme_{$meta_group}_$option_key", $value, $theme_id );
} else {
return apply_filters( "popmake_get_popup_theme_{$meta_group}", $group_meta, $theme_id );
}
}
/**
* Returns the overlay meta of a theme.
*
* @since 1.0
* @deprecated 1.8.0
* @remove 2.0.0
*
* @param int $popup_theme_id ID number of the popup to retrieve a overlay meta for
*
* @param null $key
* @param null $default
*
* @return mixed array|string of the popup overlay meta
*/
function popmake_get_popup_theme_overlay( $popup_theme_id = null, $key = null, $default = null ) {
return pum_get_theme_v2_meta_group( 'overlay', $popup_theme_id, $key, $default );
}
/**
* Returns the container meta of a theme.
*
* @since 1.0
* @deprecated 1.8.0
* @remove 2.0.0
*
* @param int $popup_theme_id ID number of the popup to retrieve a container meta for
*
* @param null $key
* @param null $default
*
* @return mixed array|string of the popup container meta
*/
function popmake_get_popup_theme_container( $popup_theme_id = null, $key = null, $default = null ) {
return pum_get_theme_v2_meta_group( 'container', $popup_theme_id, $key, $default );
}
/**
* Returns the title meta of a theme.
*
* @since 1.0
* @deprecated 1.8.0
* @remove 2.0.0
*
* @param int $popup_theme_id ID number of the popup to retrieve a title meta for
* @param null $key
* @param null $default
*
* @return mixed array|string of the popup title meta
*/
function popmake_get_popup_theme_title( $popup_theme_id = null, $key = null, $default = null ) {
return pum_get_theme_v2_meta_group( 'title', $popup_theme_id, $key, $default );
}
/**
* Returns the content meta of a theme.
*
* @since 1.0
* @deprecated 1.8.0
* @remove 2.0.0
*
* @param int $popup_theme_id ID number of the popup to retrieve a content meta for
*
* @param null $key
* @param null $default
*
* @return mixed array|string of the popup content meta
*/
function popmake_get_popup_theme_content( $popup_theme_id = null, $key = null, $default = null ) {
return pum_get_theme_v2_meta_group( 'content', $popup_theme_id, $key, $default );
}
/**
* Returns the close meta of a theme.
*
* @since 1.0
* @deprecated 1.8.0
* @remove 2.0.0
*
* @param int $popup_theme_id ID number of the popup to retrieve a close meta for
*
* @param null $key
* @param null $default
*
* @return mixed array|string of the popup close meta
*/
function popmake_get_popup_theme_close( $popup_theme_id = null, $key = null, $default = null ) {
return pum_get_theme_v2_meta_group( 'close', $popup_theme_id, $key, $default );
}
/**\
*
* @deprecated 1.8.0
*
* @param int $theme_id
*
* @return mixed
*/
function popmake_get_popup_theme_data_attr( $theme_id = 0 ) {
$data_attr = pum_get_theme_v2_meta( $theme_id );
return apply_filters( 'popmake_get_popup_theme_data_attr', $data_attr, $theme_id );
}
/**
* @deprecated 1.8.0 Do not use!
* @remove 1.9.0
*
* @return mixed
*/
function popmake_get_popup_themes_data() {
$themes = pum_get_all_themes();
$popmake_themes = [];
foreach ( $themes as $theme ) {
$popmake_themes[ $theme->ID ] = popmake_get_popup_theme_data_attr( $theme->ID );
}
wp_reset_postdata();
return apply_filters( 'popmake_get_popup_themes_data', $popmake_themes );
}
/**
* Returns the meta group of a theme or value if key is set.
*
* @since 1.0
* @deprecated 1.3.0
* @remove 2.0.0
*
* @param $group
* @param int $popup_theme_id ID number of the popup to retrieve a overlay meta for
* @param null $key
* @param null $default
*
* @return mixed array|string of the popup overlay meta
*/
function popmake_get_popup_theme_meta_group( $group, $popup_theme_id = null, $key = null, $default = null ) {
return pum_get_theme_v1_meta( $group, $popup_theme_id, $key, $default );
}
/**
* Fetches theme meta group data from v2 data format.
*
* @since 1.3.0
* @deprecated 1.7.0
* @remove 2.0.0
*
* @param $group
* @param null $popup_theme_id
* @param null $key
* @param null $default
*
* @return mixed
*/
function popmake_get_popup_theme_meta( $group, $popup_theme_id = null, $key = null, $default = null ) {
return pum_get_theme_v2_meta_group( $group, $popup_theme_id, $key, $default );
}
/**
* @deprecated 1.3.0
* @remove 2.0.0
*
* @return array|bool|mixed
*/
function popmake_popup_theme_overlay_defaults() {
return pum_get_theme_v2_meta_defaults( 'overlay' );
}
/**
* @deprecated 1.3.0
* @remove 2.0.0
*
* @return array|bool|mixed
*/
function popmake_popup_theme_container_defaults() {
return pum_get_theme_v2_meta_defaults( 'container' );
}
/**
* @deprecated 1.3.0
* @remove 2.0.0
*
* @return array|bool|mixed
*/
function popmake_popup_theme_title_defaults() {
return pum_get_theme_v2_meta_defaults( 'title' );
}
/**
* @deprecated 1.3.0
* @remove 2.0.0
*
* @return array|bool|mixed
*/
function popmake_popup_theme_content_defaults() {
return pum_get_theme_v2_meta_defaults( 'content' );
}
/**
* @deprecated 1.3.0
* @remove 2.0.0
*
* @return array|bool|mixed
*/
function popmake_popup_theme_close_defaults() {
return pum_get_theme_v2_meta_defaults( 'close' );
}
/**
* @deprecated 1.8.0
*
* @return \PUM_Model_Theme[]
*/
function popmake_get_all_popup_themes() {
return pum_get_all_themes();
}
/**
* @deprecated 1.8.0
*
* @return false|int
*/
function popmake_get_default_popup_theme() {
return pum_get_default_theme_id();
}

View File

@@ -0,0 +1,45 @@
<?php
/**
* Functions for Theme Getters
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Return the theme id.
*
* @param int $theme_id
*
* @return int
*/
function pum_get_theme_id( $theme_id = 0 ) {
if ( ! empty( $theme_id ) && is_numeric( $theme_id ) ) {
$_theme_id = $theme_id;
} elseif ( is_object( pum()->current_theme ) && is_numeric( pum()->current_theme->ID ) ) {
$_theme_id = pum()->current_theme->ID;
} else {
$_theme_id = 0;
}
return (int) apply_filters( 'pum_get_theme_id', (int) $_theme_id, $theme_id );
}
/**
* @param int $theme_id
*
* @return array
*/
function pum_get_theme_generated_styles( $theme_id = 0 ) {
$theme = pum_get_theme( $theme_id );
if ( ! pum_is_theme_object( $theme ) ) {
return [];
}
return $theme->get_generated_styles();
}

View File

@@ -0,0 +1,148 @@
<?php
/**
* Functions for Theme Migrations
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
/**
* Checks if passive migration for popups should be enabled.
*
* This determines if the query load may be potentially too high to run passive migrations on live servers.
*
* @return bool
*/
function pum_passive_theme_upgrades_enabled() {
/** @var int $theme_count */
static $theme_count;
if ( defined( 'PUM_DISABLE_PASSIVE_UPGRADES' ) && PUM_DISABLE_PASSIVE_UPGRADES ) {
return false;
}
if ( ! $theme_count ) {
$theme_count = get_transient( 'pum_theme_count' );
if ( false === $theme_count ) {
$theme_count = pum_count_themes(
[
'post_status' => [ 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash' ],
]
);
set_transient( 'pum_theme_count', $theme_count, MINUTE_IN_SECONDS );
}
}
return pum_is_popup_theme_editor() || $theme_count <= apply_filters( 'pum_passive_themes_enabled_max_count', 10 );
}
/**
* Upgrade popup data to model v2.
*
* @since 1.8.0
*
* @param PUM_Model_Theme $theme
*/
function pum_theme_migration_1( &$theme ) {
$delete_meta = [ 'popup_theme_defaults_set' ];
// Used to merge with existing values to ensure data integrity.
$meta_defaults = pum_get_theme_v2_meta_defaults();
foreach ( array_keys( $meta_defaults ) as $group ) {
// Get old data.
$v1_meta_values = pum_get_theme_v1_meta( $group, $theme->ID );
// Loop over all fields which were merged and mark their meta keys for deletion.
foreach ( $v1_meta_values as $old_meta_key => $old_meta_value ) {
$delete_meta[] = "popup_theme_{$group}_{$old_meta_key}";
}
$existing_v2_meta = $theme->get_meta( "popup_theme_{$group}" );
if ( ! empty( $existing_v2_meta ) ) {
continue;
}
// Merge defaults.
$values = wp_parse_args( $v1_meta_values, $meta_defaults[ $group ] );
// Update meta storage.
$theme->update_meta( "popup_theme_{$group}", $values );
}
/**
* Clean up automatically.
*/
pum_cleanup_post_meta_keys( $theme->ID, $delete_meta );
}
add_action( 'pum_theme_passive_migration_1', 'pum_theme_migration_1' );
/**
* Upgrade popup data to model v3.
*
* @since 1.8.0
*
* @param PUM_Model_Theme $theme
*/
function pum_theme_migration_2( &$theme ) {
$changed = false;
$delete_meta = [];
$settings = $theme->get_settings();
$old_meta_elements = [
'overlay',
'container',
'title',
'content',
'close',
];
foreach ( $old_meta_elements as $element ) {
$meta_key = 'popup_theme_' . $element;
/**
* Migrate popup_theme_overlay meta data.
*/
$element_data = $theme->get_meta( $meta_key );
if ( ! empty( $element_data ) && is_array( $element_data ) ) {
$keys = $theme->remapped_meta_settings_keys( $element );
// Foreach old key, save the value under popup settings for the new key.
foreach ( $keys as $old_key => $new_key ) {
if ( isset( $element_data[ $old_key ] ) ) {
$settings[ $new_key ] = $element_data[ $old_key ];
$changed = true;
unset( $element_data[ $old_key ] );
}
}
if ( empty( $element_data ) ) {
$delete_meta[] = $meta_key;
} else {
// Update the saved popup display data with any remaining keys from extensions.
$theme->update_meta( $meta_key, $element_data );
}
}
}
/**
* Save only if something changed.
*/
if ( $changed ) {
$theme->update_meta( 'popup_theme_settings', $settings );
}
/**
* Clean up automatically.
*/
pum_cleanup_post_meta_keys( $theme->ID, $delete_meta );
}
add_action( 'pum_theme_passive_migration_2', 'pum_theme_migration_2' );

View File

@@ -0,0 +1,82 @@
<?php
/**
* Functions for Theme Portability
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
/**
* @param $name
* @param null $settings
* @param array $extra_meta
*
* @return int|\WP_Error
*/
function pum_install_theme( $name, $settings = null, $extra_meta = [] ) {
if ( ! isset( $settings ) ) {
$settings = PUM_Admin_Themes::defaults();
}
$new_theme_id = @wp_insert_post(
[
'post_title' => $name,
'post_author' => get_current_user_id(),
'post_status' => 'publish',
'post_type' => 'popup_theme',
'comment_status' => 'closed',
'meta_input' => array_merge(
(array) $extra_meta,
[
'popup_theme_settings' => $settings,
]
),
]
);
pum_reset_assets();
return $new_theme_id;
}
/**
* @param $hash
*
* @return mixed
*/
function pum_import_theme_from_repo( $hash ) {
$theme_data = [
'name' => __( 'Imported Theme', 'popup-maker' ),
'settings' => PUM_Admin_Themes::defaults(),
'original_author' => 'Daniel',
];
return pum_install_theme(
$theme_data['name'],
$theme_data['settings'],
[
'_pum_theme_repo_hash' => $hash,
'_pum_theme_repo_author' => $theme_data['original_author'],
]
);
}
/**
* Installs a default theme and returns the new theme ID.
*
* @since 1.8.0
*
* @return int|\WP_Error
*/
function pum_install_default_theme() {
return pum_install_theme(
__( 'Default Theme', 'popup-maker' ),
null,
[
'_pum_built_in' => 'default-theme',
'_pum_default_theme' => true,
'popup_theme_data_version' => 3,
]
);
}

View File

@@ -0,0 +1,73 @@
<?php
/**
* Functions for Theme Queries
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Get a theme model instance.
*
* @param int $theme_id
*
* @return PUM_Model_Theme
*/
function pum_get_theme( $theme_id = 0 ) {
if ( ! $theme_id ) {
$theme_id = pum_get_theme_id();
}
try {
return pum()->themes->get_item( $theme_id );
} catch ( InvalidArgumentException $e ) {
// Return empty object
return new PUM_Model_Theme( $theme_id );
}
}
/**
* Queries themes and returns them in a specific format.
*
* @param array $args
*
* @return PUM_Model_Theme[]
*/
function pum_get_themes( $args = [] ) {
return pum()->themes->get_items( $args );
}
/**
* Queries themes and returns them in a specific format.
*
* @param array $args
*
* @return PUM_Model_Theme[]
*/
function pum_get_all_themes( $args = [] ) {
$args['posts_per_page'] = -1;
return pum_get_themes( $args );
}
/**
* Gets a count themes with specified args.
*
* @param array $args
*
* @return int
*/
function pum_count_themes( $args = [] ) {
$args = wp_parse_args(
$args,
[
'post_status' => 'publish',
]
);
return pum()->themes->count_items( $args );
}

View File

@@ -0,0 +1,89 @@
<?php
/**
* Functions for Themes Template
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* @param $theme_id
*
* @return string
*/
function pum_get_rendered_theme_styles( $theme_id ) {
$styles = '';
$theme = pum_get_theme( $theme_id );
if ( ! pum_is_theme( $theme ) ) {
return '';
}
$slug = $theme->post_name;
$theme_styles = $theme->get_generated_styles();
if ( empty( $theme_styles ) ) {
return $styles;
}
foreach ( $theme_styles as $element => $element_rules ) {
switch ( $element ) {
case 'overlay':
$css_selector = ".pum-theme-{$theme_id}";
if ( $slug ) {
$css_selector .= ", .pum-theme-{$slug}";
}
break;
case 'container':
$css_selector = ".pum-theme-{$theme_id} .pum-container";
if ( $slug ) {
$css_selector .= ", .pum-theme-{$slug} .pum-container";
}
break;
case 'close':
$css_selector = ".pum-theme-{$theme_id} .pum-content + .pum-close";
$admin_bar_selector = "body.admin-bar .pum-theme-{$theme_id} .pum-content + .pum-close";
if ( $slug ) {
$css_selector .= ", .pum-theme-{$slug} .pum-content + .pum-close";
$admin_bar_selector .= ", body.admin-bar .pum-theme-{$slug} .pum-content + .pum-close";
}
break;
default:
$css_selector = ".pum-theme-{$theme_id} .pum-{$element}";
if ( $slug ) {
$css_selector .= ", .pum-theme-{$slug} .pum-{$element}";
}
break;
}
$rule_set = $sep = '';
foreach ( $element_rules as $property => $value ) {
if ( ! empty( $value ) ) {
$rule_set .= $sep . $property . ': ' . $value;
$sep = '; ';
}
}
$styles .= "$css_selector { $rule_set } \r\n";
if ( 'close' === $element && ! empty( $admin_bar_selector ) && $theme->get_setting( 'close_position_outside' ) && strpos( $theme->get_setting( 'close_location' ), 'top' ) !== false ) {
$top = ! empty( $element_rules['top'] ) ? (int) str_replace( 'px', '', $element_rules['top'] ) : 0;
// Move it down to compensate for admin bar height.
$top += 32;
$styles .= "$admin_bar_selector { top: {$top}px }";
}
}
return $styles;
}