: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Instagram Feed Database
namespace TwitterFeed\Builder;
use TwitterFeed\CTF_Settings;
private $sanitized_and_sorted_data;
* CTF_Feed_Saver constructor.
public function __construct( $insert_id ) {
if ( $insert_id === 'legacy' ) {
$this->is_legacy = false;
$this->insert_id = $insert_id;
* Feed insert ID if it exists
public function get_feed_id() {
if ( $this->is_legacy ) {
if ( ! empty( $this->insert_id ) ) {
public function set_data( $data ) {
* @param string $feed_name
public function set_feed_name( $feed_name ) {
$this->feed_name = $feed_name;
* @param array $feed_db_data
public function get_feed_db_data() {
return $this->feed_db_data;
* Adds a new feed if there is no associated feed
* found. Otherwise updates the exiting feed.
public function update_or_insert() {
$this->sanitize_and_sort_data();
if ( $this->exists_in_database() ) {
* Whether or not a feed exists with the
public function exists_in_database() {
if ( $this->is_legacy ) {
if ( $this->insert_id === false ) {
$results = CTF_Db::feeds_query( $args );
return isset( $results[0] );
* Inserts a new feed from sanitized and sorted data.
* Some data is saved in the ctf_feeds table and some is
* saved in the ctf_feed_settings table.
public function insert() {
if ( $this->is_legacy ) {
if ( ! isset( $this->sanitized_and_sorted_data ) ) {
$settings_array = CTF_Feed_Saver::format_settings( $this->sanitized_and_sorted_data['feed_settings'] );
$this->sanitized_and_sorted_data['feeds'][] = array(
'values' => array( ctf_json_encode( $settings_array ) )
if ( ! empty( $this->feed_name ) ) {
$this->sanitized_and_sorted_data['feeds'][] = array(
'values' => array( $this->feed_name )
$this->sanitized_and_sorted_data['feeds'][] = array(
'values' => array( 'publish' )
$insert_id = CTF_Db::feeds_insert( $this->sanitized_and_sorted_data['feeds'] );
$this->insert_id = $insert_id;
* Updates an existing feed and related settings from
* sanitized and sorted data.
public function update() {
if ( ! isset( $this->sanitized_and_sorted_data ) ) {
$settings_array = CTF_Feed_Saver::format_settings( $this->sanitized_and_sorted_data['feed_settings'] );
if ( $this->is_legacy ) {
$to_save_json = ctf_json_encode( $settings_array );
return update_option( 'ctf_legacy_feed_settings', $to_save_json, false );
$this->sanitized_and_sorted_data['feeds'][] = array(
'values' => array( ctf_json_encode( $settings_array ) )
$this->sanitized_and_sorted_data['feeds'][] = array(
'values' => [sanitize_text_field($this->feed_name)]
$success = CTF_Db::feeds_update( $this->sanitized_and_sorted_data['feeds'], $args );
* Converts settings that have been sanitized into an associative array
* that can be saved as JSON in the database
public static function format_settings( $raw_settings ) {
$settings_array = array();
foreach ( $raw_settings as $single_setting ) {
if ( count( $single_setting['values'] ) > 1 ) {
$settings_array[ $single_setting['key'] ] = $single_setting['values'];
$settings_array[ $single_setting['key'] ] = isset( $single_setting['values'][0] ) ? $single_setting['values'][0] : '';
* Gets the Preview Settings
* for the Feed Fly Preview
public function get_feed_preview_settings( $preview_settings ){
* Retrieves and organizes feed setting data for easy use in
public function get_feed_settings() {
if ( $this->is_legacy ) {
$twitter_feed_settings = new CTF_Settings( array(), ctf_get_database_settings(), array() );
$twitter_feed_settings->set_feed_type_and_terms();
//$twitter_feed_settings->set_transient_name();
$return = $twitter_feed_settings->get_settings();
$this->feed_db_data = array(
'feed_name' => __( 'Legacy Feeds', 'custom-twitter-feeds' ),
'feed_title' => __( 'Legacy Feeds', 'custom-twitter-feeds' ),
'last_modified' => date( 'Y-m-d H:i:s' ),
} else if ( empty( $this->insert_id ) ) {
'id' => $this->insert_id,
$settings_db_data = CTF_Db::feeds_query( $args );
if ( false === $settings_db_data || sizeof($settings_db_data) == 0) {
$this->feed_db_data = array(
'id' => $settings_db_data[0]['id'],
'feed_name' => $settings_db_data[0]['feed_name'],
'feed_title' => $settings_db_data[0]['feed_title'],
'status' => $settings_db_data[0]['status'],
'last_modified' => $settings_db_data[0]['last_modified'],
$return = json_decode( $settings_db_data[0]['settings'], true );
$return['feed_name'] = $settings_db_data[0]['feed_name'];
$return = wp_parse_args( $return, CTF_Feed_Saver::settings_defaults() );
* Retrieves and organizes feed setting data for easy use in
* It will NOT get the settings from the DB, but from the Customizer builder
* To be used for updating feed preview on the fly
public function get_feed_settings_preview( $settings_db_data ) {
if ( false === $settings_db_data || sizeof($settings_db_data) == 0) {
$return = $settings_db_data;
$return = wp_parse_args( $return, CTF_Feed_Saver::settings_defaults() );
* Default settings, $return_array equalling false will return
* the settings in the general way that the "CTF_Shortcode" class,
* "ctf_get_processed_options" method does
* @param bool $return_array
public static function settings_defaults( $return_array = true ) {
$translations = get_option( 'ctf_options', array() );
$final_translations = [];
$final_translations['retweetedtext'] = isset( $translations['retweetedtext'] ) ? stripslashes( esc_attr( $translations['retweetedtext'] ) ) : __( 'Retweeted', 'custom-twitter-feeds' );
$final_translations['inreplytotext'] = isset( $translations['inreplytotext'] ) ? stripslashes( esc_attr( $translations['inreplytotext'] ) ) : __( 'In Reply To', 'custom-twitter-feeds' );
$final_translations['buttontext'] = isset( $translations['buttontext'] ) ? stripslashes( esc_attr( $translations['buttontext'] ) ) : __( 'Load More', 'custom-twitter-feeds' );
$final_translations['minutestext'] = isset( $translations['minutestext'] ) ? stripslashes( esc_attr( $translations['minutestext'] ) ) : __( 'Minutes', 'custom-twitter-feeds' );
$final_translations['hoursetext'] = isset( $translations['hoursetext'] ) ? stripslashes( esc_attr( $translations['hoursetext'] ) ) : __( 'Hours', 'custom-twitter-feeds' );
$final_translations['nowtext'] = isset( $translations['nowtext'] ) ? stripslashes( esc_attr( $translations['nowtext'] ) ) : __( 'Now', 'custom-twitter-feeds' );
'use_own_consumer' => '',
#'preserve_settings' => '',
'usertimeline_includereplies' => '',
'hometimeline_includereplies' => '',
'mentionstimeline_includereplies' => '',
'usertimeline_includeretweets' => true,
'hometimeline_includeretweets' => true,
'mentionstimeline_includeretweets' => '',
'access_token_secret' => '',
'type' => 'usertimeline',
'usertimeline_text' => '',
#'cache_time_unit' => '3600',
'includereplies' => false,
'includeretweets' => true,
'width_mobile_no_fixed' => false,
'include_replied_to' => true,
'include_retweeter' => true,
'include_author' => true,
'include_avatar' => true,
'include_author_text' => true, //NEW
'include_actions' => true,
'include_linkbox' => true,
'include_twittercards' => true,
'include_twitterlink' => true,
'persistentcache' => true,
'disableintents' => false,
'customtemplates' => false,
'disablelightbox' => false,
'carouselnavarrows' => true,
'carouselautoplay' => false,
'masonrytabletcols' => '2', //NEW
'masonrymobilecols' => '1',
'carouselrows' => '1', //NEW
'carouseltabletcols' => '2', //NEW
'carouselmobilecols' => '1',
'carouselloop' => 'rewind',
'carouselarrows' => 'onhover',
'carouselheight' => 'tallest',
'carouseltime' => '5000',
'autoscrolldistance' => '200',
'includeanyall' => 'any',
'excludeanyall' => 'any',
'request_method' => 'auto',
'cron_cache_clear' => 'unset',
'include_media_placeholder' => true,
'linktexttotwitter' => false,
'headertextcolor' => '#', //OLD
'headertext' => '', //OLD
'headersize' => 'small', //OLD
'headerstyle' => 'standard', //NEW
'customheadertextcolor' => '#',
'customheadertext' => __( 'We are on Twitter', 'custom-twitter-feeds' ),
'customheadersize' => 'small',