: 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_CF7_Integration
class PUM_CF7_Integration {
* Initialize if CF7 is active.
public static function init() {
add_filter( 'pum_get_cookies', [ __CLASS__, 'register_cookies' ] );
add_filter( 'wpcf7_editor_panels', [ __CLASS__, 'editor_panels' ] );
add_action( 'wpcf7_after_save', [ __CLASS__, 'save' ] );
add_filter( 'wpcf7_form_elements', [ __CLASS__, 'form_elements' ] );
add_action( 'popmake_preload_popup', [ __CLASS__, 'preload' ] );
* Check if the popups use CF7 Forms and force enqueue their assets.
public static function preload( $popup_id ) {
$popup = pum_get_popup( $popup_id );
if ( has_shortcode( $popup->post_content, 'contact-form-7' ) ) {
if ( defined( 'WPCF7_LOAD_JS' ) && ! WPCF7_LOAD_JS ) {
if ( function_exists( 'wpcf7_enqueue_scripts' ) ) {
if ( function_exists( 'wpcf7_enqueue_styles' ) ) {
* Append a hidden meta html element with the forms popup settings.
public static function form_elements( $elements ) {
$form = wpcf7_get_current_contact_form();
$settings = wp_json_encode( self::form_options( $form->id() ) );
return $elements . "<input type='hidden' class='wpcf7-pum' value='$settings' />";
* Get a specific forms options.
public static function form_options( $id ) {
$settings = get_option( 'cf7_pum_' . $id, self::defaults() );
return wp_parse_args( $settings, self::defaults() );
public static function defaults() {
* Registers new cookie events.
public static function register_cookies( $cookies = [] ) {
$cookies['cf7_form_success'] = [
'name' => __( 'Contact Form 7 Success (deprecated. Use Form Submission instead.)', 'popup-maker' ),
'fields' => pum_get_cookie_fields(),
* Register new CF7 form editor tab.
public static function editor_panels( $panels = [] ) {
'title' => __( 'Popup Settings', 'popup-maker' ),
'callback' => [ __CLASS__, 'editor_panel' ],
public static function editor_panel( $args ) {
$settings = self::form_options( $args->id() ); ?>
<h2><?php _e( 'Popup Settings', 'popup-maker' ); ?></h2>
<p class="description"><?php _e( 'These settings control popups after successful form submissions.', 'popup-maker' ); ?></p>
<table class="form-table">
<label for="wpcf7-pum-closepopup"><?php _e( 'Close Popup', 'popup-maker' ); ?></label>
<input type="checkbox" id="wpcf7-pum-closepopup" name="wpcf7-pum[closepopup]" value="true" <?php checked( $settings['closepopup'], true ); ?> />
<tr id="wpcf7-pum-closedelay-wrapper">
<label for="wpcf7-pum-closedelay"><?php _e( 'Delay', 'popup-maker' ); ?></label>
if ( strlen( $settings['closedelay'] ) >= 3 ) {
$settings['closedelay'] = $settings['closedelay'] / 1000;
<input type="number" id="wpcf7-pum-closedelay" min="0" step="1" name="wpcf7-pum[closedelay]" style="width: 100px;" value="<?php echo esc_attr( $settings['closedelay'] ); ?>" /><?php _e( 'seconds', 'popup-maker' ); ?>
<label for="wpcf7-pum-openpopup"><?php _e( 'Open Popup', 'popup-maker' ); ?></label>
<input type="checkbox" id="wpcf7-pum-openpopup" name="wpcf7-pum[openpopup]" value="true" <?php checked( $settings['openpopup'], true ); ?> />
<tr id="wpcf7-pum-openpopup_id-wrapper">
<label for="wpcf7-pum-openpopup_id"><?php _e( 'Popup', 'popup-maker' ); ?></label>
<select id="wpcf7-pum-openpopup_id" name="wpcf7-pum[openpopup_id]">
<?php foreach ( self::get_popup_list() as $option ) { ?>
<option value="<?php echo esc_attr( $option['value'] ); ?>" <?php selected( $settings['openpopup_id'], $option['value'] ); ?>><?php echo $option['label']; ?></option>
var $open = $('#wpcf7-pum-openpopup'),
$close = $('#wpcf7-pum-closepopup'),
$popup_id_wrapper = $('#wpcf7-pum-openpopup_id-wrapper'),
$delay_wrapper = $('#wpcf7-pum-closedelay-wrapper');
if ($open.is(':checked')) {
$popup_id_wrapper.show();
$popup_id_wrapper.hide();
if ($close.is(':checked')) {
$open.on('click', check_open);
$close.on('click', check_close);
* Get a list of popups for a select box.
public static function get_popup_list() {
'label' => __( 'Select a popup', 'popup-maker' ),
'post_status' => [ 'publish' ],
foreach ( $popups as $popup ) {
'label' => $popup->post_title,
* Save form popup options.
public static function save( $args ) {
if ( ! empty( $_POST['wpcf7-pum'] ) ) {
$settings = $_POST['wpcf7-pum'];
$settings['openpopup'] = ! empty( $settings['openpopup'] );
$settings['openpopup_id'] = ! empty( $settings['openpopup_id'] ) ? absint( $settings['openpopup_id'] ) : 0;
$settings['closepopup'] = ! empty( $settings['closepopup'] );
$settings['closedelay'] = ! empty( $settings['closedelay'] ) ? absint( $settings['closedelay'] ) : 0;
update_option( 'cf7_pum_' . $args->id(), $settings );
delete_option( 'cf7_pum_' . $args->id() );