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,170 @@
<?php
/**
* Functions for Admin Conditionals
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Determines whether the current page is an popup maker admin page.
*
* @since 1.7.0
*
* @return bool
*/
function pum_is_admin_page() {
if ( ! is_admin() || ! did_action( 'wp_loaded' ) ) {
return false;
}
$typenow = pum_typenow();
$tests = [
'popup' === $typenow,
'popup_theme' === $typenow,
! empty( $GLOBALS['hook_suffix'] ) && in_array( $GLOBALS['hook_suffix'], PUM_Admin_Pages::$pages ),
];
return in_array( true, $tests );
}
/**
* Determines whether the current admin page is the All Popups page.
*
* @since 1.12
* @return bool True if current page is All Popups page.
*/
function pum_is_all_popups_page() {
$screen = get_current_screen();
$tests = [
pum_is_admin_page(),
'edit-popup' === $screen->id,
pum_typenow() === 'popup',
];
return ! in_array( false, $tests, true );
}
/**
* Determines whether the current admin page is the popup editor.
*
* @since 1.7.0
*
* @return bool
*/
function pum_is_popup_editor() {
global $pagenow;
$tests = [
is_admin(),
pum_is_admin_page(),
'popup' === pum_typenow(),
in_array( $pagenow, [ 'post-new.php', 'post.php' ] ),
];
return ! in_array( false, $tests );
}
/**
* Determines whether the current admin page is the popup theme editor.
*
* @since 1.7.0
*
* @return bool
*/
function pum_is_popup_theme_editor() {
global $pagenow;
$tests = [
is_admin(),
pum_is_admin_page(),
'popup_theme' === pum_typenow(),
in_array( $pagenow, [ 'post-new.php', 'post.php' ] ),
];
return ! in_array( false, $tests );
}
/**
* Determines whether the current admin page is the extensions page.
*
* @since 1.7.0
*
* @param null|string $key
*
* @return bool
*/
function pum_is_submenu_page( $key = null ) {
$tests = [
is_admin(),
pum_is_admin_page(),
! pum_is_popup_editor(),
! pum_is_popup_theme_editor(),
$key && ! empty( $GLOBALS['hook_suffix'] ) ? PUM_Admin_Pages::get_page( $key ) === $GLOBALS['hook_suffix'] : true,
! isset( $key ) && ! empty( $GLOBALS['hook_suffix'] ) ? in_array( $GLOBALS['hook_suffix'], PUM_Admin_Pages::$pages ) : true,
];
return ! in_array( false, $tests );
}
/**
* Determines whether the current admin page is the subscriptions page.
*
* @since 1.7.0
*
* @return bool
*/
function pum_is_subscriptions_page() {
return pum_is_submenu_page( 'subscriptions' );
}
/**
* Determines whether the current admin page is the extensions page.
*
* @since 1.7.0
*
* @return bool
*/
function pum_is_extensions_page() {
return pum_is_submenu_page( 'extensions' );
}
/**
* Determines whether the current admin page is the settings page.
*
* @since 1.7.0
*
* @return bool
*/
function pum_is_settings_page() {
return pum_is_submenu_page( 'settings' );
}
/**
* Determines whether the current admin page is the tools page.
*
* @since 1.7.0
*
* @return bool
*/
function pum_is_tools_page() {
return pum_is_submenu_page( 'tools' );
}
/**
* Determines whether the current admin page is the support page.
*
* @since 1.7.0
*
* @return bool
*/
function pum_is_support_page() {
return pum_is_submenu_page( 'support' );
}

View File

@@ -0,0 +1,81 @@
<?php
/**
* Functions for General Admin
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Gets the current admin screen post type.
*
* @return bool|string
*/
function pum_typenow() {
if ( ! empty( $GLOBALS['typenow'] ) ) {
return $GLOBALS['typenow'];
}
// when editing pages, $typenow isn't set until later!
// try to pick it up from the query string
if ( ! empty( $_GET['post_type'] ) ) {
return sanitize_text_field( $_GET['post_type'] );
} elseif ( ! empty( $_GET['post'] ) && $_GET['post'] > 0 ) {
$post = get_post( $_GET['post'] );
} elseif ( ! empty( $_POST['post_ID'] ) && $_POST['post_ID'] > 0 ) {
$post = get_post( $_POST['post_ID'] );
}
return isset( $post ) && is_object( $post ) && $post->ID > 0 ? $post->post_type : false;
}
/**
* Generates an Popup Maker admin URL based on the given type.
*
* @since 1.7.0
*
* @param string $type Optional. Type of admin URL. Accepts 'tools', 'settings'. Default empty
* @param array $query_args Optional. Query arguments to append to the admin URL. Default empty array.
*
* @return string Constructed admin URL.
*/
function pum_admin_url( $type = '', $query_args = [] ) {
$page = '';
$whitelist = PUM_Admin_Pages::$pages;
if ( in_array( $type, $whitelist, true ) ) {
$page = "pum-{$type}";
}
$admin_query_args = array_merge( [ 'page' => $page ], $query_args );
$url = add_query_arg( $admin_query_args, admin_url( 'edit.php?post_type=popup' ) );
/**
* Filters the Popup Maker admin URL.
*
* @param string $url Admin URL.
* @param string $type Admin URL type.
* @param array $query_args Query arguments originally passed to pum_admin_url().
*/
return apply_filters( 'pum_admin_url', $url, $type, $query_args );
}
/**
* @return array
*/
function pum_support_assist_args() {
return [
// Forces the dashboard to force logout any users.
'nouser' => true,
'fname' => wp_get_current_user()->first_name,
'lname' => wp_get_current_user()->last_name,
'email' => wp_get_current_user()->user_email,
'url' => home_url(),
];
}

View File

@@ -0,0 +1,66 @@
<?php
/**
* Functions for developers
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Call this with a popup ID and it will trigger the
* JS based forms.success function with your settings
* on the next page load.
*
* @since 1.7.0
*
* @param int $popup_id
* @param array $settings
*/
function pum_trigger_popup_form_success( $popup_id = null, $settings = [] ) {
if ( ! isset( $popup_id ) ) {
$popup_id = isset( $_REQUEST['pum_form_popup_id'] ) && absint( $_REQUEST['pum_form_popup_id'] ) > 0 ? absint( $_REQUEST['pum_form_popup_id'] ) : false;
}
if ( $popup_id ) {
PUM_Integrations::$form_success = [
'popup_id' => $popup_id,
'settings' => $settings,
];
}
}
/**
* @param array $args {
* An array of parameters that customize the way the parser works.
*
* @type string $form_provider Key indicating which form provider this form belongs to.
* @type string|int $form_id Form ID, usually numeric, but can be hash based.
* @type int $form_instance_id Optional form instance ID.
* @type int $popup_id Optional popup ID.
* @type bool $ajax If the submission was processed via AJAX. Generally gonna be false outside of JavaScript.
* @type bool $tracked Whether the submission has been handled by tracking code or not. Prevents duplicates.
* }
*/
function pum_integrated_form_submission( $args = [] ) {
$args = wp_parse_args(
$args,
[
'popup_id' => null,
'form_provider' => null,
'form_id' => null,
'form_instance_id' => null,
'ajax' => false,
'tracked' => false,
]
);
$args = apply_filters( 'pum_integrated_form_submission_args', $args );
PUM_Integrations::$form_submission = $args;
do_action( 'pum_integrated_form_submission', $args );
}

View File

@@ -0,0 +1,38 @@
<?php
/**
* Functions for extensions
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Gets an array of active extensions.
*
* @since 1.7.0
*
* @return mixed
*/
function pum_enabled_extensions() {
return apply_filters( 'pum_enabled_extensions', [] );
}
/**
* Checks if a specified extension is currently active.
*
* @since 1.7.0
*
* @param string $extension
*
* @return bool
*/
function pum_extension_enabled( $extension = '' ) {
$enabled_extensions = pum_enabled_extensions();
return ! empty( $extension ) && array_key_exists( $extension, $enabled_extensions );
}

View File

@@ -0,0 +1,203 @@
<?php
/**
* General functions
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Get the current blog db_ver.
*
* @return mixed
*/
function pum_get_db_ver() {
return get_option( 'pum_db_ver', false );
}
/**
* Returns the default theme_id from global settings.
*
* Returns false if none set.
*
* @since 1.8.0
*
* @return int|false
*/
function pum_get_default_theme_id() {
$default_theme_id = pum_get_option( 'default_theme_id' );
if ( false === $default_theme_id ) {
$default_theme_id = get_option( 'popmake_default_theme' );
if ( false === $default_theme_id ) {
$default_theme_id = pum_install_default_theme();
if ( pum_update_option( 'default_theme_id', $default_theme_id ) ) {
// Self cleanup old version.
delete_option( 'popmake_default_theme' );
}
}
}
return absint( $default_theme_id );
}
/**
* Gets the cache close_text of a theme from wp_options to prevent un-needed queries on the front end.
*
* @since 1.8.0
*
* @param int $theme_id
*
* @return string
*/
function pum_get_theme_close_text( $theme_id = 0 ) {
$close_texts = pum_get_all_themes_close_text();
return isset( $close_texts[ $theme_id ] ) ? $close_texts[ $theme_id ] : '';
}
/**
* Gets the cache of theme close text from wp_options to prevent un-needed queries on the front end.
*
* @since 1.8.0
*
* @return array|mixed
*/
function pum_get_all_themes_close_text() {
$all_themes_close_text = get_option( 'pum_all_theme_close_text_cache' );
if ( false === $all_themes_close_text ) {
$all_themes_close_text = pum_update_all_themes_close_text_cache();
}
return $all_themes_close_text;
}
/**
* Updates the cache of theme close text to prevent un-needed queries on the front end.
*
* @since 1.8.0
*
* @return array
*/
function pum_update_all_themes_close_text_cache() {
$all_themes_close_text = [];
$themes = pum_get_all_themes();
foreach ( $themes as $theme ) {
$all_themes_close_text[ $theme->ID ] = $theme->get_setting( 'close_text', '' );
}
update_option( 'pum_all_theme_close_text_cache', $all_themes_close_text );
return $all_themes_close_text;
}
add_action( 'pum_save_theme', 'pum_update_all_themes_close_text_cache', 100 );
/**
* @param string $path
*
* @return string
*/
function pum_asset_path( $path = '' ) {
return Popup_Maker::$DIR . 'assets/' . ltrim( $path, '/' );
}
/**
* @param string $path
*
* @return string
*/
function pum_asset_url( $path = '' ) {
return Popup_Maker::$URL . 'assets/' . ltrim( $path, '/' );
}
/**
* @param string $encode
*
* @return string
*/
function pum_get_svg_icon( $encode = false ) {
$svg_icon_code = '<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" preserveAspectRatio="xMidYMid meet" viewBox="0 0 16 16" width="16" height="16"><defs><path d="M12.67 1.75L13.12 1.83L13.58 1.97L14.04 2.17L14.49 2.43L14.9 2.77L15.26 3.19L15.57 3.71L15.79 4.28L15.93 4.85L15.99 5.41L16 5.95L15.95 6.45L15.88 6.89L15.78 7.27L15.67 7.57L15.57 7.78L15.45 7.95L15.29 8.16L15.1 8.4L14.87 8.67L14.61 8.95L14.32 9.25L14 9.54L13.66 9.84L13.3 10.13L12.94 10.4L12.61 10.65L12.29 10.88L11.99 11.11L11.69 11.35L11.39 11.59L11.08 11.84L10.76 12.11L10.42 12.42L10.04 12.73L9.63 13.02L9.19 13.29L8.72 13.53L8.23 13.75L7.72 13.93L7.21 14.09L6.69 14.2L6.18 14.28L5.6 14.3L4.9 14.25L4.12 14.09L3.31 13.8L2.5 13.36L1.74 12.76L1.07 11.96L0.52 10.94L0.14 9.68L0 8.36L0.12 7.17L0.45 6.12L0.94 5.2L1.54 4.42L2.22 3.78L2.92 3.29L3.59 2.95L4.19 2.76L4.85 2.63L5.7 2.48L6.68 2.33L7.73 2.18L8.78 2.03L9.79 1.9L10.68 1.8L11.4 1.72L11.88 1.7L12.26 1.7L12.67 1.75ZM10.64 2.39L9.62 2.51L8.48 2.66L7.32 2.82L6.22 2.98L5.26 3.13L4.55 3.26L3.91 3.46L3.18 3.83L2.43 4.38L1.72 5.08L1.12 5.95L0.7 6.96L0.51 8.13L0.63 9.43L1 10.67L1.51 11.67L2.14 12.44L2.86 13.02L3.65 13.41L4.49 13.64L5.34 13.73L6.19 13.71L6.97 13.6L7.64 13.44L8.22 13.23L8.73 12.98L9.17 12.71L9.57 12.41L9.95 12.1L10.32 11.78L10.67 11.48L11 11.21L11.32 10.97L11.63 10.73L11.94 10.5L12.27 10.27L12.61 10.03L12.99 9.76L13.36 9.47L13.71 9.18L14.03 8.88L14.32 8.6L14.57 8.32L14.79 8.08L14.96 7.86L15.08 7.69L15.19 7.47L15.3 7.14L15.4 6.72L15.47 6.23L15.48 5.69L15.44 5.11L15.31 4.53L15.08 3.96L14.78 3.45L14.42 3.06L14.04 2.76L13.62 2.55L13.2 2.41L12.78 2.32L12.38 2.28L12 2.27L11.46 2.31L10.64 2.39Z" id="eLoMHfaS"></path><path d="M8.35 6.04L9.08 7.19L9.35 8.59L9.08 9.99L8.35 11.13L7.27 11.91L5.95 12.19L4.62 11.91L3.54 11.13L2.81 9.99L2.54 8.59L2.81 7.19L3.54 6.04L4.62 5.27L5.95 4.99L7.27 5.27L8.35 6.04ZM4.1 6.6L3.54 7.49L3.34 8.58L3.54 9.67L4.1 10.56L4.93 11.17L5.94 11.39L6.96 11.17L7.79 10.56L8.35 9.67L8.55 8.58L8.35 7.49L7.79 6.6L6.96 5.99L5.94 5.77L4.93 5.99L4.1 6.6Z" id="a1xlBX7eUk"></path><path d="M9.04 9.39L8.35 10.9L9.11 11.66C9.12 11.66 9.12 11.66 9.12 11.66C10.01 10.71 10.41 9.4 10.19 8.11C10.19 8.09 10.18 8.04 10.16 7.95L9.11 8.01L9.04 9.39Z" id="e1KfKU9JEu"></path><path d="M3.74 11.08L2.82 9.7L1.78 9.94C1.78 9.94 1.78 9.94 1.78 9.94C2.1 11.2 3 12.24 4.2 12.74C4.23 12.75 4.28 12.77 4.36 12.8L4.87 11.89L3.74 11.08Z" id="aswxBlyrF"></path><path d="M4.96 5.33L6.62 5.17L6.89 4.14C6.89 4.14 6.89 4.14 6.89 4.14C5.62 3.83 4.29 4.14 3.28 4.96C3.26 4.97 3.22 5.01 3.15 5.07L3.72 5.95L4.96 5.33Z" id="aFREkIqrT"></path><path d="M13.56 4.26L13.97 4.89L14.12 5.67L13.97 6.45L13.56 7.09L12.96 7.52L12.23 7.68L11.5 7.52L10.9 7.09L10.49 6.45L10.34 5.67L10.49 4.89L10.9 4.26L11.5 3.83L12.23 3.67L12.96 3.83L13.56 4.26ZM11.88 5.24L11.77 5.44L11.73 5.68L11.77 5.92L11.88 6.12L12.04 6.25L12.23 6.3L12.42 6.25L12.58 6.12L12.69 5.92L12.73 5.68L12.69 5.44L12.58 5.24L12.42 5.11L12.23 5.06L12.04 5.11L11.88 5.24Z" id="amDpzCYZN"></path><path d="M12.51 2.83L13.24 3.05L13.02 4.27L12.02 3.98L12.51 2.83Z" id="c1FHpaNCVv"></path><path d="M14.65 4.57L14.87 5.29L13.73 5.78L13.42 4.79L14.65 4.57Z" id="c59InZ73I"></path><path d="M14.34 7.35L13.77 7.85L12.85 7.02L13.62 6.33L14.34 7.35Z" id="cp1hej6U"></path><path d="M11.95 8.41L11.2 8.27L11.3 7.03L12.32 7.22L11.95 8.41Z" id="akiLoJGaJ"></path><path d="M9.69 6.69L9.58 5.95L10.78 5.62L10.95 6.64L9.69 6.69Z" id="a12HrJSLIM"></path><path d="M10.05 3.9L10.62 3.4L11.54 4.24L10.76 4.93L10.05 3.9Z" id="alSln9w1"></path></defs><g><g><g><use xlink:href="#eLoMHfaS" opacity="1" fill="black" fill-opacity="1"></use></g><g><g><use xlink:href="#a1xlBX7eUk" opacity="1" fill="black" fill-opacity="1"></use></g><g><use xlink:href="#e1KfKU9JEu" opacity="1" fill="black" fill-opacity="1"></use></g><g><use xlink:href="#aswxBlyrF" opacity="1" fill="black" fill-opacity="1"></use></g><g><use xlink:href="#aFREkIqrT" opacity="1" fill="black" fill-opacity="1"></use></g></g><g><g><use xlink:href="#amDpzCYZN" opacity="1" fill="black" fill-opacity="1"></use></g><g><use xlink:href="#c1FHpaNCVv" opacity="1" fill="black" fill-opacity="1"></use></g><g><use xlink:href="#c59InZ73I" opacity="1" fill="black" fill-opacity="1"></use></g><g><use xlink:href="#cp1hej6U" opacity="1" fill="black" fill-opacity="1"></use></g><g><use xlink:href="#akiLoJGaJ" opacity="1" fill="black" fill-opacity="1"></use></g><g><use xlink:href="#a12HrJSLIM" opacity="1" fill="black" fill-opacity="1"></use></g><g><use xlink:href="#alSln9w1" opacity="1" fill="black" fill-opacity="1"></use></g></g></g></g></svg>';
if ( $encode ) {
$svg_icon_code = 'data:image/svg+xml;base64,' . base64_encode( $svg_icon_code );
}
return $svg_icon_code;
}
/**
* Resets both asset cached files & transient CSS storage to be regenerated.
*
* @since 1.8.0
*/
function pum_reset_assets() {
// Reset/regenerate asset cache.
PUM_AssetCache::reset_cache();
// Reset/regenerate stored theme CSS styles.
delete_transient( 'popmake_theme_styles' );
}
/**
* Returns array key from dot notated array key..
*
* @since 1.0
*
* @deprecated 1.8.0
*
* @param array $a is the array you are searching.
* @param string $path is the dot notated path.
* @param string $default is the default returned if key empty or not found.
*
* @return mixed results of lookup
*/
function popmake_resolve( array $a, $path, $default = null ) {
$current = $a;
$p = strtok( $path, '.' );
while ( false !== $p ) {
if ( ! isset( $current[ $p ] ) ) {
return $default;
}
$current = $current[ $p ];
$p = strtok( '.' );
}
return $current;
}
/**
* Returns $_POST key.
*
* @since 1.0
*
* @param string $name is the key you are looking for. Can use dot notation for arrays such as my_meta.field1 which will resolve to $_POST['my_meta']['field1'].
*
* @return mixed results of lookup
*/
function popmake_post( $name, $do_stripslashes = true ) {
$value = popmake_resolve( $_POST, $name, false );
return $do_stripslashes ? stripslashes_deep( $value ) : $value;
}
/**
* Checks whether function is disabled.
*
* @since 1.4
*
* @param string $function Name of the function.
*
* @return bool Whether or not function is disabled.
*/
function pum_is_func_disabled( $function ) {
$disabled = explode( ',', ini_get( 'disable_functions' ) );
return in_array( $function, $disabled );
}

View File

@@ -0,0 +1,83 @@
<?php
/**
* Newsletter Functions
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* @deprecated 1.7.0 Here to prevent PUM_Newsletter_ classes from being loaded anywhere except from core.
*
* @param $class
*/
function pum_newsletter_autoloader( $class ) {}
/**
* @param $provider_id
*
* @return bool|PUM_Newsletter_Provider
*/
function pum_get_newsletter_provider( $provider_id ) {
$providers = PUM_Newsletter_Providers::instance()->get_providers();
return isset( $providers[ $provider_id ] ) ? $providers[ $provider_id ] : false;
}
/**
* @param string $provider_id
* @param string $context
* @param array $values
*
* @return mixed|string
*/
function pum_get_newsletter_provider_message( $provider_id, $context, $values = [] ) {
$provider = pum_get_newsletter_provider( $provider_id );
$default = pum_get_newsletter_default_messages( $context );
if ( ! $provider ) {
return $default;
}
$message = $provider->get_message( $context, $values );
return ! empty( $message ) ? $message : $default;
}
/**
* Gets default messages.
*
* @param null $context
*
* @return array|mixed|string
*/
function pum_get_newsletter_default_messages( $context = null ) {
$messages = [
'success' => pum_get_option( 'default_success_message', __( 'You have been subscribed!', 'popup-maker' ) ),
'double_opt_in_success' => pum_get_option( 'default_double_opt_in_success_message', __( 'Please check your email and confirm your subscription.', 'popup-maker' ) ),
'error' => pum_get_option( 'default_error_message', __( 'Error occurred when subscribing. Please try again.', 'popup-maker' ) ),
'already_subscribed' => pum_get_option( 'default_already_subscribed_message', __( 'You are already a subscriber.', 'popup-maker' ) ),
'empty_email' => pum_get_option( 'default_empty_email_message', __( 'Please enter a valid email.', 'popup-maker' ) ),
'invalid_email' => pum_get_option( 'default_invalid_email_message', __( 'Email provided is not a valid email address.', 'popup-maker' ) ),
'consent_required' => pum_get_option( 'default_consent_required_message', __( 'Email provided is not a valid email address.', 'popup-maker' ) ),
];
if ( $context ) {
return isset( $messages[ $context ] ) ? $messages[ $context ] : '';
}
return $messages;
}
/**
* @return array
*/
function pum_get_newsletter_admin_localized_vars() {
return [
'default_provider' => pum_get_option( 'newsletter_default_provider', pum_get_option( 'newsletter_default', '' ) ),
];
}

View File

@@ -0,0 +1,65 @@
<?php
/**
* Functions for Popup Conditionals
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Checks if the $popup is valid.
*
* @param mixed|PUM_Model_Popup $popup
*
* @return bool
*/
function pum_is_popup( $popup ) {
return pum_is_popup_object( $popup ) && $popup->is_valid();
}
/**
* Tests a given value to see if its a valid Popup model.
*
* @param PUM_Model_Popup|mixed $popup
*
* @return bool
*/
function pum_is_popup_object( $popup ) {
return is_a( $popup, 'PUM_Model_Popup' );
}
/**
* @param int $popup_id
*
* @return bool
*/
function pum_is_popup_loadable( $popup_id = null ) {
$popup = pum_get_popup( $popup_id );
if ( ! pum_is_popup_object( $popup ) ) {
return false;
}
return $popup->is_loadable();
}
/**
* Returns true if the close button should be shown.
*
* @param null|int $popup_id
*
* @return bool
*/
function pum_show_close_button( $popup_id = null ) {
$popup = pum_get_popup( $popup_id );
if ( ! pum_is_popup( $popup ) ) {
return true;
}
return $popup->show_close_button();
}

View File

@@ -0,0 +1,120 @@
<?php
/**
* Functions for Deprecated Popups
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
/**
* Returns a popup object.
*
* @deprecated 1.7
*
* @param null $popup_id
*
* @return false|PUM_Model_Popup
*/
function pum_popup( $popup_id = null ) {
return pum_get_popup( $popup_id );
}
/**
* Returns the meta group of a popup or value if key is set.
*
* @since 1.3.0
* @deprecated 1.4
*
* @param $group
* @param int $popup_id ID number of the popup to retrieve a overlay meta for
* @param null $key
* @param null $default
*
* @return mixed array|string
*/
function popmake_get_popup_meta( $group, $popup_id = null, $key = null, $default = null ) {
if ( ! $popup_id ) {
$popup_id = pum_get_popup_id();
}
$values = get_post_meta( $popup_id, "popup_{$group}", true );
if ( ! $values ) {
$defaults = apply_filters( "popmake_popup_{$group}_defaults", [] );
$values = array_merge( $defaults, popmake_get_popup_meta_group( $group, $popup_id ) );
} else {
$values = array_merge( popmake_get_popup_meta_group( $group, $popup_id ), $values );
}
if ( $key ) {
// Check for dot notation key value.
$test = uniqid();
$value = popmake_resolve( $values, $key, $test );
if ( $value === $test ) {
$key = str_replace( '.', '_', $key );
if ( ! isset( $values[ $key ] ) ) {
$value = $default;
} else {
$value = $values[ $key ];
}
}
return apply_filters( "popmake_get_popup_{$group}_$key", $value, $popup_id );
} else {
return apply_filters( "popmake_get_popup_{$group}", $values, $popup_id );
}
}
/**
* Returns the meta group of a popup or value if key is set.
*
* @since 1.0
* @deprecated 1.3.0
*
* @param int $popup_id ID number of the popup to retrieve a overlay meta for
*
* @return mixed array|string
*/
function popmake_get_popup_meta_group( $group, $popup_id = null, $key = null, $default = null ) {
if ( ! $popup_id || 'secure_logout' === $group ) {
$popup_id = pum_get_popup_id();
}
$post_meta = get_post_custom( $popup_id );
if ( ! is_array( $post_meta ) ) {
$post_meta = [];
}
$default_check_key = 'popup_defaults_set';
if ( ! in_array( $group, [ 'auto_open', '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_{$group}_defaults", [] );
foreach ( $post_meta as $meta_key => $value ) {
if ( strpos( $meta_key, "popup_{$group}_" ) !== false ) {
$new_key = str_replace( "popup_{$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_{$group}_$key", $value, $popup_id );
} else {
return apply_filters( "popmake_get_popup_{$group}", $group_values, $popup_id );
}
}

View File

@@ -0,0 +1,59 @@
<?php
/**
* Functions for Popup Getters
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Return the popup id.
*
* @param int $popup_id
*
* @return int
*/
function pum_get_popup_id( $popup_id = null ) {
if ( ( is_null( $popup_id ) || 0 === $popup_id ) && pum_is_popup( pum()->current_popup ) ) {
$_popup_id = pum()->current_popup->ID;
} else {
$_popup_id = ! empty( $popup_id ) && is_numeric( $popup_id ) ? $popup_id : 0;
}
return (int) apply_filters( 'pum_get_popup_id', (int) $_popup_id, $popup_id );
}
/**
* @param int $popup_id
*
* @return string
*/
function pum_get_popup_title( $popup_id = null ) {
$popup = pum_get_popup( $popup_id );
if ( ! pum_is_popup_object( $popup ) ) {
return '';
}
return $popup->get_title();
}
/**
* @param int $popup_id
*
* @return array
* @deprecated 1.8.0
*/
function pum_get_popup_triggers( $popup_id = null ) {
$popup = pum_get_popup( $popup_id );
if ( ! pum_is_popup_object( $popup ) ) {
return [];
}
return $popup->get_triggers();
}

View File

@@ -0,0 +1,272 @@
<?php
/**
* Functions for Popup 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_popup_upgrades_enabled() {
/** @var int $popup_count */
static $popup_count;
if ( defined( 'PUM_DISABLE_PASSIVE_UPGRADES' ) && PUM_DISABLE_PASSIVE_UPGRADES ) {
return false;
}
if ( ! $popup_count ) {
$popup_count = get_transient( 'pum_popup_count' );
if ( false === $popup_count ) {
$popup_count = pum_count_popups(
[
'post_status' => [ 'publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit', 'trash' ],
]
);
set_transient( 'pum_popup_count', $popup_count, HOUR_IN_SECONDS * 24 );
}
}
return $popup_count > apply_filters( 'pum_passive_popups_enabled_max_count', 5 );
}
/**
* Upgrade popup data to model v3.
*
* @since 1.7.0
*
* @param $popup PUM_Model_Popup
*/
function pum_popup_migration_2( &$popup ) {
$changed = false;
$delete_meta = [];
/**
* Update pum_sub_form shortcode args
*/
if ( has_shortcode( $popup->post_content, 'pum_sub_form' ) ) {
$new_content = preg_replace( '/\[pum_sub_form(.*)provider="none"(.*)\]/', '[pum_sub_form$1 provider=""$2]', $popup->post_content );
if ( $popup->post_content !== $new_content ) {
$popup->post_content = $new_content;
$changed = true;
$popup->save( false );
}
}
$settings = $popup->get_settings();
/**
* Migrate popup theme selection.
*/
$theme = $popup->get_meta( 'popup_theme' );
if ( ! empty( $theme ) && is_numeric( $theme ) ) {
$settings['theme_id'] = absint( $theme );
$changed = true;
$delete_meta[] = 'popup_theme';
}
/**
* Migrate popup_display meta data.
*/
$display = $popup->get_meta( 'popup_display' );
if ( ! empty( $display ) && is_array( $display ) ) {
$keys = $popup->remapped_meta_settings_keys( 'display' );
// Foreach old key, save the value under popup settings for the new key.
foreach ( $keys as $old_key => $new_key ) {
if ( isset( $display[ $old_key ] ) && ! empty( $display[ $old_key ] ) ) {
$settings[ $new_key ] = $display[ $old_key ];
$changed = true;
unset( $display[ $old_key ] );
if ( in_array(
$old_key,
[
'responsive_min_width',
'responsive_max_width',
'custom_width',
'custom_height',
]
) && isset( $display[ $old_key . '_unit' ] ) ) {
$settings[ $new_key ] .= $display[ $old_key . '_unit' ];
unset( $display[ $old_key . '_unit' ] );
}
}
}
if ( empty( $display ) ) {
$delete_meta[] = 'popup_display';
} else {
// Update the saved popup display data with any remaining keys from extensions.
$popup->update_meta( 'popup_display', $display );
}
}
/**
* Migrate popup_close meta data
*/
$close = $popup->get_meta( 'popup_close' );
if ( ! empty( $close ) && is_array( $close ) ) {
$keys = $popup->remapped_meta_settings_keys( 'close' );
// Foreach old key, save the value under popup settings for the new key.
foreach ( $keys as $old_key => $new_key ) {
if ( isset( $close[ $old_key ] ) ) {
$settings[ $new_key ] = $close[ $old_key ];
$changed = true;
unset( $close[ $old_key ] );
}
}
if ( empty( $close ) ) {
$delete_meta[] = 'popup_close';
} else {
// Update the saved popup close data with any remaining keys from extensions.
$popup->update_meta( 'popup_close', $close );
}
}
/**
* Migrate triggers.
*/
$triggers = $popup->get_meta( 'popup_triggers' );
if ( ! empty( $triggers ) && is_array( $triggers ) ) {
$triggers = ! empty( $settings['triggers'] ) && is_array( $settings['triggers'] ) ? array_merge( $settings['triggers'], $triggers ) : $triggers;
foreach ( $triggers as $key => $trigger ) {
if ( isset( $trigger['settings']['cookie']['name'] ) ) {
$triggers[ $key ]['settings']['cookie_name'] = $trigger['settings']['cookie']['name'];
unset( $triggers[ $key ]['settings']['cookie'] );
}
}
$settings['triggers'] = $triggers;
$changed = true;
$delete_meta[] = 'popup_triggers';
}
/**
* Migrate cookies.
*/
$cookies = $popup->get_meta( 'popup_cookies' );
if ( ! empty( $cookies ) && is_array( $cookies ) ) {
$cookies = ! empty( $settings['cookies'] ) && is_array( $settings['cookies'] ) ? array_merge( $settings['cookies'], $cookies ) : $cookies;
$settings['cookies'] = $cookies;
$changed = true;
$delete_meta[] = 'popup_cookies';
}
/**
* Migrate conditions.
*/
$conditions = $popup->get_meta( 'popup_conditions' );
if ( ! empty( $conditions ) && is_array( $conditions ) ) {
$conditions = ! empty( $settings['conditions'] ) && is_array( $settings['conditions'] ) ? array_merge( $settings['conditions'], $conditions ) : $conditions;
foreach ( $conditions as $cg_key => $group ) {
if ( ! empty( $group ) ) {
foreach ( $group as $c_key => $condition ) {
// Clean empty conditions.
if ( ! empty( $condition['target'] ) ) {
$fixed_condition = [
'target' => $condition['target'],
'not_operand' => isset( $condition['not_operand'] ) ? (bool) $condition['not_operand'] : false,
'settings' => isset( $condition['settings'] ) ? $condition['settings'] : [],
];
foreach ( $condition as $key => $val ) {
if ( ! in_array( $key, [ 'target', 'not_operand', 'settings' ] ) ) {
$fixed_condition['settings'][ $key ] = $val;
}
}
$conditions[ $cg_key ][ $c_key ] = $fixed_condition;
} else {
unset( $conditions[ $cg_key ][ $c_key ] );
}
}
// Clean empty groups.
if ( empty( $conditions[ $cg_key ] ) ) {
unset( $conditions[ $cg_key ] );
}
}
}
$settings['conditions'] = $conditions;
$changed = true;
$delete_meta[] = 'popup_conditions';
}
/**
* Migrate popup_mobile_disabled.
*/
$mobile_disabled = $popup->get_meta( 'popup_mobile_disabled' );
if ( ! empty( $mobile_disabled ) ) {
$settings['disable_on_mobile'] = (bool) ( $mobile_disabled );
$changed = true;
$delete_meta[] = 'popup_mobile_disabled';
}
/**
* Migrate popup_tablet_disabled.
*/
$tablet_disabled = $popup->get_meta( 'popup_tablet_disabled' );
if ( ! empty( $tablet_disabled ) ) {
$settings['disable_on_tablet'] = (bool) ( $tablet_disabled );
$changed = true;
$delete_meta[] = 'popup_tablet_disabled';
}
/**
* Migrate analytics reset keys.
*/
$open_count_reset = $popup->get_meta( 'popup_open_count_reset', false );
if ( ! empty( $open_count_reset ) && is_array( $open_count_reset ) ) {
foreach ( $open_count_reset as $key => $reset ) {
if ( is_array( $reset ) ) {
add_post_meta(
$popup->ID,
'popup_count_reset',
[
'timestamp' => ! empty( $reset['timestamp'] ) ? $reset['timestamp'] : '',
'opens' => ! empty( $reset['count'] ) ? absint( $reset['count'] ) : 0,
'conversions' => 0,
]
);
}
}
$delete_meta[] = 'popup_open_count_reset';
}
/**
* Save only if something changed.
*/
if ( $changed ) {
$popup->update_meta( 'popup_settings', $settings );
}
/**
* Clean up automatically.
*/
if ( ! empty( $delete_meta ) ) {
foreach ( $delete_meta as $key ) {
$popup->delete_meta( $key );
}
}
}
add_action( 'pum_popup_passive_migration_2', 'pum_popup_migration_2' );

View File

@@ -0,0 +1,76 @@
<?php
/**
* Functions for Popup Queries
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Get a popup model instance.
*
* @param int $popup_id
*
* @return PUM_Model_Popup
*/
function pum_get_popup( $popup_id = null ) {
if ( ( is_null( $popup_id ) || 0 === $popup_id ) && pum_is_popup( pum()->current_popup ) ) {
return pum()->current_popup;
}
/** @var int $popup_id filtered $popup_id */
$popup_id = pum_get_popup_id( $popup_id );
try {
return pum()->popups->get_item( $popup_id );
} catch ( InvalidArgumentException $e ) {
// Return empty object
return new PUM_Model_Popup( $popup_id );
}
}
/**
* Queries popups and returns them in a specific format.
*
* @param array $args
*
* @return PUM_Model_Popup[]
*/
function pum_get_popups( $args = [] ) {
return pum()->popups->get_items( $args );
}
/**
* Queries popups and returns them in a specific format.
*
* @param array $args
*
* @return PUM_Model_Popup[]
*/
function pum_get_all_popups( $args = [] ) {
$args['posts_per_page'] = -1;
return pum_get_popups( $args );
}
/**
* Gets a count popups with specified args.
*
* @param array $args
*
* @return int
*/
function pum_count_popups( $args = [] ) {
$args = wp_parse_args(
$args,
[
'post_status' => 'publish',
]
);
return pum()->popups->count_items( $args );
}

View File

@@ -0,0 +1,116 @@
<?php
/**
* Functions for Popups Template
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Render the popup ID
*
* @param null|int|string $popup_id Popup ID.
*/
function pum_popup_ID( $popup_id = null ) {
echo pum_get_popup_id( $popup_id );
}
/**
* Render the popup title.
*
* @param null|int $popup_id Popup ID.
*/
function pum_popup_title( $popup_id = null ) {
echo esc_html( pum_get_popup_title( $popup_id ) );
}
/**
* Render the popup content.
*
* @param null|int $popup_id Popup ID.
*/
function pum_popup_content( $popup_id = null ) {
$popup = pum_get_popup( $popup_id );
if ( ! pum_is_popup( $popup ) ) {
return;
}
$cached_content = PUM_Site_Popups::get_cache_content( $popup->ID );
echo false !== $cached_content ? $cached_content : $popup->get_content();
}
/**
* Render the chose popup elements classes.
*
* @param null $popup_id Popup ID.
* @param string $element Element to get classes for.
*/
function pum_popup_classes( $popup_id = null, $element = 'overlay' ) {
$popup = pum_get_popup( $popup_id );
if ( ! pum_is_popup( $popup ) ) {
return;
}
echo esc_attr( implode( ' ', $popup->get_classes( $element ) ) );
}
/**
* Render the popups data attribute.
*
* @param null|int $popup_id Popup ID.
*/
function pum_popup_data_attr( $popup_id = null ) {
$popup = pum_get_popup( $popup_id );
if ( ! pum_is_popup( $popup ) ) {
return;
}
echo 'data-popmake="' . esc_attr( wp_json_encode( $popup->get_data_attr() ) ) . '"';
}
/**
* Render the popup's content tabindex attribute to make focusable
* if needed.
*
* @param null|int $popup_id Popup ID.
*/
function pum_popup_content_tabindex_attr( $popup_id = null ) {
$popup = pum_get_popup( $popup_id );
if ( ! pum_is_popup( $popup ) ) {
return;
}
// Greater or equal to 0 makes it focusable.
echo 'tabindex="0"';
}
/**
* Render the popup close button text.
*
* @param null|int $popup_id Popup ID.
*/
function pum_popup_close_text( $popup_id = null ) {
$popup = pum_get_popup( $popup_id );
if ( ! pum_is_popup( $popup ) ) {
return;
}
$close_text = $popup->close_text();
// If the close text is a font awesome icon (E.g. "fas fa-camera"), add the icon instead of the text.
if ( preg_match( '/^fa[srldb]?\s.+/i', $close_text ) || preg_match( '/^fa-((solid)|(regular)|(light)|(thin)|(duotone))?\sfa[-]?.+/i', $close_text ) ) {
echo '<i class="' . esc_attr( $close_text ) . '"></i>';
} else {
echo esc_html( $close_text );
}
}

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;
}

View File

@@ -0,0 +1,130 @@
<?php
/**
* Functions for Cache Utility
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Add a cache key via PUM Cache.
*
* @param $key
* @param $data
* @param string $group
*
* @return bool
*/
function pum_cache_add( $key, $data, $group = '' ) {
return PUM_Utils_Cache::add( $key, $data, $group );
}
/**
* Set a cache key via PUM Cache.
*
* @param $key
* @param $data
* @param string $group
*
* @return bool
*/
function pum_cache_set( $key, $data, $group = '' ) {
return PUM_Utils_Cache::set( $key, $data, $group );
}
/**
* Replace a cache key via PUM Cache.
*
* @param $key
* @param $data
* @param string $group
*
* @return bool
*/
function pum_cache_replace( $key, $data, $group = '' ) {
return PUM_Utils_Cache::replace( $key, $data, $group );
}
/**
* Get a cache key via PUM Cache.
*
* @param $key
* @param string $group
* @param bool $force
* @param null $found
*
* @return bool|mixed
*/
function pum_cache_get( $key, $group = '', $force = false, &$found = null ) {
return PUM_Utils_Cache::get( $key, $group, $force, $found );
}
/**
* Delete a cache key via PUM Cache.
*
* @param $key
* @param string $group
*
* @return bool
*/
function pum_cache_delete( $key, $group = '' ) {
return PUM_Utils_Cache::delete( $key, $group );
}
/**
* Delete a cache group via PUM Cache.
*
* @param string $group
*
* @return bool
*/
function pum_cache_delete_group( $group = '' ) {
return PUM_Utils_Cache::delete_group( $group );
}
/**
* Increase a numeric cache value by the offset.
*
* @param $key
* @param int $offset
* @param string $group
*
* @return bool|false|int
*/
function pum_cache_incr( $key, $offset = 1, $group = '' ) {
return PUM_Utils_Cache::incr( $key, $offset, $group );
}
/**
* Decrease a numeric cache value by the offset.
*
* @param $key
* @param int $offset
* @param string $group
*
* @return bool|false|int
*/
function pum_cache_decr( $key, $offset = 1, $group = '' ) {
return PUM_Utils_Cache::decr( $key, $offset, $group );
}
/**
* Gets the filterable timeout for a cache object by key.
*
* @param $key
*
* @return int
*/
function pum_cache_timeout( $key ) {
static $timeouts;
if ( ! isset( $timeouts ) ) {
$timeouts = apply_filters( 'pum_cache_timeouts', [] );
}
return isset( $timeouts[ $key ] ) ? $timeouts[ $key ] : 0;
}

View File

@@ -0,0 +1,52 @@
<?php
/**
* Functions for Format Utility
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* @param int $time
* @param int|null $current
*
* @return mixed
*/
function pum_human_time( $time, $current = null ) {
return PUM_Utils_Format::human_time( $time, $current );
}
/**
* @param int|float $number
* @param string $format
*
* @return int|string
*/
function pum_format_number( $number, $format = '' ) {
return PUM_Utils_Format::number( $number, $format );
}
/**
* @param int|float $number
* @param string $format U|human|human-readable
*
* @return int|string
*/
function pum_format_time( $number, $format = '' ) {
return PUM_Utils_Format::time( $number, $format );
}
/**
* Removes <p></p> around URLs
*
* @param string $content
*
* @return string
*/
function pum_unwrap_urls( $content = '' ) {
return PUM_Utils_Format::unwrap_urls( $content );
}

View File

@@ -0,0 +1,88 @@
<?php
/**
* Functions for Options Utility
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Get all forum options.
*
* @return mixed
*/
function pum_get_options() {
return PUM_Utils_Options::get_all();
}
/**
* Get a forum option.
*
* @param string $key
* @param mixed $default
*
* @return mixed
*/
function pum_get_option( $key, $default = false ) {
return PUM_Utils_Options::get( $key, $default );
}
/**
* Update a forum option.
*
* @param string $key
* @param bool $value
*
* @return bool
*/
function pum_update_option( $key = '', $value = false ) {
return PUM_Utils_Options::update( $key, $value );
}
/**
* Merge array of new option values into the existing options array.
*
* @param array $new_options
*
* @return bool
*/
function pum_merge_options( $new_options = [] ) {
return PUM_Utils_Options::merge( $new_options );
}
/**
* Delete a forum option
*
* @param string $key
*
* @return bool
*/
function pum_delete_option( $key = '' ) {
return PUM_Utils_Options::delete( $key );
}
/**
* Delete a forum option
*
* @param array $keys
*
* @return bool
*/
function pum_delete_options( $keys = [] ) {
return PUM_Utils_Options::delete( $keys );
}
/**
* Remap old option keys.
*
* @param array $remap_array
*
* @return bool
*/
function pum_remap_options( $remap_array = [] ) {
return PUM_Utils_Options::remap_keys( $remap_array );
}

View File

@@ -0,0 +1,64 @@
<?php
/**
* Functions for Template Utility
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Get a templates part in $slug-$name.php fashion.
*
* Allows passing arguments that will be globally accessible in the templates.
*
* @param string $slug
* @param string $name
* @param array $args
*
* @return string
*/
function pum_get_template_part( $slug, $name = null, $args = null ) {
return PUM_Utils_Template::get_part( $slug, $name, $args );
}
/**
* Render a templates part in $slug-$name.php fashion.
*
* Allows passing arguments that will be globally accessible in the templates.
*
* @param string $slug
* @param string $name
* @param array $args
*/
function pum_template_part( $slug, $name = null, $args = [] ) {
echo pum_get_template_part( $slug, $name, $args );
}
/**
* Gets the rendered contents of the specified templates file.
*
* @param $template_name
* @param array $args
*
* @return string
*/
function pum_get_template( $template_name, $args = [] ) {
return PUM_Utils_Template::get( $template_name, $args );
}
/**
* Get other templates (e.g. product attributes) passing attributes and including the file.
*
* @deprecated Likely a better way @see pum_template_part()
*
* @param string $template_name Template file name with extension: file-name.php
* @param array $args (default: array())
*/
function pum_load_template( $template_name, $args = [] ) {
echo pum_get_template( $template_name, $args );
}

View File

@@ -0,0 +1,75 @@
<?php
/**
* Functions for Upgrades Utility
*
* @package PUM
* @copyright Copyright (c) 2023, Code Atlantic LLC
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Adds an upgrade action to the completed upgrades array
*
* @since 1.7.0
*
* @see PUM_Utils_Upgrades::set_upgrade_complete
*
* @param string $upgrade_id The action to add to the competed upgrades array
*
* @return bool If the function was successfully added
*/
function pum_set_upgrade_complete( $upgrade_id = '' ) {
return PUM_Utils_Upgrades::instance()->set_upgrade_complete( $upgrade_id );
}
/**
* Get's the array of completed upgrade actions
*
* @since 1.7.0
*
* @return array The array of completed upgrades
*/
function pum_get_completed_upgrades() {
return PUM_Utils_Upgrades::instance()->get_completed_upgrades();
}
/**
* Check if the upgrade routine has been run for a specific action
*
* @since 1.7.0
*
* @param string $upgrade_id The upgrade action to check completion for
*
* @return bool If the action has been added to the completed actions array
*/
function pum_has_completed_upgrade( $upgrade_id = '' ) {
return PUM_Utils_Upgrades::instance()->has_completed_upgrade( $upgrade_id );
}
/**
* Clean up postmeta by removing all keys from the given post_id.
*
* @param int $post_id
* @param array $keys_to_delete
*/
function pum_cleanup_post_meta_keys( $post_id = 0, $keys_to_delete = [] ) {
/**
* Clean up automatically.
*/
if ( ! empty( $keys_to_delete ) ) {
global $wpdb;
$keys_to_delete = array_map( 'esc_sql', (array) $keys_to_delete );
$meta_keys = implode( "','", $keys_to_delete );
$query = $wpdb->prepare( "DELETE FROM `$wpdb->postmeta` WHERE `post_id` = %d AND `meta_key` IN ('{$meta_keys}')", $post_id );
$wpdb->query( $query );
wp_cache_delete( $post_id, 'post_meta' );
}
}