: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* A bridge to use the new feed caches table
public function __construct( $feed_id, $cache_time, $page ) {
$this->feed_id = $feed_id;
$this->cache_time = $cache_time;
$this->feed_id .= $this->maybe_customizer_suffix();
* @param string $transient_name
public function get_transient( $transient_name ) {
$results = $this->query_ctf_feed_caches( $transient_name );
if ( empty( $results ) ) {
if ( empty( $results[0]['cache_value'] ) ) {
if ( strtotime( $results[0]['last_updated'] ) < time() - $this->cache_time ) {
return $results[0]['cache_value'];
* Mimic WP get_option for persistent caches
* @param string $transient_name
public function get_persistent( $transient_name ) {
$results = $this->query_ctf_feed_caches( $transient_name );
if ( empty( $results ) ) {
$results = get_option( $transient_name, false );
if ( ! empty( $results ) ) {
if ( empty( $results ) ) {
if ( empty( $results[0]['cache_value'] ) ) {
return $results[0]['cache_value'];
public function set_transient( $transient_name, $value, $backup = false, $cron_update = true ) {
return $this->update_or_insert( $transient_name, $value, $backup, $cron_update );
* Mimic WP update_option for persistent
public function set_persistent( $transient_name, $value ) {
return $this->update_or_insert( $transient_name, $value );
* Update or insert cache data
* @param string $transient_name
* @param string $cache_value
* @param bool $include_backup
* @param bool $cron_update
* @return bool|int|\mysqli_result|resource|null
public function update_or_insert( $transient_name, $cache_value, $include_backup = true, $cron_update = true ) {
if ( strpos( $this->feed_id, '_CUSTOMIZER' ) !== false ) {
if ( ! empty( $this->page ) ) {
if ( $this->feed_id === 'legacy' ) {
$cache_table_name = $wpdb->prefix . 'ctf_feed_caches';
SELECT * FROM $cache_table_name
$existing = $wpdb->get_results( $sql, ARRAY_A );
$data['cache_value'] = $cache_value;
$data['last_updated'] = date( 'Y-m-d H:i:s' );
if ( ! empty( $existing[0] ) ) {
$where['feed_id'] = $this->feed_id;
$where['cache_key'] = $transient_name;
$affected = $wpdb->update( $cache_table_name, $data, $where, $format, $where_format );
$data['cache_key'] = $transient_name;
$data['cron_update'] = $cron_update === true ? 'yes' : '';
$data['feed_id'] = $this->feed_id;
$affected = $wpdb->insert( $cache_table_name, $data, $format );
private function query_ctf_feed_caches( $transient_name ) {
$feed_cache = wp_cache_get( $transient_name );
if ( false === $feed_cache || ! is_array( $feed_cache ) ) {
$cache_table_name = $wpdb->prefix . 'ctf_feed_caches';
SELECT * FROM $cache_table_name
ORDER BY last_updated DESC",
$feed_cache = $wpdb->get_results( $sql, ARRAY_A );
wp_cache_set( $transient_name, $feed_cache );
private function maybe_customizer_suffix() {
$in_customizer = ! empty( $_POST['previewSettings'] ) || ( isset( $_GET['page'] ) && $_GET['page'] === 'ctf-feed-builder' );
$additional_suffix .= '_CUSTOMIZER';
return $additional_suffix;