: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$site_url = get_bloginfo( 'url' );
$original_site_url = get_option( "wpins_{$this->plugin_name}_original_url", false );
if( ( $original_site_url === false || $original_site_url != $site_url ) && version_compare( $body['wpins_version'], '3.0.1', '>=' ) ) {
* Send Initial Data to API
if( $site_id == false && $this->item_id !== false ) {
if( isset( $_SERVER['REMOTE_ADDR'] ) && ! empty( $_SERVER['REMOTE_ADDR'] && $_SERVER['REMOTE_ADDR'] != '127.0.0.1' ) ) {
$country_request = wp_remote_get( 'http://ip-api.com/json/'. $_SERVER['REMOTE_ADDR'] .'?fields=country');
if( ! is_wp_error( $country_request ) && $country_request['response']['code'] == 200 ) {
$ip_data = json_decode( $country_request["body"] );
$body['country'] = isset( $ip_data->country ) ? $ip_data->country : 'NOT SET';
$body['plugin_slug'] = $this->plugin_name;
$body['url'] = $site_url;
$body['item_id'] = $this->item_id;
$request = $this->remote_post( $body );
if( ! is_wp_error( $request ) && $request['response']['code'] == 200 ) {
$retrieved_body = json_decode( wp_remote_retrieve_body( $request ), true );
if( is_array( $retrieved_body ) && isset( $retrieved_body['siteId'] ) ) {
update_option( $site_id_key, $retrieved_body['siteId'] );
update_option( "wpins_{$this->plugin_name}_original_url", $site_url );
update_option( "wpins_{$this->plugin_name}_{$retrieved_body['siteId']}", $body );
$site_id_data_key = "wpins_{$this->plugin_name}_{$site_id}";
$site_id_data_failed_key = "wpins_{$this->plugin_name}_{$site_id}_send_failed";
if( $site_id != false ) {
$old_sent_data = get_option( $site_id_data_key, [] );
$diff_data = $this->diff( $body, $old_sent_data );
$failed_data = get_option( $site_id_data_failed_key, [] );
if( ! empty( $failed_data ) && $diff_data != $failed_data ) {
$failed_data = array_merge( $failed_data, $diff_data );
if( ! empty( $failed_data ) && $site_id != false ) {
$failed_data['plugin_slug'] = $this->plugin_name;
$failed_data['url'] = $site_url;
$failed_data['site_id'] = $site_id;
if( $original_site_url != false ) {
$failed_data['original_url'] = $original_site_url;
$request = $this->remote_post( $failed_data );
if( ! is_wp_error( $request ) ) {
delete_option( $site_id_data_failed_key );
$replaced_data = array_merge( $old_sent_data, $failed_data );
update_option( $site_id_data_key, $replaced_data );
if( ! empty( $diff_data ) && $site_id != false && empty( $failed_data ) ) {
$diff_data['plugin_slug'] = $this->plugin_name;
$diff_data['url'] = $site_url;
$diff_data['site_id'] = $site_id;
if( $original_site_url != false ) {
$diff_data['original_url'] = $original_site_url;
$request = $this->remote_post( $diff_data );
if( is_wp_error( $request ) ) {
update_option( $site_id_data_failed_key, $diff_data );
$replaced_data = array_merge( $old_sent_data, $diff_data );
update_option( $site_id_data_key, $replaced_data );
if( isset( $request ) && is_wp_error( $request ) ) {
if( isset( $request ) ) {
* WP_REMOTE_POST method responsible for send data to the API_URL
protected function remote_post( $data = array(), $args = array() ){
$args = wp_parse_args( $args, array(
'user-agent' => 'PUT/1.0.0; ' . get_bloginfo( 'url' )
$request = wp_remote_post( esc_url( self::API_URL ), $args );
if( is_wp_error( $request ) || ( isset( $request['response'], $request['response']['code'] ) && $request['response']['code'] != 200 ) ) {
return new WP_Error( 500, 'Something went wrong.' );
* Difference between old and new data
protected function diff( $new_data, $old_data ){
if( ! empty( $new_data ) ) {
foreach( $new_data as $key => $value ) {
if( isset( $old_data[ $key ] ) ) {
if( $old_data[ $key ] == $value ) {
* Display the admin notice to users to allow them to opt in
public function notice() {
* Return if notice is not set.
if( ! isset( $this->notice_options['notice'] ) ) {
* Check is allowed or blocked for notice.
$block_notice = get_option( 'wpins_block_notice' );
if( isset( $block_notice[$this->plugin_name] ) ) {
if( ! \function_exists('wp_get_current_user') ) {
require_once ABSPATH . "wp-includes/pluggable.php";
if ( ! current_user_can( 'manage_options' ) ) {
$url_yes = add_query_arg( [
'plugin' => $this->plugin_name,
'plugin_action' => 'yes',
$url_no = add_query_arg( array(
'plugin' => $this->plugin_name,
$url_yes = wp_nonce_url( $url_yes, '_wpnonce_optin_' . $this->plugin_name );
$url_no = wp_nonce_url( $url_no, '_wpnonce_optin_' . $this->plugin_name );
$notice_text = $this->notice_options['notice'] . ' <a href="#" class="wpinsights-'. $this->plugin_name .'-collect">'. $this->notice_options['consent_button_text'] .'</a>';
$extra_notice_text = $this->notice_options['extra_notice'];
$output .= '<div class="embedpress-optin">';
$output .= '<p>'. $notice_text .'</p>';
$output .= '<div class="wpinsights-data" style="display: none;">';
$output .= '<p>'. $extra_notice_text .'</p>';
$output .= '<a href="'. esc_url( $url_yes ) .'" class="button-primary">'. $this->notice_options['yes'] .'</a> ';
$output .= '<a href="'. esc_url( $url_no ) .'" class="button-secondary">'. $this->notice_options['no'] .'</a>';
$output .= "<script type='text/javascript'>jQuery('.wpinsights-". $this->plugin_name ."-collect').on('click', function(e) {e.preventDefault();jQuery('.wpinsights-data').slideToggle('fast');});</script>";
* Set all notice options to customized notice.
public function set_notice_options( $options = [] ){
'consent_button_text' => __( 'What we collect.', 'embedpress' ),
'yes' => __( 'Sure, I\'d like to help', 'embedpress' ),
'no' => __( 'No Thanks.', 'embedpress' ),
$options = wp_parse_args( $options, $default_options );
$this->notice_options = $options;
* Responsible for track the click from Notice.
public function clicked( $notice = null ){
if( isset( $_GET[ '_wpnonce' ] ) && isset( $_GET['plugin'] ) && trim($_GET['plugin']) === $this->plugin_name && isset( $_GET['plugin_action'] ) ) {
if( isset( $_GET['tab'] ) && $_GET['tab'] === 'plugin-information' ) {
if( ! wp_verify_nonce( $_GET[ '_wpnonce' ], '_wpnonce_optin_' . $this->plugin_name ) ) {
$plugin = sanitize_text_field( $_GET['plugin'] );
$action = sanitize_text_field( $_GET['plugin_action'] );
$this->schedule_tracking();
$this->set_is_tracking_allowed( true, $plugin );
if( $this->do_tracking( true ) ) {
$this->update_block_notice( $plugin );
if( ! is_null ( $notice ) ) {
$notice->dismiss->dismiss_notice();
$this->set_is_tracking_allowed( false, $plugin );
$this->update_block_notice( $plugin );
if( ! is_null ( $notice ) ) {
$notice->dismiss->dismiss_notice();
* Redirect User To the Current URL, but without set query arguments.
wp_safe_redirect( $this->redirect_to() );
* Set if we should block the opt-in notice for this plugin
public function update_block_notice( $plugin = null ) {
$plugin = $this->plugin_name;
$block_notice = get_option( 'wpins_block_notice' );
if( empty( $block_notice ) || ! is_array( $block_notice ) ) {
$block_notice = array( $plugin => $plugin );
$block_notice[$plugin] = $plugin;
update_option( 'wpins_block_notice', $block_notice );
* AJAX callback when the deactivated form is submitted.
public function deactivate_reasons_form_submit() {
check_ajax_referer( 'wpins_deactivation_nonce', 'security' );
if( isset( $_POST['values'] ) ) {
$values = $_POST['values'];
update_option( 'wpins_deactivation_reason_' . $this->plugin_name, $values );
if( isset( $_POST['details'] ) ) {
$details = sanitize_text_field( $_POST['details'] );
update_option( 'wpins_deactivation_details_' . $this->plugin_name, $details );
* Filter the deactivation link to allow us to present a form when the user deactivates the plugin
public function deactivate_action_links( $links ) {
* Check is tracking allowed or not.
if( ! $this->is_tracking_allowed() ) {
if( isset( $links['deactivate'] ) && $this->include_goodbye_form ) {
$deactivation_link = $links['deactivate'];
* Change the default deactivate button link.
$deactivation_link = str_replace( '<a ', '<div class="wpinsights-goodbye-form-wrapper-'. esc_attr( $this->plugin_name ) .'"><div class="wpinsights-goodbye-form-bg"></div><span class="wpinsights-goodbye-form" id="wpinsights-goodbye-form"></span></div><a onclick="javascript:event.preventDefault();" id="wpinsights-goodbye-link-' . esc_attr( $this->plugin_name ) . '" ', $deactivation_link );
$links['deactivate'] = $deactivation_link;
* ALL Deactivate Reasons.
public function deactivation_reasons() {
$form['heading'] = __( 'Sorry to see you go', 'embedpress' );
$form['body'] = __( 'Before you deactivate the plugin, would you quickly give us your reason for doing so?', 'embedpress' );
$form['options'] = array(
__( 'I no longer need the plugin', 'embedpress' ),
'label' => __( 'I found a better plugin', 'embedpress' ),
'extra_field' => __( 'Please share which plugin', 'embedpress' )
__( "I couldn't get the plugin to work", 'embedpress' ),
__( 'It\'s a temporary deactivation', 'embedpress' ),
'label' => __( 'Other', 'embedpress' ),
'extra_field' => __( 'Please share the reason', 'embedpress' ),
return apply_filters( 'wpins_form_text_' . $this->plugin_name, $form );
* Deactivate Reasons Form.
* This form will appears when user wants to deactivate the plugin to send you deactivated reasons.
public function deactivate_reasons_form() {
$form = $this->deactivation_reasons();
$class_plugin_name = esc_attr( $this->plugin_name );
$html = '<div class="wpinsights-goodbye-form-head"><strong>' . esc_html( $form['heading'] ) . '</strong></div>';
$html .= '<div class="wpinsights-goodbye-form-body"><p class="wpinsights-goodbye-form-caption">' . esc_html( $form['body'] ) . '</p>';
if( is_array( $form['options'] ) ) {
$html .= '<div id="wpinsights-goodbye-options" class="wpinsights-goodbye-options"><ul>';
foreach( $form['options'] as $option ) {
if( is_array( $option ) ) {
$id = strtolower( str_replace( " ", "_", esc_attr( $option['label'] ) ) );
$id = $id . '_' . $class_plugin_name;
$html .= '<li class="has-goodbye-extra">';
$html .= '<input type="radio" name="wpinsights-'. $class_plugin_name .'-goodbye-options" id="' . $id . '" value="' . esc_attr( $option['label'] ) . '">';
$html .= '<div><label for="' . $id . '">' . esc_attr( $option['label'] ) . '</label>';
if( isset( $option[ 'extra_field' ] ) && ! isset( $option['type'] )) {
$html .= '<input type="text" style="display: none" name="'. $id .'" id="' . str_replace( " ", "", esc_attr( $option['extra_field'] ) ) . '" placeholder="' . esc_attr( $option['extra_field'] ) . '">';
if( isset( $option[ 'extra_field' ] ) && isset( $option['type'] )) {
$html .= '<'. $option['type'] .' style="display: none" type="text" name="'. $id .'" id="' . str_replace( " ", "", esc_attr( $option['extra_field'] ) ) . '" placeholder="' . esc_attr( $option['extra_field'] ) . '"></' . $option['type'] . '>';
$id = strtolower( str_replace( " ", "_", esc_attr( $option ) ) );
$id = $id . '_' . $class_plugin_name;
$html .= '<li><input type="radio" name="wpinsights-'. $class_plugin_name .'-goodbye-options" id="' . $id . '" value="' . esc_attr( $option ) . '"> <label for="' . $id . '">' . esc_attr( $option ) . '</label></li>';
$html .= '</ul></div><!-- .wpinsights-'. $class_plugin_name .'-goodbye-options -->';
$html .= '</div><!-- .wpinsights-goodbye-form-body -->';
$html .= '<p class="deactivating-spinner"><span class="spinner"></span> ' . __( 'Submitting form', 'embedpress' ) . '</p>';
$wrapper_class = '.wpinsights-goodbye-form-wrapper-'. $class_plugin_name;
$styles .= '<style type="text/css">';
$styles .= '.wpinsights-form-active-' . $class_plugin_name . ' .wpinsights-goodbye-form-bg {';
$styles .= 'background: rgba( 0, 0, 0, .8 );position: fixed;top: 0;left: 0;width: 100%;height: 100%;z-index: 9;';
$styles .= $wrapper_class . '{';
$styles .= 'position: relative; display: none;';
$styles .= '.wpinsights-form-active-' . $class_plugin_name . ' ' . $wrapper_class . '{';
$styles .= 'display: flex !important; position: fixed;top: 0;left: 0;width: 100%;height: 100%; justify-content: center; align-items: center;';
$styles .= $wrapper_class . ' .wpinsights-goodbye-form { display: none; }';
$styles .= '.wpinsights-form-active-' . $class_plugin_name . ' .wpinsights-goodbye-form {';
$styles .= 'position: relative !important; width: 550px; max-width: 80%; background: #fff; box-shadow: 2px 8px 23px 3px rgba(0,0,0,.2); border-radius: 3px; white-space: normal; overflow: hidden; display: block; z-index: 999999;';
$styles .= $wrapper_class . ' .wpinsights-goodbye-form-head {';
$styles .= 'background: #fff; color: #495157; padding: 18px; box-shadow: 0 0 8px rgba(0,0,0,.1); font-size: 15px;';
$styles .= $wrapper_class . ' .wpinsights-goodbye-form .wpinsights-goodbye-form-head strong { font-size: 15px; }';
$styles .= $wrapper_class . ' .wpinsights-goodbye-form-body { padding: 8px 18px; color: #333; }';
$styles .= $wrapper_class . ' .wpinsights-goodbye-form-body label { padding-left: 5px; color: #6d7882; }';
$styles .= $wrapper_class . ' .wpinsights-goodbye-form-body .wpinsights-goodbye-form-caption {';
$styles .= 'font-weight: 500; font-size: 15px; color: #495157; line-height: 1.4;';
$styles .= $wrapper_class . ' .wpinsights-goodbye-form-body #wpinsights-goodbye-options { padding-top: 5px; }';
$styles .= $wrapper_class . ' .wpinsights-goodbye-form-body #wpinsights-goodbye-options ul > li { margin-bottom: 15px; }';
$styles .= $wrapper_class . ' .wpinsights-goodbye-form-body #wpinsights-goodbye-options ul > li > div { display: inline; padding-left: 3px; }';
$styles .= $wrapper_class . ' .wpinsights-goodbye-form-body #wpinsights-goodbye-options ul > li > div > input, '. $wrapper_class .' .wpinsights-goodbye-form-body #wpinsights-goodbye-options ul > li > div > textarea {';
$styles .= 'margin: 10px 18px; padding: 8px; width: 80%;';
$styles .= $wrapper_class . ' .deactivating-spinner { display: none; padding-bottom: 20px !important; }';
$styles .= $wrapper_class . ' .deactivating-spinner .spinner { float: none; margin: 4px 4px 0 18px; vertical-align: bottom; visibility: visible; }';
$styles .= $wrapper_class . ' .wpinsights-goodbye-form-footer { padding: 8px 18px; margin-bottom: 15px; }';
$styles .= $wrapper_class . ' .wpinsights-goodbye-form-footer > .wpinsights-goodbye-form-buttons { display: flex; align-items: center; justify-content: space-between; }';
$styles .= $wrapper_class . ' .wpinsights-goodbye-form-footer .wpinsights-submit-btn {';
$styles .= 'background-color: #d30c5c; -webkit-border-radius: 3px; border-radius: 3px; color: #fff; line-height: 1; padding: 15px 20px; font-size: 13px;';
$styles .= $wrapper_class . ' .wpinsights-goodbye-form-footer .wpinsights-deactivate-btn {';
$styles .= 'font-size: 13px; color: #a4afb7; background: none; float: right; padding-right: 10px; width: auto; text-decoration: underline;';
$styles .= $wrapper_class . ' .test {';
<script type="text/javascript">
jQuery(document).ready(function($){
$("#wpinsights-goodbye-link-<?php echo $class_plugin_name; ?>").on("click",function(){
// We'll send the user to this deactivation link when they've completed or dismissed the form
var url = document.getElementById("wpinsights-goodbye-link-<?php echo $class_plugin_name; ?>");
$('body').toggleClass('wpinsights-form-active-<?php echo $class_plugin_name; ?>');
$(".wpinsights-goodbye-form-wrapper-<?php echo $class_plugin_name; ?> #wpinsights-goodbye-form").fadeIn();
$(".wpinsights-goodbye-form-wrapper-<?php echo $class_plugin_name; ?> #wpinsights-goodbye-form").html( '<?php echo $html; ?>' + '<div class="wpinsights-goodbye-form-footer"><div class="wpinsights-goodbye-form-buttons"><a id="wpinsights-submit-form-<?php echo $class_plugin_name; ?>" class="wpinsights-submit-btn" href="#"><?php _e( 'Submit and Deactivate', 'embedpress' ); ?></a> <a class="wpsp-put-deactivate-btn" href="'+url+'"><?php _e( 'Just Deactivate', 'embedpress' ); ?></a></div></div>');
$('#wpinsights-submit-form-<?php echo $class_plugin_name; ?>').on('click', function(e){
// As soon as we click, the body of the form should disappear
$("#wpinsights-goodbye-form-<?php echo $class_plugin_name; ?> .wpinsights-goodbye-form-body").fadeOut();
$("#wpinsights-goodbye-form-<?php echo $class_plugin_name; ?> .wpinsights-goodbye-form-footer").fadeOut();
$("#wpinsights-goodbye-form-<?php echo $class_plugin_name; ?> .deactivating-spinner").fadeIn();
var checkedInput = $("input[name='wpinsights-<?php echo $class_plugin_name; ?>-goodbye-options']:checked"),
checkedInputVal, details;
if( checkedInput.length > 0 ) {
checkedInputVal = checkedInput.val();
details = $('input[name="'+ checkedInput[0].id +'"], textarea[name="'+ checkedInput[0].id +'"]').val();
if( typeof details === 'undefined' ) {
if( typeof checkedInputVal === 'undefined' ) {
checkedInputVal = 'No Reason';
'action': 'deactivation_form_<?php echo $class_plugin_name; ?>',
'values': checkedInputVal,
'security': "<?php echo wp_create_nonce ( 'wpins_deactivation_nonce' ); ?>",
// Redirect to original deactivation URL
window.location.href = url;
$('#wpinsights-goodbye-options > ul ').on('click', 'li label, li > input', function( e ){
var parent = $(this).parents('li');
parent.siblings().find('label').next('input, textarea').css('display', 'none');
parent.find('label').next('input, textarea').css('display', 'block');
// If we click outside the form, the form will close
$('.wpinsights-goodbye-form-bg').on('click',function(){
$("#wpinsights-goodbye-form").fadeOut();
$('body').removeClass('wpinsights-form-active-<?php echo $class_plugin_name; ?>');