: 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' ) ) {
public static function init() {
add_action( 'admin_init', [ __CLASS__, 'hooks' ] );
add_action( 'admin_init', [ __CLASS__, 'php_handler' ] );
add_action( 'wp_ajax_pum_alerts_action', [ __CLASS__, 'ajax_handler' ] );
add_filter( 'pum_alert_list', [ __CLASS__, 'whats_new_alerts' ], 0 );
add_filter( 'pum_alert_list', [ __CLASS__, 'integration_alerts' ], 5 );
add_filter( 'pum_alert_list', [ __CLASS__, 'translation_request' ], 10 );
add_action( 'admin_menu', [ __CLASS__, 'append_alert_count' ], 999 );
* Gets a count of current alerts.
public static function alert_count() {
return count( self::get_alerts() );
* Append alert count to Popup Maker menu item.
public static function append_alert_count() {
$count = self::alert_count();
foreach ( $menu as $key => $item ) {
if ( 'edit.php?post_type=popup' === $item[2] ) {
$menu[ $key ][0] .= $count ? ' <span class="update-plugins count-' . $count . '"><span class="plugin-count pum-alert-count" aria-hidden="true">' . $count . '</span></span>' : '';
public static function translation_request( $alerts = [] ) {
$version = explode( '.', Popup_Maker::$VER );
// Get only the major.minor version exclude the point releases.
$version = $version[0] . '.' . $version[1];
$code = 'translation_request_' . $version;
// Bail Early if they have already dismissed.
if ( self::has_dismissed_alert( $code ) ) {
// Get locales based on the HTTP accept language header.
$locales_from_header = PUM_Utils_I10n::get_http_locales();
// Abort early if no locales in header.
if ( empty( $locales_from_header ) ) {
// Get acceptable non EN WordPress locales based on the HTTP accept language header.
// Used when the current locale is EN only I believe.
$non_en_locales_from_header = PUM_Utils_I10n::get_non_en_accepted_wp_locales_from_header();
// If no additional languages are supported abort
if ( empty( $non_en_locales_from_header ) ) {
* Assume all at this point are possible polyglots.
* -- Translation available in one additional language!
* ---- Show notice that there other language is available and we need help translating.
* -- Translation available in more than one language!
* ---- Show notice that their other languages are available and need help translating.
* -- Translation not available!
* ---- Show notice that plugin is not translated and we need help.
* Else If translation for their language(s) exists, but isn't up to date!
* -- Show notice that their language is available, but out of date and need help translating.
* Else If translations for their language doesn't exist!
* -- Show notice that plugin is not translated and we need help.
$current_locale = function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
// Get the active language packs of the plugin.
$translation_status = PUM_Utils_I10n::translation_status();
// Retrieve all the WordPress locales in which the plugin is translated.
$locales_with_translations = wp_list_pluck( $translation_status, 'language' );
$locale_translation_versions = wp_list_pluck( $translation_status, 'version' );
// Suggests existing langpacks
$suggested_locales_with_langpack = array_values( array_intersect( $non_en_locales_from_header, $locales_with_translations ) );
$current_locale_is_suggested = in_array( $current_locale, $suggested_locales_with_langpack );
$current_locale_is_translated = in_array( $current_locale, $locales_with_translations );
// Last chance to abort early before querying all available languages.
// We abort here if the user is already using a translated language that is up to date!
if ( $current_locale_is_suggested && $current_locale_is_translated && version_compare( $locale_translation_versions[ $current_locale ], Popup_Maker::$VER, '>=' ) ) {
// Retrieve all the WordPress locales.
$locales_supported_by_wordpress = PUM_Utils_I10n::available_locales();
// Get the native language names of the locales.
$suggest_translated_locale_names = [];
foreach ( $suggested_locales_with_langpack as $locale ) {
$suggest_translated_locale_names[ $locale ] = $locales_supported_by_wordpress[ $locale ]['native_name'];
// If we get this far, they clearly have multiple language available
// If current locale is english but they have others available, they are likely polyglots.
$currently_in_english = strpos( $current_locale, 'en' ) === 0;
if ( $currently_in_english ) {
// Only one locale suggestion.
if ( 1 === count( $suggest_translated_locale_names ) ) {
$language = current( $suggest_translated_locale_names );
$suggest_string = sprintf( /* translators: %s: native language name. */
__( 'This plugin is also available in %1$s. <a href="%2$s" target="_blank">Help improve the translation!</a>', 'popup-maker' ),
esc_url( 'https://translate.wordpress.org/projects/wp-plugins/popup-maker' )
// Multiple locale suggestions.
} elseif ( ! empty( $suggest_translated_locale_names ) ) {
$primary_language = current( $suggest_translated_locale_names );
array_shift( $suggest_translated_locale_names );
foreach ( $suggest_translated_locale_names as $language ) {
$other_suggest .= $language . ', ';
$suggest_string = sprintf( /* translators: 1: native language name, 2: other native language names, comma separated */
__( 'This plugin is also available in %1$s (also: %2$s). <a href="%3$s" target="_blank">Help improve the translation!</a>', 'popup-maker' ),
trim( $other_suggest, ' ,' ),
esc_url( 'https://translate.wordpress.org/projects/wp-plugins/popup-maker' )
// Non-English locale in header, no translations.
} elseif ( ! empty( $non_en_locales_from_header ) ) {
if ( 1 === count( $non_en_locales_from_header ) ) {
$locale = reset( $non_en_locales_from_header );
$suggest_string = sprintf( /* translators: 1: native language name, 2: URL to translate.wordpress.org */
__( 'This plugin is not translated into %1$s yet. <a href="%2$s" target="_blank">Help translate it!</a>', 'popup-maker' ),
$locales_supported_by_wordpress[ $locale ]['native_name'],
esc_url( 'https://translate.wordpress.org/projects/wp-plugins/popup-maker' )
$primary_locale = reset( $non_en_locales_from_header );
$primary_language = $locales_supported_by_wordpress[ $primary_locale ]['native_name'];
array_shift( $non_en_locales_from_header );
foreach ( $non_en_locales_from_header as $locale ) {
$other_suggest .= $locales_supported_by_wordpress[ $locale ]['native_name'] . ', ';
$suggest_string = sprintf( /* translators: 1: native language name, 2: other native language names, comma separated */
__( 'This plugin is also available in %1$s (also: %2$s). <a href="%3$s" target="_blank">Help improve the translation!</a>', 'popup-maker' ),
trim( $other_suggest, ' ,' ),
esc_url( 'https://translate.wordpress.org/projects/wp-plugins/popup-maker' )
// The plugin has no translation for the current locale.
} elseif ( ! $current_locale_is_suggested && ! $current_locale_is_translated ) {
$suggest_string = sprintf( __( 'This plugin is not translated into %1$s yet. <a href="%2$s" target="_blank">Help translate it!</a>', 'popup-maker' ), $locales_supported_by_wordpress[ $current_locale ]['native_name'], esc_url( 'https://translate.wordpress.org/projects/wp-plugins/popup-maker' ) );
// The plugin has translations for current locale, but they are out of date.
} elseif ( $current_locale_is_suggested && $current_locale_is_translated && version_compare( $locale_translation_versions[ $current_locale ], Popup_Maker::$VER, '<' ) ) {
$suggest_string = sprintf( /* translators: %s: native language name. */
__( 'This plugin\'s translation for %1$s is out of date. <a href="%2$s" target="_blank">Help improve the translation!</a>', 'popup-maker' ),
$locales_supported_by_wordpress[ $current_locale ]['native_name'],
esc_url( 'https://translate.wordpress.org/projects/wp-plugins/popup-maker' )
if ( ! empty( $suggest_string ) ) {
'message' => $suggest_string,
public static function whats_new_alerts( $alerts = [] ) {
$upgraded_from = PUM_Utils_Upgrades::$upgraded_from;
if ( version_compare( $upgraded_from, '0.0.0', '>' ) ) {
if ( version_compare( $upgraded_from, '1.8.0', '<' ) ) {
'code' => 'whats_new_1_8_0',
'<strong>' . __( 'See whats new in v%1$s - (%2$sview all changes%3$s)', 'popup-maker' ) . '</strong>',
'<a href="' . add_query_arg(
'tab' => 'plugin-information',
'plugin' => 'popup-maker',
'section' => 'changelog',
admin_url( 'plugin-install.php' )
) . '" target="_blank">',
'html' => "<ul class='ul-disc'>" . '<li>' . 'New UX for the Popup Theme editor.' . '</li>' . '<li>' . 'New close button positions: top center, bottom center, middle left & middle right.' . '</li>' . '<li>' . 'New option to position close button outside of popup.' . '</li>' . '</ul>',
public static function integration_alerts( $alerts = [] ) {
'label' => __( 'BuddyPress', 'buddypress' ),
'learn_more_url' => 'https://wppopupmaker.com/works-with/buddypress/',
'conditions' => ! class_exists( 'PUM_BuddyPress' ) && ( function_exists( 'buddypress' ) || class_exists( 'BuddyPress' ) ),
'slug' => 'popup-maker-buddypress-integration',
'name' => 'Popup Maker - BuddyPress Integration',
foreach ( $integrations as $key => $integration ) {
if ( $integration['conditions'] ) {
$path = "{$integration['slug']}/{$integration['slug']}.php";
$plugin_data = file_exists( WP_PLUGIN_DIR . '/' . $path ) ? get_plugin_data( WP_PLUGIN_DIR . '/' . $path, false, false ) : false;
$installed = $plugin_data && ! empty( $plugin_data['Name'] ) && $plugin_data['Name'] === $integration['name'];
$text = $installed ? __( 'activate it now', 'popup-maker' ) : __( 'install it now', 'popup-maker' );
$url = $installed ? esc_url( wp_nonce_url( admin_url( 'plugins.php?action=activate&plugin=' . $path ), 'activate-plugin_' . $path ) ) : esc_url( wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=popup-maker-buddypress-integration' ), 'install-plugin_popup-maker-buddypress-integration' ) );
'code' => $key . '_integration_available',
'message' => sprintf( __( '%1$sDid you know:%2$s Popup Maker has custom integrations with %3$s, %4$slearn more%5$s or %6$s%7$s%8$s!', 'popup-maker' ), '<strong>', '</strong>', $integration['label'], '<a href="' . $integration['learn_more_url'] . '" target="_blank">', '</a>', '<a href="' . $url . '">', $text, '</a>' ),
'type' => $installed ? 'warning' : 'info',
* 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' ] );
public static function should_show_alerts() {
count( self::get_global_alerts() ) > 0,
* Allow additional style properties for notice alerts.
* @param array $styles Array of allowed style properties.
public static function allow_inline_styles( $styles ) {
$styles[] = 'list-style';
$styles[] = 'margin-left';
$styles[] = 'margin-right';
$styles[] = 'margin-top';
$styles[] = 'margin-bottom';
* Return array of allowed html tags.
public static function allowed_tags() {
return array_merge_recursive(
wp_kses_allowed_html( 'post' ),
// Allow script tags with type="" attribute.
'script' => [ 'type' => true ],
* Render admin alerts if available.
public static function admin_notices() {
if ( ! self::should_show_alerts() ) {
$global_only = ! pum_is_admin_page();
$alerts = $global_only ? self::get_global_alerts() : self::get_alerts();
$count = count( $alerts );
wp_enqueue_script( 'pum-admin-general' );
wp_enqueue_style( 'pum-admin-general' );
$nonce = wp_create_nonce( 'pum_alerts_action' );
<script type="text/javascript">
window.pum_alerts_nonce = '<?php echo $nonce; ?>';
<img alt="" class="logo" width="30" src="<?php echo Popup_Maker::$URL; ?>assets/images/logo.png" /> <?php printf( '%s%s (%s)', ( $global_only ? __( 'Popup Maker', 'popup-maker' ) . ' ' : '' ), __( 'Notifications', 'popup-maker' ), '<span class="pum-alert-count">' . $count . '</span>' ); ?>
<p><?php __( 'Check out the following notifications from Popup Maker.', 'popup-maker' ); ?></p>
add_filter( 'safe_style_css', [ __CLASS__, 'allow_inline_styles' ] );
foreach ( $alerts as $alert ) {
$expires = 1 === $alert['dismissible'] ? '' : $alert['dismissible'];
$dismiss_url = add_query_arg(
'code' => $alert['code'],
'pum_dismiss_alert' => 'dismiss',
<div class="pum-alert-holder" data-code="<?php echo esc_attr( $alert['code'] ); ?>" class="<?php echo $alert['dismissible'] ? 'is-dismissible' : ''; ?>" data-dismissible="<?php echo esc_attr( $alert['dismissible'] ); ?>">
<div class="pum-alert <?php echo '' !== $alert['type'] ? 'pum-alert__' . esc_attr( $alert['type'] ) : ''; ?>">