: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Class for Admin Settings
* @copyright Copyright (c) 2023, Code Atlantic LLC
if ( ! defined( 'ABSPATH' ) ) {
* Class PUM_Admin_Settings
class PUM_Admin_Settings {
public static $notices = [];
public static function init() {
add_action( 'admin_notices', [ __CLASS__, 'notices' ] );
add_action( 'admin_init', [ __CLASS__, 'save' ] );
// add_action( 'pum_license_deactivated', array( __CLASS__, 'license_deactivated' ) );
// add_action( 'pum_license_check_failed', array( __CLASS__, 'license_deactivated' ) );
// display default admin notice
* Displays any saved admin notices.
public static function notices() {
if ( isset( $_GET['success'] ) && get_option( 'pum_settings_admin_notice' ) ) {
'type' => $_GET['success'] ? 'success' : 'error',
'message' => get_option( 'pum_settings_admin_notice' ),
delete_option( 'pum_settings_admin_notice' );
if ( ! empty( self::$notices ) ) {
foreach ( self::$notices as $notice ) { ?>
<div class="notice notice-<?php echo esc_attr( $notice['type'] ); ?> is-dismissible">
<p><strong><?php esc_html_e( $notice['message'] ); ?></strong></p>
<button type="button" class="notice-dismiss">
<span class="screen-reader-text"><?php _e( 'Dismiss this notice.', 'popup-maker' ); ?></span>
* Save settings when needed.
public static function save() {
if ( ! empty( $_POST['pum_settings'] ) && empty( $_POST['pum_license_activate'] ) && empty( $_POST['pum_license_deactivate'] ) ) {
if ( ! isset( $_POST['pum_settings_nonce'] ) || ! wp_verify_nonce( $_POST['pum_settings_nonce'], basename( __FILE__ ) ) ) {
if ( ! current_user_can( 'manage_options' ) ) {
$settings = self::sanitize_settings( $_POST['pum_settings'] );
$settings = apply_filters( 'pum_sanitize_settings', $settings );
if ( PUM_Utils_Options::update_all( $settings ) ) {
'message' => __( 'Settings saved successfully!', 'popup-maker' ),
do_action( 'pum_save_settings', $settings );
* Process licensing if set.
* // We store the key in wp_options for use by the update & licensing system to keep things cleanly detached.
* $old_license = get_option( 'pum_license_key' );
* if ( empty( $settings['pum_license_key'] ) ) {
* delete_option( 'pum_license_key' ); // empty key, remove existing license info.
* delete_option( 'pum_license' ); // empty key, remove existing license info.
* } else if ( $old_license != $settings['pum_license_key'] ) {
* update_option( 'pum_license_key', $settings['pum_license_key'] );
* delete_option( 'pum_license' ); // new license has been entered, so must reactivate
* // Prevent additional calls to licensing.
* if ( empty( $_POST['pum_license_activate'] ) ) {
* $message = PUM_Licensing::activate();
* if ( $message !== true && ! empty ( $message ) ) {
* self::$notices[] = array(
* self::$notices[] = array(
* 'message' => __( 'License activated successfully!', 'popup-maker' ),
public static function sanitize_settings( $settings = [] ) {
$fields = self::fields();
$fields = PUM_Admin_Helpers::flatten_fields_array( $fields );
foreach ( $fields as $field_id => $field ) {
switch ( $field['type'] ) {
if ( ! isset( $settings[ $field_id ] ) ) {
$settings[ $field_id ] = false;
foreach ( $settings as $key => $value ) {
$field = self::get_field( $key );
// Sanitize every string value.
if ( is_string( $value ) ) {
$settings[ $key ] = sanitize_text_field( $value );
switch ( $field['type'] ) {
$settings[ $key ] = is_string( $value ) ? trim( $value ) : $value;
$settings[ $key ] .= $settings[ $key . '_unit' ];
$old = PUM_Utils_Options::get( $key );
if ( $old && $old !== $new ) {
delete_option( str_replace( '_license_key', '_license_active', $key ) );
call_user_func( $field['options']['activation_callback'] );
$settings[ $key ] = is_string( $value ) ? trim( $value ) : $value;
// Activate / deactivate license keys maybe?
// Some custom field types include multiple additional fields that do not need to be saved, strip out any non-whitelisted fields.
unset( $settings[ $key ] );
public static function get_field( $id ) {
foreach ( $tabs as $tab => $sections ) {
if ( PUM_Admin_Helpers::is_field( $sections ) ) {
foreach ( $sections as $section => $fields ) {
foreach ( $fields as $key => $args ) {
* Returns array of pum settings fields.
public static function fields() {
if ( ! isset( $fields ) ) {
'label' => __( 'Default Popup Theme', 'popup-maker' ),
'dynamic_desc' => sprintf( '%1$s<br/><a id="edit_theme_link" href="%3$s">%2$s</a>', __( 'Choose the default theme used for new popups', 'popup-maker' ), __( 'Customize This Theme', 'popup-maker' ), admin_url( 'post.php?action=edit&post={{data.value}}' ) ),
'options' => pum_is_settings_page() ? PUM_Helpers::popup_theme_selectlist() : null,
'std' => pum_get_default_theme_id(),
'gutenberg_support_enabled' => [
'label' => __( 'Enable Block Editor Support', 'popup-maker' ),
'desc' => __( 'Enable experimental support for using the block editor to edit popups.', 'popup-maker' ),
'google_fonts_api_key' => [
'label' => __( 'Google Fonts API Key *optional', 'popup-maker' ),
'desc' => __( 'Enter your own Google Fonts API key to always get the latest fonts available.', 'popup-maker' ),
'label' => __( 'Allow usage tracking?', 'popup-maker' ),
/* translators: 1 & 2 are opening and closing HTML of the link around "Learn more" */
esc_html__( 'Allow data sharing so that we can receive a little information on how it is used and help us make this plugin better? No user data is sent to our servers. No sensitive data is tracked. %1$sLearn more%2$s', 'popup-maker' ),
' <a target="_blank" rel="noreferrer noopener" href="https://docs.wppopupmaker.com/article/528-the-data-the-popup-maker-plugin-collects?utm_campaign=contextual-help&utm_medium=inline-doclink&utm_source=settings-page&utm_content=telemetry-setting">',
// TODO Remove or move externally of this location later.
if ( ! ( class_exists( 'PUM_MCI' ) && version_compare( PUM_MCI::$VER, '1.3.0', '<' ) ) ) {
$fields['subscriptions'] = [
'pum_newsletter_settings',
'newsletter_default_provider' => [
'label' => __( 'Default Newsletter Provider', 'popup-maker' ),
'desc' => __( 'The default mailing provider used for the subscription form.', 'popup-maker' ),
'options' => array_merge(
PUM_Newsletter_Providers::dropdown_list(),
'none' => __( 'None', 'popup-maker' ),
'default_success_message' => [
'label' => __( 'Success Message', 'popup-maker' ),
'desc' => __( 'Message to show user when successfuly subscribed.', 'popup-maker' ),
'std' => __( 'You have been subscribed!', 'popup-maker' ),
'default_empty_email_message' => [
'label' => __( 'Empty Email Message', 'popup-maker' ),
'desc' => __( 'Message to show user when no email is entered.', 'popup-maker' ),
'std' => __( 'Please enter a valid email.', 'popup-maker' ),
'default_invalid_email_message' => [
'label' => __( 'Invalid Email Message', 'popup-maker' ),
'desc' => __( 'Message to show user when an invalid email is entered.', 'popup-maker' ),
'std' => __( 'Email provided is not a valid email address.', 'popup-maker' ),
'default_error_message' => [
'label' => __( 'Error Message', 'popup-maker' ),
'desc' => __( 'Message to show user when an error has occurred.', 'popup-maker' ),
'std' => __( 'Error occurred when subscribing. Please try again.', 'popup-maker' ),
'default_already_subscribed_message' => [
'label' => __( 'Already Subscribed Message', 'popup-maker' ),
'desc' => __( 'Message to show user who is already subscribed.', 'popup-maker' ),
'std' => __( 'You are already a subscriber.', 'popup-maker' ),
'default_consent_required_message' => [
'label' => __( 'Consent Required Message', 'popup-maker' ),
'desc' => __( 'Message to show user who is already subscribed.', 'popup-maker' ),
'std' => __( 'You must agree to continue.', 'popup-maker' ),
'disable_popup_open_tracking' => [
'label' => __( 'Disables popup open tracking?', 'popup-maker' ),
'desc' => __( 'This will disable the built in analytics functionality.', 'popup-maker' ),
'content' => '<strong>' . __( 'Disclaimer', 'popup-maker' ) . ':</strong> ' . __( 'These settings only pertain to usage of the Popup Maker built in subscription form shortcode, not 3rd party form plugins.', 'popup-maker' ),
'privacy_consent_always_enabled' => [
'label' => __( 'Always enable consent field on subscription forms.', 'popup-maker' ),
'yes' => __( 'Yes', 'popup-maker' ),
'no' => __( 'No', 'popup-maker' ),
'default_privacy_consent_label' => [
'label' => __( 'Consent Text', 'popup-maker' ),
'std' => __( 'Notify me about related content and special offers.', 'popup-maker' ),
'privacy_consent_always_enabled' => 'yes',
'default_privacy_consent_type' => [
'label' => __( 'Consent Field Type', 'popup-maker' ),
'desc' => __( 'Radio forces the user to make a choice, often resulting in more opt-ins.', 'popup-maker' ),
'radio' => __( 'Radio', 'popup-maker' ),
'checkbox' => __( 'Checkbox', 'popup-maker' ),
'privacy_consent_always_enabled' => 'yes',
'default_privacy_consent_required' => [
'label' => __( 'Consent Required', 'popup-maker' ),
'std' => pum_get_option( 'default_privacy_consent_required' ),
'privacy_consent_always_enabled' => 'yes',
'default_privacy_consent_radio_layout' => [
'label' => __( 'Consent Radio Layout', 'popup-maker' ),
'inline' => __( 'Inline', 'popup-maker' ),
'stacked' => __( 'Stacked', 'popup-maker' ),
'std' => __( 'Yes', 'popup-maker' ),
'privacy_consent_always_enabled' => 'yes',
'default_privacy_consent_type' => 'radio',
'default_privacy_consent_yes_label' => [
'label' => __( 'Consent Yes Label', 'popup-maker' ),
'std' => __( 'Yes', 'popup-maker' ),
'privacy_consent_always_enabled' => 'yes',
'default_privacy_consent_type' => 'radio',
'default_privacy_consent_no_label' => [
'label' => __( 'Consent No Label', 'popup-maker' ),
'std' => __( 'No', 'popup-maker' ),
'privacy_consent_always_enabled' => 'yes',
'default_privacy_consent_type' => 'radio',
'default_privacy_usage_text' => [
'label' => __( 'Consent Usage Text', 'popup-maker' ),
'desc' => function_exists( 'get_privacy_policy_url' ) ? sprintf( __( 'You can use %1$s%2$s to insert a link to your privacy policy. To customize the link text use %1$s:Link Text%2$s', 'popup-maker' ), '{{privacy_link', '}}' ) : '',
'std' => __( 'If you opt in above we use this information send related content, discounts and other special offers.', 'popup-maker' ),
'privacy_consent_always_enabled' => 'yes',
'label' => __( 'Try to bypass ad blockers.', 'popup-maker' ),
'adblock_bypass_url_method' => [
'label' => __( 'Ad blocker: Naming method', 'popup-maker' ),
'desc' => __( 'This will help generate unique names for our JavaScript files and the analytics routes.', 'popup-maker' ),
'random' => __( 'Randomize Names', 'popup-maker' ),
'custom' => __( 'Custom Names', 'popup-maker' ),
'bypass_adblockers' => true,
'adblock_bypass_custom_filename' => [
'placeholder' => 'my-awesome-popups',
'label' => __( 'Ad blocker: Custom Name', 'popup-maker' ),
'desc' => __( 'A custom & recognizable name to use for our assets.', 'popup-maker' ),
'bypass_adblockers' => true,
'adblock_bypass_url_method' => 'custom',
'adjust_body_padding' => [
'label' => __( 'Adjust the right padding added to the body when popups are shown with an overlay.', 'popup-maker' ),
/* translators: 1 & 2 are opening and closing HTML of the link around "Learn more" */
esc_html__( 'Use this if your popups "jump" or "shift" when opened. %1$sLearn more%2$s', 'popup-maker' ),
'<a target="_blank" rel="noreferrer noopener" href="https://docs.wppopupmaker.com/article/314-why-does-my-site-shift-jump-or-skip-when-a-popup-is-triggered?utm_campaign=contextual-help&utm_medium=inline-doclink&utm_source=settings-page&utm_content=adjust-right-padding">',
'body_padding_override' => [
'label' => __( 'Body Padding Override', 'popup-maker' ),
'adjust_body_padding' => true,
'disabled_admin_bar' => [
'label' => __( 'Disable Popups Admin Bar', 'popup-maker' ),
'desc' => __( 'This will disable the admin Popups menu item.', 'popup-maker' ),
'label' => __( 'Enable Debug Mode', 'popup-maker' ),
'desc' => __( 'This will turn on multiple debug tools used to quickly find issues.', 'popup-maker' ),
'enable_easy_modal_compatibility_mode' => [
'label' => __( 'Enable Easy Modal v2 Compatibility Mode', 'popup-maker' ),
'desc' => __( 'This will automatically make any eModal classes you have added to your site launch the appropriate Popup after import.', 'popup-maker' ),
'disable_popup_category_tag' => [
'label' => __( 'Disable categories & tags?', 'popup-maker' ),
'desc' => __( 'This will disable the popup tags & categories.', 'popup-maker' ),
'disable_asset_caching' => [
'label' => __( 'Disable asset caching.', 'popup-maker' ),
'desc' => __( 'By default Popup Maker caches a single JS & CSS file in your Uploads folder. These files include core, extension & user customized styles & scripts in a single set of files.', 'popup-maker' ),