: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* @copyright Copyright (c) 2023, Code Atlantic LLC
if ( ! defined( 'ABSPATH' ) ) {
* Class PUM_Shortcode_Popup
* Registers the popup_close shortcode.
class PUM_Shortcode_Popup extends PUM_Shortcode {
public $has_content = true;
public $inner_content_priority = 15;
public function label() {
return __( 'Popup', 'popup-maker' );
public function description() {
return __( 'Insert a popup inline rather. Great for simple popups used for supporting content.', 'popup-maker' );
public function inner_content_labels() {
'label' => __( 'Content', 'popup-maker' ),
'description' => __( 'Can contain other shortcodes, images, text or html content.', 'popup-maker' ),
public function post_types() {
'general' => __( 'General', 'popup-maker' ),
'display' => __( 'Display', 'popup-maker' ),
'position' => __( 'Position', 'popup-maker' ),
'animation' => __( 'Animation', 'popup-maker' ),
'close' => __( 'Close', 'popup-maker' ),
public function subtabs() {
'pum_sub_form_shortcode_subtabs',
'main' => __( 'General', 'popup-maker' ),
'main' => __( 'Display', 'popup-maker' ),
'main' => __( 'Position', 'popup-maker' ),
'main' => __( 'Animation', 'popup-maker' ),
'main' => __( 'Close', 'popup-maker' ),
public function fields() {
'label' => __( 'Unique Popup ID', 'popup-maker' ),
'placeholder' => __( '`offer`, `more-info`', 'popup-maker' ),
'desc' => __( 'Used in popup triggers to target this popup', 'popup-maker' ),
'label' => __( 'Popup Title', 'popup-maker' ),
'placeholder' => __( 'Enter popup title text,', 'popup-maker' ),
'desc' => __( 'This will be displayed above the content. Leave it empty to disable it.', 'popup-maker' ),
'label' => __( 'Popup Theme', 'popup-maker' ),
'placeholder' => __( 'Choose a theme,', 'popup-maker' ),
'desc' => __( 'Choose which popup theme will be used.', 'popup-maker' ),
'std' => pum_get_default_theme_id(),
'options' => pum_is_settings_page() ? PUM_Helpers::popup_theme_selectlist() : null,
'label' => __( 'Disable Overlay', 'popup-maker' ),
'description' => __( 'Checking this will disable and hide the overlay for this popup.', 'popup-maker' ),
'label' => __( 'Size', 'popup-maker' ),
'description' => __( 'Select the size of the popup.', 'popup-maker' ),
'options' => array_flip( apply_filters( 'popmake_popup_display_size_options', [] ) ),
'label' => __( 'Width', 'popup-maker' ),
'label' => __( 'Width Unit', 'popup-maker' ),
'options' => array_flip( apply_filters( 'popmake_size_unit_options', [] ) ),
'label' => __( 'Height', 'popup-maker' ),
'label' => __( 'Height Unit', 'popup-maker' ),
'options' => array_flip( apply_filters( 'popmake_size_unit_options', [] ) ),
'label' => __( 'Location', 'popup-maker' ),
'description' => __( 'Choose where the popup will be displayed.', 'popup-maker' ),
'options' => array_flip( apply_filters( 'popmake_popup_display_location_options', [] ) ),
'label' => __( 'Top', 'popup-maker' ),
'description' => sprintf( _x( 'Distance from the %s edge of the screen.', 'Screen Edge: top, bottom', 'popup-maker' ), strtolower( __( 'Top', 'popup-maker' ) ) ),
'label' => __( 'Bottom', 'popup-maker' ),
'description' => sprintf( _x( 'Distance from the %s edge of the screen.', 'Screen Edge: top, bottom', 'popup-maker' ), strtolower( __( 'Bottom', 'popup-maker' ) ) ),
'label' => __( 'Left', 'popup-maker' ),
'description' => sprintf( _x( 'Distance from the %s edge of the screen.', 'Screen Edge: top, bottom', 'popup-maker' ), strtolower( __( 'Left', 'popup-maker' ) ) ),
'label' => __( 'Right', 'popup-maker' ),
'description' => sprintf( _x( 'Distance from the %s edge of the screen.', 'Screen Edge: top, bottom', 'popup-maker' ), strtolower( __( 'Right', 'popup-maker' ) ) ),
'label' => __( 'Animation Type', 'popup-maker' ),
'description' => __( 'Select an animation type for your popup.', 'popup-maker' ),
'options' => array_flip( apply_filters( 'popmake_popup_display_animation_type_options', [] ) ),
'label' => __( 'Animation Speed', 'popup-maker' ),
'description' => __( 'Set the animation speed for the popup.', 'popup-maker' ),
'unit' => __( 'ms', 'popup-maker' ),
'label' => __( 'Animation Origin', 'popup-maker' ),
'description' => __( 'Choose where the animation will begin.', 'popup-maker' ),
'options' => array_flip( apply_filters( 'popmake_popup_display_animation_origin_options', [] ) ),
'label' => __( 'Click Overlay to Close', 'popup-maker' ),
'description' => __( 'Checking this will cause popup to close when user clicks on overlay.', 'popup-maker' ),
* @param array $atts shortcode attributes
* @param string $content shortcode content
public function handler( $atts, $content = null ) {
'pum_popup_shortcode_default_atts',
'location' => 'center top',
'animation_type' => 'fade',
'animation_speed' => 1000,
'animation_origin' => 'top',
// We need to fake a popup using the PUM_Popup data model.
$post_id = rand( - 99999, - 1 ); // negative ID, to avoid clash with a valid post
$post->post_date = current_time( 'mysql' );
$post->post_date_gmt = current_time( 'mysql', 1 );
$post->post_title = $atts['title'];
$post->post_content = $content;
$post->post_status = 'publish';
$post->comment_status = 'closed';
$post->ping_status = 'closed';
$post->post_name = $atts['id']; // append random number to avoid clash
$post->post_type = 'popup';
$post->filter = 'raw'; // important!
// Convert to WP_Post object
$wp_post = new WP_Post( $post );
// Add the fake post to the cache
wp_cache_add( $post_id, $wp_post, 'posts' );
$popup = new PUM_Model_Popup( $wp_post );
if ( ! $atts['theme_id'] ) {
$atts['theme_id'] = $atts['theme'] ? $atts['theme'] : pum_get_default_theme_id();
$popup->title = $atts['title'];
$popup->settings = array_merge(
PUM_Admin_Popups::defaults(),
'disable_analytics' => true,
'theme_id' => $atts['theme_id'],
'overlay_disabled' => $atts['overlay_disabled'],
'custom_width' => $atts['width'],
'custom_width_unit' => $atts['width_unit'],
'custom_height' => $atts['height'],
'custom_height_unit' => $atts['height_unit'],
'custom_height_auto' => $atts['width'] > 0 ? 0 : 1,
'location' => $atts['location'],
'position_top' => $atts['position_top'],
'position_left' => $atts['position_left'],
'position_bottom' => $atts['position_bottom'],
'position_right' => $atts['position_right'],
'position_fixed' => $atts['position_fixed'],
'animation_type' => $atts['animation_type'],
'animation_speed' => $atts['animation_speed'],
'animation_origin' => $atts['animation_origin'],
'close_on_overlay_click' => $atts['overlay_click'],
'close_on_esc_press' => $atts['esc_press'],
'extra_selectors' => '#popmake-' . $atts['id'],
$current_global_popup = pum()->current_popup;
pum()->current_popup = $popup;
$return = pum_get_template_part( 'popup' );
// Small hack to move popup to body.
$return .= "<script type='text/javascript' id='pum-move-popup-" . $post_id . "'>jQuery(document).ready(function () {
jQuery('#pum-" . $post_id . "').appendTo('body');
window.pum_vars.popups[ 'pum-" . $popup->ID . "' ] = " . PUM_Utils_Array::safe_json_encode( $popup->get_public_settings() ) . ";
window.pum_popups[ 'pum-" . $popup->ID . "' ] = " . PUM_Utils_Array::safe_json_encode( $popup->get_public_settings() ) . ";
jQuery('#pum-move-popup-" . $post_id . "').remove();
pum()->current_popup = $current_global_popup;
public function template() { ?>
<p class="pum-sub-form-desc">
<?php esc_html_e( 'Popup', 'popup-maker' ); ?>: ID "{{attrs.id}}"