: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
Contributors: galdub, tomeraharon
Description: Use Poptin to get more leads, sales, and email subscribers. Create targeted beautiful pop ups and forms in less than 2 minutes with ease.
Author URI: https://www.poptin.com
// Prevent direct file access
use Hummingbird\Core\Utils;
if (!defined('ABSPATH')) {
define('POPTIN_VERSION', '1.3.2');
define('POPTIN_PATH', dirname(__FILE__));
define('POPTIN_PATH_INCLUDES', dirname(__FILE__) . '/inc');
define('POPTIN_FOLDER', basename(POPTIN_PATH));
define('POPTIN_URL', plugins_url() . '/' . POPTIN_FOLDER);
define('POPTIN_URL_INCLUDES', POPTIN_URL . '/inc');
define('POPTIN_ID', get_option('poptin_id'));
define('POPTIN_USER_ID', get_option('poptin_user_id'));
define('POPTIN_MARKETPLACE_TOKEN', get_option('poptin_marketplace_token'));
define('POPTIN_MARKETPLACE_EMAIL_ID', get_option('poptin_marketplace_email_id'));
define('POPTIN_FRONT_SITE', 'https://www.poptin.com');
define('POPTIN_MARKETPLACE', 'Wrdprs');
define('POPTIN_MARKETPLACE_LOGIN_URL', 'https://app.popt.in/api/marketplace/auth');
define('POPTIN_MARKETPLACE_REGISTER_URL', 'https://app.popt.in/api/marketplace/register');
define('POPTIN_CACERT_PATH', POPTIN_PATH . "/assets/ca-cert/cacert-2017-06-07.pem");
include_once "class-affiliate.php";
public function __construct()
register_activation_hook(__FILE__, 'poptin_activation_hook');
register_deactivation_hook(__FILE__, 'poptin_deactivation_hook');
add_action('admin_enqueue_scripts', array($this, 'poptin_add_admin_javascript'));
add_action('admin_enqueue_scripts', array($this, 'poptin_add_admin_css'));
// register admin pages for the plugin
add_action('admin_menu', array($this, 'poptin_admin_pages_callback'));
add_action('plugins_loaded', array($this, 'poptin_add_textdomain'));
$poptinidcheck = get_option('poptin_id', (isset($myOption_def) ? $myOption_def : false));
$poptinid = get_option('poptin_id');
if (strlen($poptinid) != 13) {
update_option('poptin_id', '');
add_action('wp_head', array($this, 'poptin_add_script_frontend'));
// Add actions for storing value and fetching URL
// use the wp_ajax_nopriv_ hook for non-logged users (handle guest actions)
* AJAX Calls registration
* Action => name followed after wp_ajax
add_action('wp_ajax_poptin_register', array($this, 'poptin_marketplace_registration'));
add_action('wp_ajax_poptin_logmein', array($this, 'poptin_markplace_login'));
add_action('wp_ajax_delete-id', array($this, 'delete_poptin_id'));
add_action('wp_ajax_add-id', array($this, 'add_poptin_id'));
* Admin Initialization calls registration
* We need this to send user to Poptin's Admin page on activation
add_action('admin_init', 'poptin_plugin_redirect');
add_filter('admin_footer_text', array($this, 'replace_footer_text'));
* Admin Initialization calls registration
* We need this to send user to Poptin's Admin page on activation
if (isset($_GET['poptin_logmein'])) {
if (!function_exists('is_user_logged_in')) {
require_once(ABSPATH . "wp-includes/pluggable.php");
if (is_user_logged_in()) {
if (current_user_can('administrator')) {
$after_registration = '';
if (isset($_GET['after_registration'])) {
$after_registration = $_GET['after_registration'];
$this->poptin_markplace_login_direct($after_registration);
echo '<style>html {background: #f1f1f1;}body{margin:0;padding:0;}h1 {background: #fff;font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;padding: 1em 2em;-webkit-box-shadow: 0 1px 3px rgba(0,0,0,0.13);text-align:center;color: #666;font-size: 24px;margin: 30px auto 0;padding:20px;display:table;border-radius:5px}</style>';
echo '<h1>Please login as administrator</h1>';
wp_redirect(wp_login_url());
* Not sure why is this here
add_filter('clean_url', 'async_scripts', 11, 1);
add_action('admin_footer', array($this, 'deactivate_modal'));
add_action('wp_ajax_poptin_plugin_deactivate', array($this, 'poptin_plugin_deactivate'));
* Retrieve the original footer text
private function get_original_text()
/* The way of determining the default footer text was changed in 3.9 */
if (version_compare($wp_version, '3.9', '<')) {
$text = __('Thank you for creating with <a href="http://wordpress.org/">WordPress</a>.');
/* translators: %s: https://wordpress.org/ */
$text = sprintf(__('Thank you for creating with <a href="%s">WordPress</a>.'), __('https://wordpress.org/'));
* Replace the admin footer text
* @param string $footer_text The current footer text
* @return string The new footer text
function replace_footer_text($footer_text)
return str_replace($this->get_original_text(), '', $footer_text);
public function poptin_plugin_deactivate()
if (current_user_can('manage_options')) {
$response['message'] = "";
$reason = filter_input(INPUT_POST, 'reason');
$nonce = filter_input(INPUT_POST, 'nonce');
$response['message'] = "Please provide reason";
} else if (empty($nonce)) {
$response['message'] = esc_html__("Your request is not valid", 'poptin');
if (!wp_verify_nonce($nonce, 'poptin_deactivate_nonce')) {
$response['message'] = esc_html__("Your request is not valid", 'poptin');
if ($errorCounter == 0) {
$email = "none@none.none";
if (isset($postData['email_id']) && !empty($postData['email_id']) && filter_var($postData['email_id'], FILTER_VALIDATE_EMAIL)) {
$email = $postData['email_id'];
$user_name = $current_user->first_name . " " . $current_user->last_name;
$subject = "Poptin was removed from {$domain}";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$headers .= 'From: ' . $user_name . ' <' . $email . '>' . PHP_EOL;
$headers .= 'Reply-To: ' . $user_name . ' <' . $email . '>' . PHP_EOL;
$headers .= 'X-Mailer: PHP/' . phpversion();
<table border="0" cellspacing="0" cellpadding="5">
<td><?php echo esc_attr(POPTIN_VERSION) ?></td>
<td><?php echo esc_url($domain) ?></td>
<td><?php echo esc_attr($email) ?></td>
<td><?php echo nl2br(esc_attr($reason)) ?></td>
<th>WordPress Version</th>
<td><?php echo esc_attr(get_bloginfo('version')) ?></td>
<td><?php echo esc_attr(PHP_VERSION) ?></td>
$content = ob_get_clean();
$email_id = "contact@poptin.on.crisp.email";
wp_mail($email_id, $subject, $content, $headers);
echo json_encode($response);
public function deactivate_modal()
if (current_user_can('manage_options')) {
if ('plugins.php' !== $pagenow) {
include 'deactivate-form.php';
* Function: poptin_marketplace_registration
* Description: Will be called via the Admin Page AJAX
* Will be checked with WP nounce.
* If the verification is OK, we go ahead and create the account.
* Email Address - Would be pre-filled in the form in the Admin Page.
* User wants, can change the email id.
* We store the registration email ID, to ensure that we do not have issues in future.
* Basic wrapper function to the poptin_middleware_registration_curl
* Responds in JSON from the cURL call.
* Parameters: email (argument)
* domain - retrieved from the Wordpress base.
* first_name - derived from the nice_name of the existing logged in user.
* last_name - derived from the nice_name of the existing logged in user.
* Return: Return response is derived directly from the chain function poptin_middleware_registration_curl
function poptin_marketplace_registration()
if (!current_user_can('manage_options')) {
die('You are now allowed to do this.');
$email = sanitize_email($_POST['email']);
* We check the sanitization here again for the email id.
* This is for AJAX call, hence the double check is required.
* If this is okay, we go ahead and send the data poptin_marketplace_registration function.
$return_array['success'] = false;
$return_array['message'] = 'Invalid Email Address found.';
echo json_encode($return_array);
if (check_ajax_referer('poptin-fe-register', 'security')) {
if (!function_exists('wp_get_current_user')) {
require_once(ABSPATH . "wp-includes/pluggable.php");
$user_data = wp_get_current_user();
$user_nice_name = $user_data->data->user_nicename;
$user_nice_name_array = explode(" ", $user_nice_name);
$first_name = $user_nice_name_array[0];
if (isset($user_nice_name_array[1])) {
$last_name = $user_nice_name_array[1];
$last_name = $user_nice_name_array[0];
$this->poptin_middleware_registration_curl($first_name, $last_name, $domain, $email);
$return_array['success'] = false;
$return_array['message'] = 'Invalid request. Please refresh & try again.';
echo json_encode($return_array);
* Function: poptin_markplace_login_direct
* Description: Based on the Options stored in the WP database
* We make request to the marketplace api for login
* In simpler terms this is a wrapper function for making AJAX call -> to cURL call -> to respond back.
* Parameters: POST Data NOT required
* - token [Generated at the time of registration from the marketplace API ONLY]
* - email [Email ID used at the time of registration from the marketplace API ONLY]
* Return: login_url - if it went successful
function poptin_markplace_login_direct($after_registration = '')
$token = POPTIN_MARKETPLACE_TOKEN;
$user_id = POPTIN_USER_ID;
$curl_URL = POPTIN_MARKETPLACE_LOGIN_URL;
$curl_post_array = array(
$curl_options = $this->generate_curl_options($curl_URL, $curl_post_array);
curl_setopt_array($curl, $curl_options);
$response = curl_exec($curl);
$err = curl_error($curl);
$response_return_array = array();
$response_return_array['success'] = false;
echo json_encode($response_return_array);
$response_array = json_decode($response);
if ($response_array->success) {
$login_url = $response_array->login_url;
// If user just registered
if ($after_registration != '') {
$login_url .= '&utm_source=wordpress';
header("Location: " . $login_url);
exit(wp_redirect("admin.php?page=Poptin"));
exit(wp_redirect("admin.php?page=Poptin"));
* Function: poptin_add_admin_javascript
* Description: Will be called via the Admin Page AJAX
* Will be checked with WP nounce.
* If the verification is OK, we go ahead and create the account.
* Email Address - Would be pre-filled in the form in the Admin Page.
* User wants, can change the email id.
* We store the registration email ID, to ensure that we do not have issues in future.
* Basic wrapper function to the poptin_middleware_registration_curl
* Responds in JSON from the cURL call.
* Parameters: email (argument)
* domain - retrieved from the Wordpress base.
* first_name - derived from the nice_name of the existing logged in user.
* last_name - derived from the nice_name of the existing logged in user.
* Return: Return response is derived directly from the chain function poptin_middleware_registration_curl
public function poptin_add_admin_javascript($hook)
if ('toplevel_page_Poptin' === $hook) {
wp_enqueue_script('jquery');
wp_register_script('poptin-admin', plugins_url('assets/js/poptin-admin.js', __FILE__), array('jquery'), '1.0.6', true);
wp_enqueue_script('poptin-admin');
wp_register_script('bootstrap-modal', plugins_url('assets/js/bootstrap.min.js', __FILE__), array('jquery'), '1.0', true);
wp_enqueue_script('bootstrap-modal');
* Function: poptin_add_script_frontend
* Description: Will add the Poptin JS code to the system.
public function poptin_add_script_frontend()
echo "<script id='pixel-script-poptin' src='https://cdn.popt.in/pixel.js?id=" . POPTIN_ID . "' async='true'></script> ";
* Function: poptin_add_admin_css
* Description: Will add the backend CSS required for the display of poptin settings page.
* Parameters: hook | Not used.
public function poptin_add_admin_css($hook)
if ('toplevel_page_Poptin' === $hook) {
wp_register_style('poptin-admin', plugins_url('assets/css/poptin-admin.css', __FILE__), array(), '1.1');
wp_enqueue_style('poptin-admin');
wp_register_style('bootstrap-modal-css', plugins_url('assets/css/bootstrap.min.css', __FILE__), array(), '1.0');
wp_enqueue_style('bootstrap-modal-css');
* Function: poptin_admin_pages_callback
* Description: Will add the Poptin Page into the Menu System of Wordpress
public function poptin_admin_pages_callback()
//$this->check_if_poptin_is_connected();
add_menu_page(__("Poptin", 'ppbase'), __("Poptin", 'ppbase'), 'manage_options', 'Poptin', array($this, 'poptin_admin_view'), POPTIN_URL . '/assets/images/menu-icon.png');
* Function: poptin_admin_view
* Description: The URL link is added to render the view setup as per the function
public function poptin_admin_view()
include_once(POPTIN_PATH . '/views/poptin_admin_view.php');
* Function: poptin_add_textdomain
public function poptin_add_textdomain()
load_plugin_textdomain('poptin', false, dirname(plugin_basename(__FILE__)) . '/lang/');
* Function: delete_poptin_id
* Description: AJAX wrapper for removing Poptin ID
function delete_poptin_id()
if (!current_user_can('manage_options')) {
die('You now allowed to do this.');
if (!isset($_POST['data']['nonce']) || !wp_verify_nonce($_POST['data']['nonce'], "ppFormIdDeactivate")) {
die('You now allowed to do this.');
update_option('poptin_id', '');
update_option('poptin_marketplace_token', '');
update_option('poptin_marketplace_email_id', '');
update_option('poptin_user_id', '');
poptin_clear_all_caches();
'message' => 'Database updated successfully.'