: 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_Modules_Reviews
* This class adds a review request system for your plugin or theme to the WP dashboard.
class PUM_Modules_Reviews {
public static $api_url = 'https://api.wppopupmaker.com/wp-json/pmapi/v1/review_action';
public static function init() {
// add_action( 'init', array( __CLASS__, 'hooks' ) );
add_filter( 'pum_alert_list', [ __CLASS__, 'review_alert' ] );
add_action( 'wp_ajax_pum_review_action', [ __CLASS__, 'ajax_handler' ] );
* Hook into relevant WP actions.
public static function hooks() {
if ( is_admin() && current_user_can( 'edit_posts' ) ) {
add_action( 'admin_notices', [ __CLASS__, 'admin_notices' ] );
add_action( 'network_admin_notices', [ __CLASS__, 'admin_notices' ] );
add_action( 'user_admin_notices', [ __CLASS__, 'admin_notices' ] );
* Get the install date for comparisons. Sets the date to now if none is found.
public static function installed_on() {
$installed_on = get_option( 'pum_reviews_installed_on', false );
$installed_on = current_time( 'mysql' );
update_option( 'pum_reviews_installed_on', $installed_on );
public static function ajax_handler() {
'group' => self::get_trigger_group(),
'code' => self::get_trigger_code(),
'pri' => self::get_current_trigger( 'pri' ),
'reason' => 'maybe_later',
if ( ! wp_verify_nonce( $_REQUEST['nonce'], 'pum_review_action' ) ) {
$user_id = get_current_user_id();
$dismissed_triggers = self::dismissed_triggers();
$dismissed_triggers[ $args['group'] ] = $args['pri'];
update_user_meta( $user_id, '_pum_reviews_dismissed_triggers', $dismissed_triggers );
update_user_meta( $user_id, '_pum_reviews_last_dismissed', current_time( 'mysql' ) );
switch ( $args['reason'] ) {
update_user_meta( $user_id, '_pum_reviews_last_dismissed', current_time( 'mysql' ) );
self::already_did( true );
} catch ( Exception $e ) {
wp_send_json_error( $e );
public static function get_trigger_group() {
if ( ! isset( $selected ) ) {
$dismissed_triggers = self::dismissed_triggers();
$triggers = self::triggers();
foreach ( $triggers as $g => $group ) {
foreach ( $group['triggers'] as $t => $trigger ) {
if ( ! in_array( false, $trigger['conditions'] ) && ( empty( $dismissed_triggers[ $g ] ) || $dismissed_triggers[ $g ] < $trigger['pri'] ) ) {
if ( isset( $selected ) ) {
public static function get_trigger_code() {
if ( ! isset( $selected ) ) {
$dismissed_triggers = self::dismissed_triggers();
foreach ( self::triggers() as $g => $group ) {
foreach ( $group['triggers'] as $t => $trigger ) {
if ( ! in_array( false, $trigger['conditions'] ) && ( empty( $dismissed_triggers[ $g ] ) || $dismissed_triggers[ $g ] < $trigger['pri'] ) ) {
if ( isset( $selected ) ) {
* @return bool|mixed|void
public static function get_current_trigger( $key = null ) {
$group = self::get_trigger_group();
$code = self::get_trigger_code();
if ( ! $group || ! $code ) {
$trigger = self::triggers( $group, $code );
return empty( $key ) ? $trigger : ( isset( $trigger[ $key ] ) ? $trigger[ $key ] : false );
* Returns an array of dismissed trigger groups.
* Array contains the group key and highest priority trigger that has been shown previously for each group.
public static function dismissed_triggers() {
$user_id = get_current_user_id();
$dismissed_triggers = get_user_meta( $user_id, '_pum_reviews_dismissed_triggers', true );
if ( ! $dismissed_triggers ) {
$dismissed_triggers = [];
return $dismissed_triggers;
* Returns true if the user has opted to never see this again. Or sets the option.
* @param bool $set If set this will mark the user as having opted to never see this again.
public static function already_did( $set = false ) {
$user_id = get_current_user_id();
update_user_meta( $user_id, '_pum_reviews_already_did', true );
return (bool) get_user_meta( $user_id, '_pum_reviews_already_did', true );
* Gets a list of triggers.
public static function triggers( $group = null, $code = null ) {
if ( ! isset( $triggers ) ) {
$time_message = __( 'Hi there! You\'ve been using Popup Maker on your site for %s - I hope it\'s been helpful. If you\'re enjoying my plugin, would you mind rating it 5-stars to help spread the word?', 'popup-maker' );
'message' => sprintf( $time_message, __( '1 week', 'popup-maker' ) ),
strtotime( self::installed_on() . ' +1 week' ) < time(),
'link' => 'https://wordpress.org/support/plugin/popup-maker/reviews/?rate=5#rate-response',
'message' => sprintf( $time_message, __( '1 month', 'popup-maker' ) ),
strtotime( self::installed_on() . ' +1 month' ) < time(),
'link' => 'https://wordpress.org/support/plugin/popup-maker/reviews/?rate=5#rate-response',
'message' => sprintf( $time_message, __( '3 months', 'popup-maker' ) ),
strtotime( self::installed_on() . ' +3 months' ) < time(),
'link' => 'https://wordpress.org/support/plugin/popup-maker/reviews/?rate=5#rate-response',
$open_message = __( 'Hi there! You\'ve recently hit %s popup views on your site – that’s awesome!! If you\'d like to celebrate this milestone, rate Popup Maker 5-stars to help spread the word!', 'popup-maker' );
foreach ( [ 50, 100, 500, 1000, 5000, 10000, 50000, 100000, 500000, 1000000, 5000000 ] as $num ) {
$triggers['open_count']['triggers'][ $num . '_opens' ] = [
'message' => sprintf( $open_message, number_format( $num ) ),
get_option( 'pum_total_open_count', 0 ) > $num,
'link' => 'https://wordpress.org/support/plugin/popup-maker/reviews/?rate=5#rate-response',
$triggers = apply_filters( 'pum_reviews_triggers', $triggers );
uasort( $triggers, [ __CLASS__, 'rsort_by_priority' ] );
// Sort each groups triggers.
foreach ( $triggers as $k => $v ) {
uasort( $triggers[ $k ]['triggers'], [ __CLASS__, 'rsort_by_priority' ] );
if ( ! isset( $triggers[ $group ] ) ) {
if ( ! isset( $code ) ) {
return $triggers[ $group ];
return isset( $triggers[ $group ]['triggers'][ $code ] ) ? $triggers[ $group ]['triggers'][ $code ] : false;
* Register alert when review request is available.
public static function review_alert( $alerts = [] ) {
if ( self::hide_notices() ) {
$trigger = self::get_current_trigger();
// Used to anonymously distinguish unique site+user combinations in terms of effectiveness of each trigger.
$uuid = wp_hash( home_url() . '-' . get_current_user_id() );
<script type="text/javascript">
window.pum_review_nonce = '<?php echo wp_create_nonce( 'pum_review_action' ); ?>';
window.pum_review_api_url = '<?php echo esc_attr( self::$api_url ); ?>';
window.pum_review_uuid = '<?php echo esc_attr( $uuid ); ?>';
window.pum_review_trigger = {
group: '<?php echo esc_attr( self::get_trigger_group() ); ?>',
code: '<?php echo esc_attr( self::get_trigger_code() ); ?>',
pri: '<?php echo esc_attr( self::get_current_trigger( 'pri' ) ); ?>'
<a class="pum-dismiss" target="_blank" href="<?php echo esc_attr( $trigger['link'] ); ?>" data-reason="am_now"> <strong><?php _e( 'Ok, you deserve it', 'popup-maker' ); ?></strong> </a>
<a href="#" class="pum-dismiss" data-reason="maybe_later">
<?php _e( 'Nope, maybe later', 'popup-maker' ); ?>
<a href="#" class="pum-dismiss" data-reason="already_did">
<?php _e( 'I already did', 'popup-maker' ); ?>
'code' => 'review_request',
'message' => '<strong>' . $trigger['message'] . '<br />~ danieliser' . '</strong>',
* Render admin notices if available.
public static function admin_notices() {
if ( self::hide_notices() ) {
$group = self::get_trigger_group();
$code = self::get_trigger_code();
$pri = self::get_current_trigger( 'pri' );
$trigger = self::get_current_trigger();
// Used to anonymously distinguish unique site+user combinations in terms of effectiveness of each trigger.
$uuid = wp_hash( home_url() . '-' . get_current_user_id() );
<script type="text/javascript">
group: '<?php echo esc_attr( $group ); ?>',
code: '<?php echo esc_attr( $code ); ?>',
pri: '<?php echo esc_attr( $pri ); ?>'
function dismiss(reason) {
action: 'pum_review_action',
nonce: '<?php echo wp_create_nonce( 'pum_review_action' ); ?>',
<?php if ( ! empty( self::$api_url ) ) : ?>
url: '<?php echo esc_attr( self::$api_url ); ?>',
trigger_group: trigger.group,
trigger_code: trigger.code,
uuid: '<?php echo esc_attr( $uuid ); ?>'
.on('click', '.pum-notice .pum-dismiss', function (event) {
reason = $this.data('reason'),
notice = $this.parents('.pum-notice');
notice.fadeTo(100, 0, function () {
notice.slideUp(100, function () {
$('.pum-notice button.notice-dismiss').click(function (event) {
<div class="notice notice-success is-dismissible pum-notice">
<img class="logo" src="<?php echo POPMAKE_URL; ?>/assets/images/icon-256x256.jpg" />
<?php esc_html_e( $trigger['message'] ); ?>
<a class="pum-dismiss" target="_blank" href="<?php echo esc_attr( $trigger['link'] ); ?>" data-reason="am_now">
<strong><?php esc_html_e( 'Ok, you deserve it', 'popup-maker' ); ?></strong>
<a href="#" class="pum-dismiss" data-reason="maybe_later">
<?php esc_html_e( 'Nope, maybe later', 'popup-maker' ); ?>
<a href="#" class="pum-dismiss" data-reason="already_did">
<?php esc_html_e( 'I already did', 'popup-maker' ); ?>