: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
return apply_filters( 'pum_popup_is_loadable', $loadable, $this->ID );
* Check an individual condition with settings.
* @param array $condition Condition to check.
public function check_condition( $condition = [] ) {
$condition_args = PUM_Conditions::instance()->get_condition( $condition['target'] );
if ( ! $condition_args ) {
// Bail early with true for conditions that will be processed in JavaScript later.
if ( $this->is_js_condition( $condition ) ) {
$condition['settings'] = isset( $condition['settings'] ) && is_array( $condition['settings'] ) ? $condition['settings'] : [];
return (bool) call_user_func( $condition_args['callback'], $condition, $this );
* Check if mobile was disabled
public function mobile_disabled() {
return (bool) apply_filters( 'pum_popup_mobile_disabled', $this->get_setting( 'disable_on_mobile' ), $this->ID );
* Check if tablet was disabled
public function tablet_disabled() {
return (bool) apply_filters( 'pum_popup_tablet_disabled', (bool) $this->get_setting( 'disable_on_tablet' ), $this->ID );
* Get a popups event count.
* @param string $event Event nme.
* @param string $which Which stats to get.
public function get_event_count( $event = 'open', $which = 'current' ) {
$current = $this->get_meta( "popup_{$event}_count" );
// Save future queries by inserting a valid count.
if ( false === $current || ! is_numeric( $current ) ) {
$this->update_meta( "popup_{$event}_count", $current );
return absint( $current );
$total = $this->get_meta( "popup_{$event}_count_total" );
// Save future queries by inserting a valid count.
if ( false === $total || ! is_numeric( $total ) ) {
$this->update_meta( "popup_{$event}_count_total", $total );
* Increase popup event counts.
* @param string $event Evet to increase count for.
public function increase_event_count( $event = 'open' ) {
* This section simply ensures that all keys exist before the below query runs. This should only ever cause extra queries once per popup, usually in the admin.
$keys = PUM_Analytics::event_keys( $event );
// Set the current count.
$current = $this->get_event_count( $event );
// Set the total count since creation.
$total = $this->get_event_count( $event, 'total' );
$this->update_meta( 'popup_' . $keys[0] . '_count', absint( $current ) );
$this->update_meta( 'popup_' . $keys[0] . '_count_total', absint( $total ) );
$this->update_meta( 'popup_last_' . $keys[1], time() );
$site_total = get_option( 'pum_total_' . $keys[0] . '_count', 0 );
update_option( 'pum_total_' . $keys[0] . '_count', $site_total );
// If is multisite add this blogs total to the site totals.
if ( function_exists( 'is_multisite' ) && is_multisite() ) {
$network_total = get_site_option( 'pum_site_total_' . $keys[0] . '_count', false );
$network_total = ! $network_total ? $site_total : $network_total + 1;
update_site_option( 'pum_site_total_' . $keys[0] . '_count', $network_total );
* Set event default values.
* @param string $event Event name.
public function set_event_defaults( $event ) {
$this->get_event_count( $event );
$this->get_event_count( $event, 'total' );
$keys = PUM_Analytics::event_keys( $event );
$last = $this->get_meta( 'popup_last_' . $keys[1] );
if ( empty( $last ) || ! is_numeric( $last ) ) {
$this->update_meta( 'popup_last_' . $keys[1], 0 );
* Log and reset popup open count to 0.
public function reset_counts() {
// Log the reset time and count.
'opens' => absint( $this->get_event_count( 'open', 'current' ) ),
'conversions' => absint( $this->get_event_count( 'conversion', 'current' ) ),
foreach ( [ 'open', 'conversion' ] as $event ) {
$keys = PUM_Analytics::event_keys( $event );
$this->update_meta( 'popup_' . $keys[0] . '_count', 0 );
$this->update_meta( 'popup_last_' . $keys[1], 0 );
* Returns the last reset information.
public function get_last_count_reset() {
$resets = $this->get_meta( 'popup_count_reset', false );
if ( empty( $resets ) ) {
if ( ! empty( $resets['timestamp'] ) ) {
// Looks like the result is already the last one, return it.
if ( count( $resets ) === 1 ) {
// Looks like we only got one result, return it.
usort( $resets, [ $this, 'compare_resets' ] );
* Array comparison callback function comparing timestamps.
* @param array $a Array with `timestamp` key for comparison.
* @param array $b Array with `timestamp` key for comparison.
public function compare_resets( $a, $b ) {
return (float) $a['timestamp'] < (float) $b['timestamp'];
* Setup this popup when instantiated.
* @param WP_Post $post WP_Post object.
public function setup( $post ) {
if ( ! $this->is_valid() ) {
// REVIEW Does this need to be here or somewhere else like get_meta/get_setting?
if ( ! isset( $this->data_version ) ) {
$this->data_version = (int) $this->get_meta( 'data_version' );
if ( ! $this->data_version ) {
$theme = $this->get_meta( 'popup_theme' );
$display_settings = $this->get_meta( 'popup_display' );
// If there are existing settings set the data version to 2 so they can be updated.
// Otherwise set to the current version as this is a new popup.
$is_v2 = ( ! empty( $display_settings ) && is_array( $display_settings ) ) || $theme > 0;
$this->data_version = $is_v2 ? 2 : $this->model_version;
$this->update_meta( 'data_version', $this->data_version );
if ( $this->data_version < $this->model_version && pum_passive_popup_upgrades_enabled() ) {
* Process passive settings migration as each popup is loaded. The will only run each migration routine once for each popup.
$this->passive_migration();
* Allows for passive migration routines based on the current data version.
public function passive_migration() {
$this->doing_passive_migration = true;
for ( $i = $this->data_version; $this->data_version < $this->model_version; $i ++ ) {
do_action_ref_array( 'pum_popup_passive_migration_' . $this->data_version, [ &$this ] );
* Update the popups data version.
$this->update_meta( 'data_version', $this->data_version );
do_action_ref_array( 'pum_popup_passive_migration', [ &$this, $this->data_version ] );
$this->doing_passive_migration = false;
* @deprecated 1.7.0 Still used in several extension migration routines, so needs to stay for now.
pum()->popups->update_item( $this->ID, $this->to_array() );
} catch ( Exception $e ) {
* Get instance of popup model.
* @deprecated 1.8.0 Only here to prevent possible errors.
* @param int $id Popup ID.
* @param bool $force Force load.
* @return PUM_Model_Popup
public static function instance( $id, $force = false ) {
return pum_get_popup( $id );