: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
namespace TwitterFeed\Admin;
// Exit if accessed directly
use TwitterFeed\Builder\CTF_Db;
if ( ! defined( 'ABSPATH' ) ) {
class CTF_New_User extends CTF_Notifications {
* Source of notifications content.
const SOURCE_URL = 'https://plugin.smashballoon.com/newuser.json';
const OPTION_NAME = 'ctf_newuser_notifications';
public function hooks() {
add_action( 'admin_init', array( $this, 'dismiss' ) );
add_action( 'wp_ajax_ctf_review_notice_consent_update', array( $this, 'review_notice_consent' ) );
public function option_name() {
return self::OPTION_NAME;
public function source_url() {
* Verify notification data before it is saved.
* @param array $notifications Array of notifications items to verify.
public function verify( $notifications ) {
if ( ! is_array( $notifications ) || empty( $notifications ) ) {
$option = $this->get_option();
foreach ( $notifications as $key => $notification ) {
// The message should never be empty, if they are, ignore.
if ( empty( $notification['content'] ) ) {
// Ignore if notification has already been dismissed.
if ( ! empty( $option['dismissed'] ) && in_array( $notification['id'], $option['dismissed'] ) ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
$data[ $key ] = $notification;
* Verify saved notification data for active notifications.
* @param array $notifications Array of notifications items to verify.
public function verify_active( $notifications ) {
if ( ! is_array( $notifications ) || empty( $notifications ) ) {
$ctf_statuses_option = get_option( 'ctf_statuses', array() );
$current_time = ctf_get_current_time();
$ctf_rating_notice_option = get_option( 'ctf_rating_notice', false );
$ctf_rating_notice_waiting = get_transient( 'custom_twitter_feeds_rating_notice_waiting' );
$should_show_rating_notice = ($ctf_rating_notice_waiting !== 'waiting' && $ctf_rating_notice_option !== 'dismissed');
// new user discount logic
$in_new_user_month_range = true;
$should_show_new_user_discount = false;
$has_been_one_month_since_rating_dismissal = isset( $ctf_statuses_option['rating_notice_dismissed'] ) ? ((int)$ctf_statuses_option['rating_notice_dismissed'] + ((int)$notifications['review']['wait'] * DAY_IN_SECONDS)) < $current_time + 1: true;
if ( isset( $ctf_statuses_option['first_install'] ) && $ctf_statuses_option['first_install'] === 'from_update' ) {
$user_id = $current_user->ID;
$ignore_new_user_sale_notice_meta = get_user_meta( $user_id, 'ctf_ignore_new_user_sale_notice' );
$ignore_new_user_sale_notice_meta = isset( $ignore_new_user_sale_notice_meta[0] ) ? $ignore_new_user_sale_notice_meta[0] : '';
if ( $ignore_new_user_sale_notice_meta !== 'always' ) {
$should_show_new_user_discount = true;
} elseif ( $in_new_user_month_range && $has_been_one_month_since_rating_dismissal && $ctf_rating_notice_waiting !== 'waiting' ) {
$user_id = $current_user->ID;
$ignore_new_user_sale_notice_meta = get_user_meta( $user_id, 'ctf_ignore_new_user_sale_notice' );
$ignore_new_user_sale_notice_meta = isset( $ignore_new_user_sale_notice_meta[0] ) ? $ignore_new_user_sale_notice_meta[0] : '';
if ( $ignore_new_user_sale_notice_meta !== 'always'
&& isset( $ctf_statuses_option['first_install'] )
&& $current_time > (int)$ctf_statuses_option['first_install'] + ((int)$notifications['discount']['wait'] * DAY_IN_SECONDS) ) {
$should_show_new_user_discount = true;
if ( ctf_is_pro_version() ) {
$should_show_new_user_discount = false;
if ( isset( $notifications['review'] ) && $should_show_rating_notice ) {
return array( $notifications['review'] );
} elseif ( isset( $notifications['discount'] ) && $should_show_new_user_discount ) {
return array( $notifications['discount'] );
if ( ! $this->has_access() ) {
$option = $this->get_option();
$ctf_options = get_option( 'ctf_options', array() );
if ( empty( $ctf_options[ CTF_SITE_ACCESS_TOKEN_KEY ] ) ) {
$feeds_count = CTF_Db::feeds_count();
if ( $feeds_count > 0 ) {
'title' => 'Twitter API Changes',
'content' => 'Using Custom Twitter Feeds now requires that you connect with Smash Balloon and create a site key. Click the button below to visit our website and verify an email address to get started.',
'type' => array( 'free' ),
'recent_install_override' => true,
'url' => ctf_oauth_url( admin_url( 'admin.php?page=ctf-settings' ) ),
'start' => '2022-02-08 00:00:00',
'end' => '2030-02-08 00:00:00',
// Only update if does not exist.
if ( empty( $option['update'] ) ) {
$events = ! empty( $option['events'] ) ? $this->verify_active( $option['events'] ) : array();
$feed = ! empty( $option['feed'] ) ? $this->verify_active( $option['feed'] ) : array();
return array_merge( $events, $feed );
* Add a manual notification event.
* @param array $notification Notification data.
public function add( $notification ) {
if ( empty( $notification['id'] ) ) {
$option = $this->get_option();
if ( in_array( $notification['id'], $option['dismissed'] ) ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
foreach ( $option['events'] as $item ) {
if ( $item['id'] === $notification['id'] ) {
$notification = $this->verify( array( $notification ) );
'update' => $option['update'],
'feed' => $option['feed'],
'events' => array_merge( $notification, $option['events'] ),
'dismissed' => $option['dismissed'],
* Update notification data from feed.
public function update() {
$feed = $this->fetch_feed();
$option = $this->get_option();
'events' => $option['events'],
'dismissed' => $option['dismissed'],
* Do not enqueue anything extra.
public function enqueues() {
public function review_notice_consent() {
check_ajax_referer( 'ctf-admin', 'ctf_nonce' );
$cap = ctf_get_manage_options_cap();
if ( ! current_user_can( $cap ) ) {
wp_send_json_error(); // This auto-dies.
$consent = isset( $_POST[ 'consent' ] ) ? sanitize_text_field( $_POST[ 'consent' ] ) : '';
update_option( 'ctf_review_consent', $consent );
if ( $consent == 'no' ) {
$ctf_statuses_option = get_option( 'ctf_statuses', array() );
update_option( 'ctf_rating_notice', 'dismissed', false );
$ctf_statuses_option['rating_notice_dismissed'] = ctf_get_current_time();
update_option( 'ctf_statuses', $ctf_statuses_option, false );
* Output notifications on Form Overview admin area.
public function output() {
$notifications = $this->get();
if ( empty( $notifications ) ) {
if ( function_exists( 'display_instagram' ) ) {
if ( function_exists( 'cff_check_for_db_updates' ) ) {
// new user notices included in regular settings page notifications so this
// checks to see if user is one of those pages
if ( ! empty( $_GET['page'] )
&& strpos( $_GET['page'], 'ctf' ) !== false ) {
$content_allowed_tags = array(
foreach ( $notifications as $notification ) {
$img_src = CTF_PLUGIN_URL . 'admin/assets/img/' . sanitize_text_field( $notification['image'] );
$type = sanitize_text_field( $notification['id'] );
// check if this is a review notice
if( $type == 'review' ) {
$review_consent = get_option( 'ctf_review_consent' );
$ctf_open_feedback_url = 'https://smashballoon.com/feedback/?plugin=twitter-free';
// step #1 for the review notice
if ( ! $review_consent ) {
<div class="ctf_notice ctf_review_notice_step_1">
<img src="<?php echo esc_url( str_replace( array( 'sbi', 'png' ), array( 'ctf', 'svg' ), $img_src ) ); ?>" alt="notice">
<div class="ctf-notice-text">
<p class="ctf-notice-text-p"><?php echo __( 'Are you enjoying the Twitter Feed Plugin?', 'custom-twitter-feeds' ); ?></p>
<div class="ctf-notice-consent-btns">
'<button class="ctf-btn-link" id="ctf_review_consent_yes">%s</button>',
__( 'Yes', 'custom-twitter-feeds' )
'<a href="%s" target="_blank" rel="nofollow noopener" class="ctf-btn-link" id="ctf_review_consent_no">%s</a>',
__( 'No', 'custom-twitter-feeds' )
$close_href = add_query_arg( array( 'ctf_dismiss' => $type ) );
$title = $this->get_notice_title( $notification );
$content = $this->get_notice_content( $notification, $content_allowed_tags );
if ( ! empty( $notification['btns'] ) && is_array( $notification['btns'] ) ) {
foreach ( $notification['btns'] as $btn_type => $btn ) {
if ( ! is_array( $btn['url'] ) ) {
$buttons[ $btn_type ]['url'] = $this->replace_merge_fields( $btn['url'], $notification );
} elseif ( is_array( $btn['url'] ) ) {
$buttons[ $btn_type ]['url'] = add_query_arg( $btn['url'] );
$buttons[ $btn_type ]['attr'] = '';
if ( ! empty( $btn['attr'] ) ) {
$buttons[ $btn_type ]['attr'] = ' target="_blank" rel="noopener noreferrer"';
$buttons[ $btn_type ]['class'] = '';
if ( ! empty( $btn['class'] ) ) {
$buttons[ $btn_type ]['class'] = ' ' . $btn['class'];
$buttons[ $btn_type ]['text'] = '';
if ( ! empty( $btn['text'] ) ) {
$buttons[ $btn_type ]['text'] = wp_kses( $btn['text'], $content_allowed_tags );
$review_consent = get_option( 'ctf_review_consent' );
$review_step2_style = '';
if ( $type == 'review' && ! $review_consent ) {
$review_step2_style = 'style="display: none;"';
<div class="ctf_notice_op ctf_notice ctf_<?php echo esc_attr( $type ); ?>_notice" <?php echo !empty( $review_step2_style ) ? $review_step2_style : ''; ?>>
<img src="<?php echo esc_url( str_replace( array( 'sbi', 'png' ), array( 'ctf', 'svg' ), $img_src ) ); ?>" alt="notice">
<?php echo $image_overlay; ?>
<div class="ctf-notice-text">
<div class="ctf-notice-text-inner">
<h3 class="ctf-notice-text-header"><?php echo $title; ?></h3>
<p class="ctf-notice-text-p"><?php echo $content; ?></p>
<div class="ctf-notice-btns-wrap">
<p class="ctf-notice-links">
foreach ( $buttons as $type => $button ) :
$btn_classes = array('ctf-btn');
$btn_classes[] = esc_attr( $button['class'] );
if ( $type == 'primary' ) {
$btn_classes[] = 'ctf-btn-blue';
$btn_classes[] = 'ctf-btn-grey';
<a class="<?php echo implode(' ', $btn_classes); ?>" href="<?php echo esc_attr( str_replace( 'sbi_', 'ctf_', $button['url'] ) ); ?>"<?php echo $button['attr']; ?>><?php echo $button['text']; ?></a>
<div class="ctf-notice-dismiss">
<a href="<?php echo esc_url( $close_href ); ?>">
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M14 1.41L12.59 0L7 5.59L1.41 0L0 1.41L5.59 7L0 12.59L1.41 14L7 8.41L12.59 14L14 12.59L8.41 7L14 1.41Z" fill="#141B38"></path>
* CTF Get Notice Title depending on the notice type
* @param array $notification
public function get_notice_title( $notification ) {
$type = $notification['id'];
// Notice title depending on notice type
if ( $type == 'review' ) {
$title = __( 'Glad to hear you are enjoying it. Would you consider leaving a positive review?', 'custom-twitter-feeds' );
} else if ( $type == 'discount' ) {
$title = __( 'Exclusive Offer! 60% OFF', 'custom-twitter-feeds' );
$title = $this->replace_merge_fields( $notification['title'], $notification );
* CTF Get Notice Content depending on the notice type
* @param array $notification
* @param array $content_allowed_tags
* @return string $content
public function get_notice_content( $notification, $content_allowed_tags ) {
$type = $notification['id'];
// Notice content depending on notice type
if ( $type == 'review' ) {
$content = __( 'It really helps to support the plugin and help others to discover it too!', 'custom-twitter-feeds' );
} else if ( $type == 'discount' ) {
$content = __( 'We don’t run promotions very often, but for a limited time we’re offering 60% Off our Pro version to all users of our free Twitter Feed.', 'custom-twitter-feeds' );
if ( ! empty( $notification['content'] ) ) {
$content = wp_kses( $this->replace_merge_fields( $notification['content'], $notification ), $content_allowed_tags );
* Hide messages permanently or some can be dismissed temporarily
public function dismiss() {