: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Tracking functions for reporting plugin usage to the Smash Balloon site for users that have opted in
* @copyright Copyright (c) 2018, Chris Christoff
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
public function __construct() {
add_action( 'init', array( $this, 'schedule_send' ) );
add_filter( 'cron_schedules', array( $this, 'add_schedules' ) );
add_action( 'ctf_usage_tracking_cron', array( $this, 'send_checkin' ) );
add_action( 'admin_init', array( $this, 'save_setting' ) );
private function normalize_and_format( $key, $value ) {
'usertimeline_includereplies',
'hometimeline_includereplies',
'mentionstimeline_includereplies',
'usertimeline_includeretweets',
'hometimeline_includeretweets',
'mentionstimeline_includeretweets',
'include_media_placeholder'
$custom_text_settings = array(
$comma_separate_counts_settings = array(
'use_own_consumer' => '',
'preserve_settings' => '',
'usertimeline_includereplies' => '',
'hometimeline_includereplies' => '',
'mentionstimeline_includereplies' => '',
'usertimeline_includeretweets' => '',
'hometimeline_includeretweets' => '1',
'mentionstimeline_includeretweets' => '',
'access_token_secret' => '',
'type' => 'usertimeline',
'usertimeline_text' => '',
'cache_time_unit' => '3600',
'includeretweets' => true,
'width_mobile_no_fixed' => '0',
'include_retweeter' => '1',
'include_actions' => '1',
'include_twitterlink' => '1',
'include_linkbox' => '1',
'persistentcache' => '1',
'disablelightbox' => '0',
'include_twittercards' => '1',
'include_replied_to' => '1',
'carouselautoplay' => '0',
'masonrymobilecols' => '1',
'carouselmobilecols' => '1',
'carouselloop' => 'none',
'carouselarrows' => 'onhover',
'carouselheight' => 'tallest',
'carouseltime' => '5000',
'autoscrolldistance' => '200',
'includeanyall' => 'any',
'excludeanyall' => 'any',
'request_method' => 'auto',
'cron_cache_clear' => 'unset',
'include_media_placeholder' => '1',
'linktexttotwitter' => '',
'headertextcolor' => '#',
'datetextsize' => 'inherit',
'datetextweight' => 'inherit',
'authortextsize' => 'inherit',
'authortextweight' => 'inherit',
'tweettextsize' => 'inherit',
'tweettextweight' => 'inherit',
'retweetedtext' => 'Retweeted',
'quotedauthorsize' => 'inherit',
'quotedauthorweight' => 'inherit',
'twitterlinktext' => 'Twitter',
'buttontextcolor' => '#',
'buttontext' => 'Load More...',
'inreplytotext' => 'In reply to'
if ( is_array( $value ) ) {
// 0 for anything that might be false, 1 for everything else
} elseif ( in_array( $key, $normal_bools, true ) ) {
if ( in_array( $value, array( false, 0, '0', 'false', '' ), true ) ) {
// if a custom text setting, we just want to know if it's different than the default
} elseif ( in_array( $key, $custom_text_settings, true ) ) {
if ( $defaults[ $key ] === $value ) {
} elseif ( in_array( $key, $comma_separate_counts_settings, true ) ) {
if ( str_replace( ' ', '', $value ) === '' ) {
$split_at_comma = explode( ',', $value );
return count( $split_at_comma );
private function get_data() {
// Retrieve current theme info
$theme_data = wp_get_theme();
if ( function_exists( 'get_blog_count' ) ) {
$count_b = get_blog_count();
$php_version = rtrim( ltrim( sanitize_text_field( phpversion() ) ) );
$php_version = ! empty( $php_version ) ? substr( $php_version, 0, strpos( $php_version, '.', strpos( $php_version, '.' ) + 1 ) ) : phpversion();
$data['this_plugin'] = 'tw';
$data['php_version'] = $php_version;
$data['mi_version'] = CTF_VERSION;
$data['wp_version'] = $wp_version;
$data['server'] = isset( $_SERVER['SERVER_SOFTWARE'] ) ? $_SERVER['SERVER_SOFTWARE'] : '';
$data['multisite'] = is_multisite();
$data['url'] = home_url();
$data['themename'] = $theme_data->Name;
$data['themeversion'] = $theme_data->Version;
$data['settings'] = array();
$data['pro'] = ctf_is_pro_version() ? '1' : '';
$data['sites'] = $count_b;
$data['usagetracking'] = get_option( 'ctf_usage_tracking_config', false );
$num_users = function_exists( 'count_users' ) ? count_users() : 'Not Set';
$data['usercount'] = is_array( $num_users ) ? $num_users['total_users'] : 1;
$data['timezoneoffset']= date('P');
$settings_to_send = array();
$raw_settings = get_option( 'ctf_options', array() );
foreach ( $raw_settings as $key => $value ) {
if ( $key === 'consumer_key'
|| $key === 'consumer_secret'
|| $key === 'access_token'
|| $key === 'access_token_secret'
} elseif ( $key === 'connected_accounts' ) {
if ( is_array( $raw_settings['connected_accounts'] ) ) {
$settings_to_send['connected_accounts'] = count( $raw_settings['connected_accounts'] );
$settings_to_send['connected_accounts'] = 0;
$value = $this->normalize_and_format( $key, $value );
if ( $value !== false ) {
$settings_to_send[ $key ] = $value;
$results = $wpdb->get_results( "
WHERE `option_name` LIKE ('%\_transient\_ctf\_%')
AND `option_name` NOT LIKE ('%\_transient\_ctf\_header%');", ARRAY_A );
if ( isset( $results[0] ) ) {
$settings_to_send['num_found_feed_caches'] = count( $feed_caches );
$data['settings'] = $settings_to_send;
// Retrieve current plugin information
if( ! function_exists( 'get_plugins' ) ) {
include ABSPATH . '/wp-admin/includes/plugin.php';
$plugins = get_plugins();
$active_plugins = get_option( 'active_plugins', array() );
$plugins_to_send = array();
foreach ( $plugins as $plugin_path => $plugin ) {
// If the plugin isn't active, don't show it.
if ( ! in_array( $plugin_path, $active_plugins ) )
$plugins_to_send[] = $plugin['Name'];
$data['active_plugins'] = $plugins_to_send;
$data['locale'] = get_locale();
public function send_checkin( $override = false, $ignore_last_checkin = false ) {
$home_url = trailingslashit( home_url() );
if ( strpos( $home_url, 'smashballoon.com' ) !== false ) {
if( ! $this->tracking_allowed() && ! $override ) {
// Send a maximum of once per week
$usage_tracking = get_option( 'ctf_usage_tracking', array( 'last_send' => 0, 'enabled' => ctf_is_pro_version() ) );
if ( is_numeric( $usage_tracking['last_send'] ) && $usage_tracking['last_send'] > strtotime( '-1 week' ) && ! $ignore_last_checkin ) {
$request = wp_remote_post( 'https://usage.smashballoon.com/v1/checkin/', array(
'body' => $this->get_data(),
'user-agent' => 'MI/' . CTF_VERSION . '; ' . get_bloginfo( 'url' )
// If we have completed successfully, recheck in 1 week
$usage_tracking['last_send'] = time();
update_option( 'ctf_usage_tracking', $usage_tracking, false );
private function tracking_allowed() {
$usage_tracking = get_option( 'ctf_usage_tracking', array( 'last_send' => 0, 'enabled' => ctf_is_pro_version() ) );
$tracking_allowed = isset( $usage_tracking['enabled'] ) ? $usage_tracking['enabled'] : ctf_is_pro_version();
return $tracking_allowed;
public function schedule_send() {
if ( ! wp_next_scheduled( 'ctf_usage_tracking_cron' ) ) {
$tracking['day'] = rand( 0, 6 );
$tracking['hour'] = rand( 0, 23 );
$tracking['minute'] = rand( 0, 59 );
$tracking['second'] = rand( 0, 59 );
$tracking['offset'] = ( $tracking['day'] * DAY_IN_SECONDS ) +
( $tracking['hour'] * HOUR_IN_SECONDS ) +
( $tracking['minute'] * MINUTE_IN_SECONDS ) +
$last_sunday = strtotime("next sunday") - (7 * DAY_IN_SECONDS);
if ( ($last_sunday + $tracking['offset']) > time() + 6 * HOUR_IN_SECONDS ) {
$tracking['initsend'] = $last_sunday + $tracking['offset'];
$tracking['initsend'] = strtotime("next sunday") + $tracking['offset'];
wp_schedule_event( $tracking['initsend'], 'weekly', 'ctf_usage_tracking_cron' );
update_option( 'ctf_usage_tracking_config', $tracking );
public function add_schedules( $schedules = array() ) {
// Adds once weekly to the existing schedules.
$schedules['weekly'] = array(
'display' => __( 'Once Weekly', 'custom-twitter-feeds' )
public function save_setting() {
if ( isset( $_POST['ctf_usage_tracking_enable'] ) ) {
$usage_tracking['enabled'] = false;
if ( isset( $_POST['ctf_usage_tracking_enable'] ) && $_POST['ctf_usage_tracking_enable'] === 'on' ) {
$usage_tracking['enabled'] = true;
update_option( 'ctf_usage_tracking', $usage_tracking, false );