: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Function: add_poptin_id
* Description: AJAX wrapper for adding Poptin ID, only used when user enters the Poptin ID manually.
if (!current_user_can('manage_options')) {
die('You now allowed to do this.');
if (!isset($_POST['data']['nonce']) || !wp_verify_nonce($_POST['data']['nonce'], "ppFormIdRegister")) {
die('You now allowed to do this.');
if (isset($_POST['data']) && isset($_POST['data']['poptin_id'])) {
$id = $_POST['data']['poptin_id'];
update_option('poptin_id', $id);
poptin_clear_all_caches();
'message' => 'Database updated successfully.'
* Function: poptin_middleware_registration_curl
private function poptin_middleware_registration_curl($first_name, $last_name, $domain, $email)
* Because Wordpress doesn't provide one
* We will rely on the Middleware's Country Code for this one
* Overriding Country Code
* Not sending First + Last Name as per Gal Dubinski
* first_name => $first_name,
$curl_URL = POPTIN_MARKETPLACE_REGISTER_URL;
$curl_post_array = array(
'marketplace' => POPTIN_MARKETPLACE,
$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;
$response_return_array['message'] = "Internal error occurred. Please try again later.";
echo json_encode($response_return_array);
$response_array = json_decode($response);
if ($response_array->success) {
$response_return_array['success'] = true;
$response_return_array['message'] = "Registration successful";
$response_return_array['js_client_id'] = $response_array->client_id;
$response_return_array['user_token'] = $response_array->token;
* We setup the update options
update_option("poptin_id", $response_array->client_id);
update_option("poptin_user_id", $response_array->user_id);
update_option("poptin_marketplace_token", $response_array->token);
update_option("poptin_marketplace_email_id", $email);
poptin_clear_all_caches();
echo json_encode($response_return_array);
$response_return_array['success'] = false;
$response_return_array['message'] = $response_array->message;
echo json_encode($response_return_array);
* Function: generate_curl_options
* Description: This is Utility Function generates the POST cURL calls options.
* Have placed a function to ensure it remains generic and updates do not require many changes.
* Uses the CA Cert certificate.
* Return: Array | Options Array for cURL Post method call.
private function generate_curl_options($curl_URL, $curl_post_array)
$curl_options_array = array(
CURLOPT_URL => $curl_URL,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $curl_post_array,
CURLOPT_CAINFO => POPTIN_CACERT_PATH
return $curl_options_array;
* Function: poptin_shortcode
* Description: Converts the content value to poptin div.
* [poptin-embed 123456789] => <div class='poptin-123456789'></div>
* Return: Echo of generated <div></div>
function poptin_shortcode($arguments)
if(isset($arguments[0]) && !empty($arguments[0])) {
$poptin_div_id = $arguments[0];
return "<div class='poptin-'".esc_attr($poptin_div_id)."'></div>";
// add_shortcode('poptin-embed', 'poptin_shortcode');
* Function: poptin_shortcode_form
* Description: Converts the content value to poptin form.
* [poptin-form 123456789] => <div class="poptin-embedded" data-id="123456789"></div>
* Return: Echo of generated <div></div>
function poptin_shortcode_form($arguments)
if(isset($arguments[0]) && !empty($arguments[0])) {
$poptin_div_id = $arguments[0];
return "<div class='poptin-embedded' data-id='" . esc_attr($poptin_div_id) . "'></div>";
add_shortcode('poptin-form', 'poptin_shortcode_form');
* Function: async_scripts
* Description: Async URL for changes from asyncload to async='async'
function async_scripts($url)
if (strpos($url, '#asyncload') === false)
return str_replace('#asyncload', '', $url);
return str_replace('#asyncload', '', $url) . "' async='async";
* Function: poptin_plugin_redirect
* Description: Called via admin_init action in Constructor
* Will redirect to the plugin page if the poptin_plugin_redirection is setup.
* Once redirection is pushed, the key is removed.
function poptin_plugin_redirect()
if (!defined("DOING_AJAX") && get_option('poptin_plugin_redirection', false)) {
delete_option('poptin_plugin_redirection');
exit(wp_redirect("admin.php?page=Poptin"));
* Function: poptin_activation_hook
* Description: On installation of the plugin this will be called.
* We want to setup/update poptin related options at this time.
* Options to change to blank
* - poptin_id [Poptin ID used for JS injection]
* - poptin_marketplace_token [Poptin Marketplace Token | Generated at the time of registration from the plugin ONLY]
* - poptin_marketplace_email_id [Poptin Marketplace Email ID | used at the time of registration from the plugin ONLY]
function poptin_activation_hook()
* We want these three options to be blank on activation/installation of the plugin
add_option('poptin_id', '', '', 'yes');
add_option("poptin_marketplace_token", "", '', 'yes');
add_option("poptin_marketplace_email_id", "", '', 'yes');
add_option("poptin_user_id", "", '', 'yes');
* We want to take the user to the Plugin Page on installation.
* Hence setting up a temporary redirection key.
* It gets removed as soon as it's called for the first time.
* Ussage at : poptin_plugin_redirect, and called with admin_init
if(!defined("DOING_AJAX")) {
add_option('poptin_plugin_redirection', true);
* Function: poptin_decativation_hook
* Description: On deactivation of the plugin this will be called.
* We want to delete poptin related options at this time.
* Options to change to remove
* - poptin_id [Poptin ID used for JS injection]
* - poptin_marketplace_token [Poptin Marketplace Token | Generated at the time of registration from the plugin ONLY]
* - poptin_marketplace_email_id [Poptin Marketplace Email ID | used at the time of registration from the plugin ONLY]
function poptin_deactivation_hook()
delete_option('poptin_id');
delete_option('poptin_marketplace_token');
delete_option('poptin_marketplace_email_id');
delete_option('poptin_user_id');
* If At all this was not removed already
delete_option('poptin_plugin_redirection');
poptin_clear_all_caches();
* Function: poptin_clear_all_caches
* Description: Clears caches from below plugins if any
function poptin_clear_all_caches()
global $wp_fastest_cache;
// if W3 Total Cache is being used, clear the cache
if (function_exists('w3tc_flush_all')) {
/* if WP Super Cache is being used, clear the cache */
if (function_exists('wp_cache_clean_cache')) {
global $file_prefix, $supercachedir;
if (empty($supercachedir) && function_exists('get_supercache_dir')) {
$supercachedir = get_supercache_dir();
wp_cache_clean_cache($file_prefix);
if (class_exists('WpeCommon')) {
//be extra careful, just in case 3rd party changes things on us
if (method_exists('WpeCommon', 'purge_memcached')) {
//WpeCommon::purge_memcached();
if (method_exists('WpeCommon', 'clear_maxcdn_cache')) {
//WpeCommon::clear_maxcdn_cache();
if (method_exists('WpeCommon', 'purge_varnish_cache')) {
//WpeCommon::purge_varnish_cache();
if (method_exists('WpFastestCache', 'deleteCache') && !empty($wp_fastest_cache)) {
$wp_fastest_cache->deleteCache();
if (function_exists('rocket_clean_domain')) {
if (function_exists('run_rocket_sitemap_preload')) {
run_rocket_sitemap_preload();
if (class_exists("autoptimizeCache") && method_exists("autoptimizeCache", "clearall")) {
autoptimizeCache::clearall();
if (class_exists("LiteSpeed_Cache_API") && method_exists("autoptimizeCache", "purge_all")) {
LiteSpeed_Cache_API::purge_all();
if (class_exists('\Hummingbird\Core\Utils')) {
$modules = Utils::get_active_cache_modules();
foreach ($modules as $module => $name) {
$mod = Utils::get_module($module);
if ('minify' === $module) {
$poptinBase = new POPTIN_Plugin_Base();