: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
namespace TwitterFeed\Admin;
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
use TwitterFeed\Admin\CTF_Response;
use TwitterFeed\Admin\CTF_Cache_Handler;
use TwitterFeed\Builder\CTF_Feed_Saver;
use TwitterFeed\Builder\CTF_Feed_Builder;
use TwitterFeed\Admin\CTF_HTTP_Request;
use TwitterFeed\CTF_GDPR_Integrations;
use TwitterFeed\Pro\CTF_Resizer;
use TwitterFeed\SB_Twitter_Cron_Updater;
class CTF_Global_Settings {
const SLUG = 'ctf-settings';
* Determining if the user is viewing the our page, if so, party on.
add_action('admin_menu', [$this, 'register_menu']);
add_filter( 'admin_footer_text', [$this, 'remove_admin_footer_text'] );
add_action( 'wp_ajax_ctf_save_settings', [$this, 'ctf_save_settings'] );
add_action( 'wp_ajax_ctf_activate_license', [$this, 'ctf_activate_license'] );
add_action( 'wp_ajax_ctf_deactivate_license', [$this, 'ctf_deactivate_license'] );
add_action( 'wp_ajax_ctf_test_connection', [$this, 'ctf_test_connection'] );
add_action( 'wp_ajax_ctf_recheck_connection', [$this, 'ctf_recheck_connection'] );
add_action( 'wp_ajax_ctf_import_settings_json', [$this, 'ctf_import_settings_json'] );
add_action( 'wp_ajax_ctf_export_settings_json', [$this, 'ctf_export_settings_json'] );
add_action( 'wp_ajax_ctf_clear_cache_settings', [$this, 'ctf_clear_cache_settings'] );
add_action( 'wp_ajax_ctf_clear_persistent_cache', [$this, 'ctf_clear_persistent_cache'] );
add_action( 'wp_ajax_ctf_clear_twittercard_cache', [$this, 'ctf_clear_twittercard_cache'] );
add_action( 'wp_ajax_ctf_clear_image_resize_cache', [$this, 'ctf_clear_image_resize_cache'] );
add_action( 'wp_ajax_ctf_dpa_reset', [$this, 'ctf_dpa_reset'] );
* This will save the data fron the settings page
public function ctf_save_settings() {
check_ajax_referer( 'ctf_admin_nonce', 'nonce' );
$cap = ctf_get_manage_options_cap();
if ( ! current_user_can( $cap ) ) {
wp_send_json_error(); // This auto-dies.
$model = isset( $data[ 'model' ] ) ? $data['model'] : null;
// return if the model is null
// get the ctf license key and extensions license key
$ctf_license_key = sanitize_text_field( $_POST['ctf_license_key'] );
// Only update the ctf_license_key value when it's inactive
if ( get_option( 'ctf_license_status') == 'inactive' ) {
if ( empty( $ctf_license_key ) || strlen( $ctf_license_key ) < 1 ) {
delete_option( 'ctf_license_key' );
delete_option( 'ctf_license_data' );
delete_option( 'ctf_license_status' );
update_option( 'ctf_license_key', $ctf_license_key );
$license_key = trim( get_option( 'ctf_license_key' ) );
if ( empty( $ctf_license_key ) && ! empty( $license_key ) ) {
$ctf_license_data = $this->get_license_data( $license_key, 'deactivate_license', CTF_PRODUCT_NAME );
delete_option( 'ctf_license_key' );
delete_option( 'ctf_license_data' );
delete_option( 'ctf_license_status' );
$model = (array) \json_decode( \stripslashes( $model ) );
$general = (array) $model['general'];
$feeds = (array) $model['feeds'];
$translation = (array) $model['translation'];
$advanced = (array) $model['advanced'];
// Get the values and sanitize
$ctf_settings = get_option( 'ctf_options', array() );
$ctf_settings['preserve_settings'] = $general['preserveSettings'];
$ctf_settings[ CTF_SITE_ACCESS_TOKEN_KEY ] = $general['siteKey'];
// Save translation settings data
foreach( $translation as $key => $val ) {
$ctf_settings[ $key ] = $val;
$ctf_settings['custom_css'] = $feeds['customCSS'];
$ctf_settings['custom_js'] = $feeds['customJS'];
$ctf_settings['gdpr'] = sanitize_text_field( $feeds['gdpr'] );
$ctf_settings['ctf_caching_type'] = sanitize_text_field( $feeds['cachingType'] );
$ctf_settings['cache_time'] = sanitize_text_field( $feeds['cacheTime'] );
$ctf_settings['cache_time_unit'] = sanitize_text_field( $feeds['cacheTimeUnit'] );
$ctf_settings['ctf_cache_cron_interval'] = sanitize_text_field( $feeds['cronInterval'] );
$ctf_settings['ctf_cache_cron_time'] = sanitize_text_field( $feeds['cronTime'] );
$ctf_settings['ctf_cache_cron_am_pm'] = sanitize_text_field( $feeds['cronAmPm'] );
$ctf_settings['rebranding'] = (bool)$advanced['rebranding'];
$ctf_settings['resizing'] = (bool)$advanced['resizing'];
$ctf_settings['persistentcache'] = (bool)$advanced['persistentcache'];
$ctf_settings['ajax_theme'] = (bool)$advanced['ajax_theme'];
$ctf_settings['headenqueue'] = (bool)$advanced['headenqueue'];
$ctf_settings['customtemplates'] = (bool)$advanced['customtemplates'];
$ctf_settings['creditctf'] = (bool)$advanced['creditctf'];
$ctf_settings['autores'] = (bool)$advanced['autores'];
$ctf_settings['customtemplates'] = (bool)$advanced['customtemplates'];
$ctf_settings['disableintents'] = !(bool)$advanced['enableintents'];
$ctf_settings['request_method'] = sanitize_text_field($advanced['request_method']);
$ctf_settings['cron_cache_clear'] = sanitize_text_field($advanced['cron_cache_clear']);
$ctf_settings['sslonly'] = (bool)$advanced['sslonly'];
$ctf_settings['curlcards'] = (bool)$advanced['curlcards'];
$usage_tracking = get_option( 'ctf_usage_tracking', array( 'last_send' => 0, 'enabled' => ctf_is_pro_version() ) );
if ( isset( $advanced['email_notification_addresses'] ) ) {
$usage_tracking['enabled'] = false;
if ( isset( $advanced['usage_tracking'] ) ) {
if ( ! is_array( $usage_tracking ) ) {
'enabled' => $advanced['usage_tracking'],
$usage_tracking['enabled'] = $advanced['usage_tracking'];
update_option( 'ctf_usage_tracking', $usage_tracking, false );
// Update the ctf_style_settings option that contains data for translation and advanced tabs
update_option( 'ctf_options', $ctf_settings );
SB_Twitter_Cron_Updater::start_cron_job( $ctf_settings['ctf_cache_cron_interval'], $ctf_settings['ctf_cache_cron_time'], $ctf_settings['ctf_cache_cron_am_pm'] );
// Clear the stored caches.
$cache_handler = new CTF_Cache_Handler();
$cache_handler->clear_persistent_cache();
new CTF_Response( true, array(
'cronNextCheck' => $this->get_cron_next_check()
* SBI Activate License Key
public function ctf_activate_license() {
check_ajax_referer( 'ctf_admin_nonce', 'nonce' );
$cap = ctf_get_manage_options_cap();
if ( ! current_user_can( $cap ) ) {
wp_send_json_error(); // This auto-dies.
// do the form validation to check if license_key is not empty
if ( empty( $_POST[ 'license_key' ] ) ) {
new CTF_Response( false, array(
'message' => __( 'License key required!', 'custom-twitter-feeds' ),
$license_key = sanitize_text_field( $_POST[ 'license_key' ] );
// make the remote api call and get license data
$ctf_license_data = $this->get_license_data( $license_key, 'activate_license', CTF_PRODUCT_NAME );
// update the license data
if( !empty( $ctf_license_data ) ) {
update_option( 'ctf_license_data', $ctf_license_data );
// update the licnese key only when the license status is activated
update_option( 'ctf_license_key', $license_key );
// update the license status
update_option( 'ctf_license_status', $ctf_license_data['license'] );
// Check if there is any error in the license key then handle it
$ctf_license_data = $this->get_license_error_message( $ctf_license_data );
// Send ajax response back to client end
'licenseStatus' => $ctf_license_data['license'],
'licenseData' => $ctf_license_data
new CTF_Response( true, $data );
* SBI Deactivate License Key
public function ctf_deactivate_license() {
check_ajax_referer( 'ctf_admin_nonce', 'nonce' );
$cap = ctf_get_manage_options_cap();
if ( ! current_user_can( $cap ) ) {
wp_send_json_error(); // This auto-dies.
$license_key = trim( get_option( 'ctf_license_key' ) );
$ctf_license_data = $this->get_license_data( $license_key, 'deactivate_license', CTF_PRODUCT_NAME );
// update the license data
if( !empty( $ctf_license_data ) ) {
update_option( 'ctf_license_data', $ctf_license_data );
if ( ! $ctf_license_data['success'] ) {
new CTF_Response( false, array() );
// remove the license keys and update license key status
if( $ctf_license_data['license'] == 'deactivated' ) {
update_option( 'ctf_license_status', 'inactive' );
'licenseStatus' => 'inactive'
new CTF_Response( true, $data );
public function ctf_test_connection() {
check_ajax_referer( 'ctf_admin_nonce', 'nonce' );
$cap = ctf_get_manage_options_cap();
if ( ! current_user_can( $cap ) ) {
wp_send_json_error(); // This auto-dies.
$license_key = get_option( 'ctf_license_key' );
'edd_action'=> 'check_license',
'license' => $license_key,
'item_name' => urlencode( CTF_PRODUCT_NAME ) // the name of our product in EDD
$url = add_query_arg( $ctf_api_params, CTF_LICENSE_URL );
// Make the remote API request
$request = CTF_HTTP_Request::request( 'GET', $url, $args );
if ( CTF_HTTP_Request::is_error( $request ) ) {
new CTF_Response( false, array(
new CTF_Response( true, array(
public function ctf_recheck_connection() {
check_ajax_referer( 'ctf_admin_nonce', 'nonce' );
$cap = ctf_get_manage_options_cap();
if ( ! current_user_can( $cap ) ) {
wp_send_json_error(); // This auto-dies.
// Do the form validation
$license_key = isset( $_POST['license_key'] ) ? sanitize_text_field( $_POST['license_key'] ) : '';
$item_name = isset( $_POST['item_name'] ) ? sanitize_text_field( $_POST['item_name'] ) : '';
$option_name = isset( $_POST['option_name'] ) ? sanitize_text_field( $_POST['option_name'] ) : '';
if ( empty( $license_key ) || empty( $item_name ) ) {
new CTF_Response( false, array() );
// make the remote license check API call
$ctf_license_data = $this->get_license_data( $license_key, 'check_license', $item_name );
$license_changed = $this->update_recheck_license_data( $ctf_license_data, $item_name, $option_name );
// send AJAX response back
new CTF_Response( true, array(
'license' => $ctf_license_data['license'],
'licenseChanged' => $license_changed
* @param array $license_data
* @param string $item_name
* @param string $option_name
* @return bool $license_changed
public function update_recheck_license_data( $license_data, $item_name, $option_name ) {
$license_changed = false;
// if we are updating plugin's license data
if ( CTF_PRODUCT_NAME == $item_name ) {
// compare the old stored license status with new license status
if ( get_option( 'ctf_license_status' ) != $license_data['license'] ) {
update_option( 'ctf_license_data', $license_data );
update_option( 'ctf_license_status', $license_data['license'] );
// If we are updating extensions license data
if ( CTF_PRODUCT_NAME != $item_name ) {
// compare the old stored license status with new license status
if ( get_option( 'ctf_license_status_' . $option_name ) != $license_data['license'] ) {
update_option( 'ctf_license_status_' . $option_name, $license_data['license'] );
// if we are updating extensions license data and it's not valid
// then remote the extensions license status
if ( CTF_PRODUCT_NAME != $item_name && 'valid' != $license_data['license'] ) {
delete_option( 'ctf_license_status_' . $option_name );
* SBI Import Feed Settings JSON
public function ctf_import_settings_json() {
check_ajax_referer( 'ctf_admin_nonce', 'nonce' );
$cap = ctf_get_manage_options_cap();
if ( ! current_user_can( $cap ) ) {
wp_send_json_error(); // This auto-dies.
$filename = $_FILES['file']['name'];
$ext = pathinfo($filename, PATHINFO_EXTENSION);
new CTF_Response( false, [] );
$imported_settings = file_get_contents( $_FILES["file"]["tmp_name"] );
// check if the file is empty
if ( empty( $imported_settings ) ) {
new CTF_Response( false, [] );
$feed_return = \TwitterFeed\Builder\CTF_Feed_Saver_Manager::import_feed( $imported_settings );
// check if there's error while importing
if ( ! $feed_return['success'] ) {
new CTF_Response( false, [] );
// Once new feed has imported lets export all the feeds to update in front end
$exported_feeds = \TwitterFeed\Builder\CTF_Db::feeds_query();
foreach( $exported_feeds as $feed_id => $feed ) {
'name' => $feed['feed_name']
new CTF_Response( true, array(
* SBI Export Feed Settings JSON
public function ctf_export_settings_json() {
\TwitterFeed\Builder\CTF_Feed_Builder::check_privilege();
if ( ! isset( $_GET['feed_id'] ) ) {
$feed_id = filter_var( $_GET['feed_id'], FILTER_SANITIZE_NUMBER_INT );
$feed = \TwitterFeed\Builder\CTF_Feed_Saver_Manager::get_export_json( $feed_id );
$feed_info = \TwitterFeed\Builder\CTF_Db::feeds_query( array('id' => $feed_id) );
$feed_name = strtolower( $feed_info[0]['feed_name'] );
$filename = 'ctf-feed-' . $feed_name . '.json';
// create a new empty file in the php memory
$file = fopen( 'php://memory', 'w' );
header( 'Content-type: application/json' );
header( 'Content-disposition: attachment; filename = "' . $filename . '";' );
public function ctf_clear_cache_settings() {
check_ajax_referer( 'ctf_admin_nonce', 'nonce' );
$cap = ctf_get_manage_options_cap();
if ( ! current_user_can( $cap ) ) {
wp_send_json_error(); // This auto-dies.
// Get the updated cron schedule interval and time settings from user input and update the database
$model = isset( $_POST[ 'model' ] ) ? sanitize_text_field( $_POST['model'] ) : null;
$model = (array) \json_decode( \stripslashes( $model ) );
$feeds = (array) $model['feeds'];
$ctf_options = wp_parse_args( get_option( 'ctf_options' ), $this->default_settings_options() );
$cron_clear_cache = isset($ctf_options['cron_cache_clear']) ? $ctf_options['cron_cache_clear'] : 'no';
$cache_time = isset($feeds['cache_time']) ? (int)$feeds['cache_time'] : 1;
$cache_time_unit = isset($feeds['cache_time_unit']) ? (int)$feeds['cache_time_unit'] : 3600;
if ($cron_clear_cache == 'no') {
wp_clear_scheduled_hook('ctf_cron_job');
elseif ($cron_clear_cache == 'yes') {
//Clear the existing cron event
wp_clear_scheduled_hook('ctf_cron_job');
//Set the event schedule based on what the caching time is set to
if ($cache_time_unit == 3600 && $cache_time > 5) {
$ctf_cron_schedule = 'twicedaily';