: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
namespace EmbedPress\Includes\Classes;
if (!defined('ABSPATH')) {
} // Exit if accessed directly.
class EmbedPress_Notice {
const ADMIN_UPDATE_NOTICE_KEY = 'wpdeveloper_notices_seen';
public $text_domain = 'embedpress';
private $properties = array(
'links', 'message', 'thumbnail',
private $methods = array(
'message', 'thumbnail', 'classes'
* cne_day == current_notice_end_day
public $cne_time = '2 day';
public $maybe_later_time = '7 day';
public $finish_time = [];
* First Install Version Of The Plugin
private $do_notice_action;
public $options_args = array();
* Upsale Notice Arguments
* Revoke this function when the object is created.
* @param string $plugin_file
public function __construct( $plugin_file = '', $version = '' ) {
$this->plugin_file = $plugin_file;
$this->plugin_name = basename( $plugin_file, '.php' );
$this->version = $version;
$this->timestamp = intval( current_time( 'timestamp' ) );
$this->notice_id = 'wpdeveloper_notice_' . str_replace( '.', '_', $this->version );
$this->do_notice_action = 'wpdeveloper_notices_for_' . $this->plugin_name;
new EmbedPress_Core_Installer( $this->plugin_name );
add_action( 'init', array( $this, 'first_install_track') );
add_action( 'deactivate_' . $this->plugin_file, array( $this, 'first_install_end' ) );
add_action( 'init', array( $this, 'hooks' ) );
add_action( 'wpdeveloper_notice_clicked_for_' . $this->plugin_name, array( $this, 'clicked' ) );
add_action( 'wp_ajax_wpdeveloper_upsale_notice_dissmiss_for_' . $this->plugin_name, array( $this, 'upsale_notice_dissmiss' ) );
add_action( 'wp_ajax_wpdeveloper_notice_dissmiss_for_' . $this->plugin_name, array( $this, 'notice_dissmiss' ) );
add_action( 'wpdeveloper_before_notice_for_' . $this->plugin_name, array( $this, 'before' ) );
add_action( 'wpdeveloper_after_notice_for_' . $this->plugin_name, array( $this, 'after' ) );
add_action( 'wpdeveloper_before_upsale_notice_for_' . $this->plugin_name, array( $this, 'before_upsale' ) );
add_action( 'wpdeveloper_after_upsale_notice_for_' . $this->plugin_name, array( $this, 'after' ) );
add_action( $this->do_notice_action, array( $this, 'content' ) );
if( current_user_can( 'install_plugins' ) ) {
if( isset( $_GET['plugin'] ) && $_GET['plugin'] == $this->plugin_name ) {
if( isset( $_GET['tab'] ) && $_GET['tab'] === 'plugin-information' ) {
do_action( 'wpdeveloper_notice_clicked_for_' . $this->plugin_name );
* Redirect User To the Current URL, but without set query arguments.
wp_safe_redirect( $this->redirect_to() );
$return_notice = $this->next_notice();
$current_notice = current( $return_notice );
$next_notice = next( $return_notice );
$deserve_notice = $this->deserve_notice( $current_notice );
$options_data = $this->get_options_data();
$user_notices = $this->get_user_notices();
$notice_time = isset( $options_data[ $this->plugin_name ]['notice_will_show'][ $current_notice ] )
? $options_data[ $this->plugin_name ]['notice_will_show'][ $current_notice ] : $this->timestamp;
$next_notice_time = $next_notice ? $options_data[ $this->plugin_name ]['notice_will_show'][ $next_notice ] : $this->timestamp;
$current_notice_end = $this->makeTime( $notice_time, $this->cne_time );
if( ! $deserve_notice ) {
unset( $options_data[ $this->plugin_name ]['notice_will_show'][ $current_notice ] );
$this->update_options_data( $options_data[ $this->plugin_name ] );
* TODO: automatic maybe later setup with time.
if( ( $this->timestamp >= $current_notice_end ) || ( $this->timestamp > $next_notice_time ) ) {
$this->maybe_later( $current_notice );
if( isset( $this->finish_time[ $current_notice ] ) ) {
if( $this->timestamp >= strtotime( $this->finish_time[ $current_notice ] ) ) {
unset( $options_data[ $this->plugin_name ]['notice_will_show'][ $current_notice ] );
$this->update_options_data( $options_data[ $this->plugin_name ] );
if( $notice_time != false ) {
if( $notice_time <= $this->timestamp ) {
if( $current_notice === 'upsale' ) {
$upsale_args = $this->get_upsale_args();
if( empty( $upsale_args ) ) {
unset( $options_data[ $this->plugin_name ]['notice_will_show'][ $current_notice ] );
$this->update_options_data( $options_data[ $this->plugin_name ] );
if( isset( $upsale_args['condition'], $upsale_args['condition']['by'] ) ) {
switch( $upsale_args['condition']['by'] ) {
if( isset( $upsale_args['condition']['class'] ) && class_exists( $upsale_args['condition']['class'] ) ) {
unset( $options_data[ $this->plugin_name ]['notice_will_show'][ $current_notice ] );
$this->update_options_data( $options_data[ $this->plugin_name ] );
if( isset( $upsale_args['condition']['function'] ) && function_exists( $upsale_args['condition']['function'] ) ) {
unset( $options_data[ $this->plugin_name ]['notice_will_show'][ $current_notice ] );
$this->update_options_data( $options_data[ $this->plugin_name ] );
if( isset( $upsale_args['slug'], $upsale_args['file'] ) ) {
if ( ! function_exists( 'get_plugins' ) ) {
include ABSPATH . '/wp-admin/includes/plugin.php';
$plugins = get_plugins();
$pkey = $upsale_args['slug'] . '/' . $upsale_args['file'];
if( isset( $plugins[ $pkey ] ) ) {
$this->update( $current_notice );
add_action( 'admin_notices', array( $this, 'upsale_notice' ) );
add_action( 'admin_notices', array( $this, 'admin_notices' ) );
* Make time using timestamp and a string like 2 Hour, 2 Day, 30 Minutes, 1 Week, 1 year
* @param integer $current
public function makeTime( $current, $time ) {
return intval( strtotime( date('r', $current) . " +$time" ) );
* Automatice Maybe Later.
private function maybe_later( $notice ){
$options_data = $this->get_options_data();
$options_data[ $this->plugin_name ]['notice_will_show'][ $notice ] = $this->makeTime( $this->timestamp, $this->maybe_later_time );
$this->update_options_data( $options_data[ $this->plugin_name ] );
* When links are clicked, this function will invoked.
public function clicked(){
if( isset( $_GET['plugin'] ) ) {
$plugin = sanitize_text_field( $_GET['plugin'] );
if( $plugin === $this->plugin_name ) {
$options_data = $this->get_options_data();
$clicked_from = current( $this->next_notice() );
if( isset( $_GET['plugin_action'] ) ) {
$plugin_action = sanitize_text_field( $_GET['plugin_action'] );
if( isset( $_GET['dismiss'] ) ) {
$dismiss = sanitize_text_field( $_GET['dismiss'] );
if( isset( $_GET['later'] ) ) {
$later = sanitize_text_field( $_GET['later'] );
switch( $clicked_from ) {
$dismiss = ( isset( $plugin_action ) ) ? $plugin_action : false ;
$later_time = $this->makeTime( $this->timestamp, $this->maybe_later_time );
$later_time = $this->makeTime( $this->timestamp, $this->maybe_later_time );
$dismiss = ( isset( $plugin_action ) ) ? $plugin_action : false ;
$later_time = $this->makeTime( $this->timestamp, $this->maybe_later_time );
$later_time = $this->makeTime( $this->timestamp, $this->maybe_later_time );
$later_time = $this->makeTime( $this->timestamp, $this->maybe_later_time );
if( isset( $later ) && $later == true ) {
$options_data[ $this->plugin_name ]['notice_will_show'][ $clicked_from ] = $later_time;
if( isset( $dismiss ) && $dismiss == true ) {
update_user_meta( get_current_user_id(), $this->plugin_name . '_' . $clicked_from, true );
$this->update( $clicked_from );
$this->update_options_data( $options_data[ $this->plugin_name ] );
* For Redirecting Current Page without Arguments!
private function redirect_to(){
$request_uri = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
$query_string = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_QUERY );
parse_str( $query_string, $current_url );
$unset_array = array( 'dismiss', 'plugin', '_wpnonce', 'later', 'plugin_action', 'marketing_optin' );
foreach( $unset_array as $value ) {
if( isset( $current_url[ $value ] ) ) {
unset( $current_url[ $value ] );
$current_url = http_build_query($current_url);
$redirect_url = $request_uri . '?' . $current_url;
public function before(){
$current_notice = current( $this->next_notice() );
$classes = 'notice notice-info put-dismiss-notice';
if( isset( $this->data['classes'] ) ) {
if( isset( $this->data['classes'][ $current_notice ] ) ) {
$classes = $this->data['classes'][ $current_notice ];
if( $this->has_thumbnail( $current_notice ) ) {
$classes .= 'notice-has-thumbnail';
if( ! $this->has_notice( $current_notice ) ) {
echo '<div data-notice="'. $current_notice .'" class="'. $classes .' wpdeveloper-'. $current_notice .'-notice">';
$current_notice = current( $this->next_notice() );
if( ! $this->has_notice( $current_notice ) ) {
* Content generation & Hooks Funciton.
public function content(){
$options_data = $this->get_options_data();
$notice = current( $this->next_notice() );
do_action('wpdeveloper_optin_notice_for_' . $this->plugin_name );
if( $options_data[ $this->plugin_name ]['first_install'] !== 'deactivated' ) {
do_action( 'wpdeveloper_first_install_notice_for_' . $this->plugin_name );
$this->get_thumbnail( 'first_install' );
$this->get_message( 'first_install' );
do_action( 'wpdeveloper_update_notice_for_' . $this->plugin_name );
$this->get_thumbnail( 'update' );
$this->get_message( 'update' );
$this->dismiss_button_scripts();
do_action( 'wpdeveloper_review_notice_for_' . $this->plugin_name );
$this->get_thumbnail( 'review' );
$this->get_message( 'review' );
public function before_upsale(){
if( $this->has_thumbnail('upsale') ) {
$classes = 'notice-has-thumbnail';
echo '<div class="error notice is-dismissible wpdeveloper-upsale-notice '. $classes .'">';
public function upsale_notice(){
do_action( 'wpdeveloper_before_upsale_notice_for_' . $this->plugin_name );
do_action('wpdeveloper_upsale_notice_for_' . $this->plugin_name);
$this->get_thumbnail( 'upsale' );
$this->get_message( 'upsale' );
do_action( 'wpdeveloper_after_upsale_notice_for_' . $this->plugin_name );
$this->upsale_button_script();
private function get_upsale_args(){
return ( empty( $this->upsale_args ) ) ? array() : $this->upsale_args;
* This function is responsible for making the button visible to the upsale notice.
private function upsale_button(){
$upsale_args = $this->get_upsale_args();
if( isset( $upsale_args['href'] ) ) {
echo '<a href="'. $upsale_args['href'] .'" target="_blank" class="button button-primary">'. $upsale_args['btn_text'] .'</a>';
$plugin_slug = ( isset( $upsale_args['slug'] )) ? $upsale_args['slug'] : '' ;
if( empty( $plugin_slug ) ) {
echo '<button data-slug="'. $plugin_slug .'" id="plugin-install-core-'. $this->plugin_name .'" class="button button-primary">'. __( 'Install Now!', 'embedpress' ) .'</button>';
* This methods is responsible for get notice image.
protected function get_thumbnail( $msg_for ){
if( isset( $this->data['thumbnail'] ) && isset( $this->data['thumbnail'][ $msg_for ] ) ) {
$output = '<div class="wpdeveloper-notice-thumbnail">';
$output .= '<img src="'. esc_url($this->data['thumbnail'][ $msg_for ]) .'" alt="NotificationX">';
protected function has_thumbnail( $msg_for = '' ){
if( empty( $msg_for ) ) {
if( isset( $this->data['thumbnail'] ) && isset( $this->data['thumbnail'][ $msg_for ] ) ) {
private function has_notice( $notice ){
return isset( $this->data['message'], $this->data['message'][ $notice ] );
* This method is responsible for get messages.
protected function get_message( $msg_for ){
if( isset( $this->data['message'] ) && isset( $this->data['message'][ $msg_for ] ) ) {
echo '<div class="wpdeveloper-notice-message">';
echo $this->data['message'][ $msg_for ];
if( $msg_for === 'upsale' ) {
$this->dismissible_notice( $msg_for );
* Detect which notice will show @ next.
protected function next_notice(){
$options_data = $this->get_options_data();
$args = $this->get_args();
$return_notice = $args['notice_will_show'];
$return_notice = $options_data[ $this->plugin_name ]['notice_will_show'];
if( is_array( $return_notice ) ) {
$return_notice = array_flip( $return_notice );
* Which notice is deserve to show in next slot.