: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
class Tbp_Dynamic_Content {
private static $items = null;
* Name of the option that stores Dynamic Content settings
private static $field_name = '__dc__';
public static function run() {
add_filter( 'tf_builder_row', array( __CLASS__, 'tf_builder_row' ) );
add_filter( 'themify_builder_module_render_vars', array( __CLASS__, 'themify_builder_module_render_vars' ) );
if ( Themify_Builder_Model::is_frontend_editor_page()) {
add_action( 'themify_builder_frontend_enqueue', array( __CLASS__, 'admin_enqueue' ) );
add_action( 'themify_builder_admin_enqueue', array( __CLASS__, 'admin_enqueue' ), 15 );
add_action( 'wp_ajax_tpb_get_dynamic_content_fields', array( __CLASS__, 'options' ) );
add_action( 'wp_ajax_tpb_get_dynamic_content_preview', array( __CLASS__, 'preview' ) );
add_action( 'themify_builder_background_styling', array( __CLASS__, 'background_styling' ), 10, 4 );
private static function register_items() {
if ( self::$items !== null ) {
$items = self::$items = array();
$base_path = TBP_DIR . 'includes/dynamic-content/';
$files = scandir ( $base_path );
foreach ($files as $file) {
if ( $file !== '.' && $file !== '..' && $file !== '.svn' ) {
include_once $base_path . $file;
$name = pathinfo( $file, PATHINFO_FILENAME );
$items[ $name ] = "Tbp_Dynamic_Item_{$name}";
$items = apply_filters( 'tbp_dynamic_items', $items );
foreach ( $items as $id => $class ) {
$instance = new $class();
/* add this item only if is_available() */
if ( $instance->is_available() === true ) {
self::$items[ $id ] = $instance;
public static function get( $id = null ) {
return $id === null ? self::$items : ( isset( self::$items[ $id ] ) ? self::$items[ $id ] : false );
public static function get_list() {
foreach ( self::$items as $id => $instance ) {
'type' => $instance->get_type(),
* Adds inline styles for styling the background image of Builder components
* hooked to "themify_builder_background_styling"
public static function background_styling( $builder_id, $settings, $order_id, $type ) {
if ( ! isset( $settings[ 'styling' ][ self::$field_name ] ) || $settings[ 'styling' ][ self::$field_name ]==='{}' ) {
$dc = is_string($settings[ 'styling' ][ self::$field_name ])?json_decode( $settings[ 'styling' ][ self::$field_name ], true ):$settings[ 'styling' ][ self::$field_name ];
if ( ! is_array( $dc ) ) {
static $cacheIDs=array();
if ( $type==='row' || $type==='column' || $type==='subrow' ) {
$element_id = isset($settings['element_id'])?'tb_'.$settings['element_id']:$order_id;
if(!isset($cacheIDs[$type])){
$bg_fields=array('background_image'=>'');
$inner_select.=$type==='column'?'tb-column-inner':$type.'_inner';
$bg_fields['background_image_inner']=array($inner_select);
if($type==='column' && Themify_Builder::$frontedit_active===true){
$bg_fields['background_image_inner'][]= '>.tb_holder';
$cacheIDs[$type]=$bg_fields;
$type_selector='.module_' . $type;
$mod_name = $settings['mod_name'];
if(!isset($cacheIDs[$mod_name])){
$module = Themify_Builder_Model::$modules[ $mod_name ];
$styling = $module->get_form_settings( true );
$bg_fields = self::get_background_image_fields( $styling );
$cacheIDs[$mod_name]=$bg_fields;
$bg_fields =$cacheIDs[$mod_name];
$type_selector='.module-' . $mod_name;
if ( empty( $bg_fields )) {
$intersect = array_intersect_key($dc,$bg_fields);
if(Tbp_Utils::$isLoop===true){
if(class_exists('TB_Advanced_Posts_Module') && TB_Advanced_Posts_Module::$builder_id!==null){
$builder_id = str_replace( 'tb_', '', TB_Advanced_Posts_Module::$builder_id );
elseif(class_exists('TB_Advanced_Products_Module') && TB_Advanced_Products_Module::$builder_id!==null){
$builder_id = str_replace( 'tb_', '', TB_Advanced_Products_Module::$builder_id );
$base='.themify_builder';
$base.='.themify_builder_content-'.$builder_id;
foreach ( $intersect as $key => $options ) {
if ( $value = self::get_value( $options ) ) {
if(Tbp_Utils::$isLoop===true){
$selector.=' .post-'.get_the_ID();
$selector.=" {$type_selector}.{$element_id}";
if(is_string($bg_fields[ $key ])){
$selector.=$bg_fields[ $key ];
$selector.=implode(',',$bg_fields[ $key ]);
$styles.= $selector . '{ background-image:url("' . $value . '") }';
echo '<style class="tbp_dc_styles">' . $styles . '</style>';
* Loops through a component styling definition to find all background-image fields
private static function get_background_image_fields( array $array ) {
$iterator = new RecursiveArrayIterator( $array );
$recursive = new RecursiveIteratorIterator( $iterator, RecursiveIteratorIterator::SELF_FIRST );
foreach ( $recursive as $value ) {
if ( isset( $value['prop'], $value['id'] ) && !isset($value['ishover']) && $value['prop'] === 'background-image' && ($value['label']==='bg' || $value['label']==='b_i') && ($value['type']==='image' || $value['type']==='imageGradient')) {
$list[ $value['id'] ] = $value['selector'];
public static function tf_builder_row( $row ) {
if ( ! empty( $row['cols'] ) ) {
foreach ( $row['cols'] as $column_index => $column ) {
if ( ! empty( $column['modules'] ) ) {
foreach ( $column['modules'] as $module_index => $module ) {
if ( ! empty( $module['cols'] ) ) {
foreach ( $module['cols'] as $sub_column_index => $sub_column ) {
if ( ! empty( $sub_column['modules'] ) ) {
foreach ( $sub_column['modules'] as $sub_column_module_index => $sub_column_module ) {
$replace = self::do_replace( $row['cols'][ $column_index ]['modules'][ $module_index ]['cols'][ $sub_column_index ]['modules'][ $sub_column_module_index ] );
if ( $replace === '__disable_module__' ) {
unset( $row['cols'][ $column_index ]['modules'][ $module_index ]['cols'][ $sub_column_index ]['modules'][ $sub_column_module_index ] );
} else if ( $replace === '__disable_row__' ) {
} else if ( $replace === '__disable_subrow__' ) {
unset( $row['cols'][ $column_index ]['modules'][ $module_index ] );
$row['cols'][ $column_index ]['modules'][ $module_index ]['cols'][ $sub_column_index ]['modules'][ $sub_column_module_index ] = $replace;
$replace = self::do_replace( $row['cols'][ $column_index ]['modules'][ $module_index ], true );
if ( $replace === '__disable_module__' ) {
unset( $row['cols'][ $column_index ]['modules'][ $module_index ] );
} else if ( $replace === '__disable_row__' ) {
/* hide the entire row */
$row['cols'][ $column_index ]['modules'][ $module_index ] = $replace;
* Filter module settings in preview
public static function themify_builder_module_render_vars( $vars ) {
if ( Themify_Builder::$frontedit_active === true ) {
$vars = self::do_replace( $vars );
* Parse DC settings and replace the module settings in $vars with their values.
public static function do_replace( $vars, $ignore_disable_subrow_condition = false ) {
if ( ! isset( $vars['mod_settings'][ self::$field_name ] ) || $vars['mod_settings'][ self::$field_name ]==='{}' )
$fields = is_string($vars['mod_settings'][ self::$field_name ])?json_decode( $vars['mod_settings'][ self::$field_name ], true ):$vars['mod_settings'][ self::$field_name ];
if ( empty( $fields ) || ! is_array( $fields ) ) {
foreach ( $fields as $key => $options ) {
if ( ! isset( $options['item'] ) || isset( $options['repeatable'] ) ) {
if ( isset( $vars['mod_settings'][ $key ] ) && is_array( $vars['mod_settings'][ $key ] ) ) {
unset( $options['repeatable'], $options['o'] );
// loop through repeatable items
if ( ! empty( $options ) && is_array( $options ) ) {
foreach ( $options as $i => $items ) {
if ( ! empty( $items ) ) {
foreach ( $items as $field_name => $field_options ) {
if ( isset( $field_options['item'] ) ) {
$value = self::get_value( $field_options );
if ( in_array( $value, array( '__disable_module__', '__disable_row__' ) ) ) {
} else if ( '__disable_subrow__' === $value ) {
if ( $ignore_disable_subrow_condition ) {
// replace field with empty string
$vars['mod_settings'][ $key ][ $i ][ $field_name ] = '';
// flag the subrow to be removed
return '__disable_subrow__';
$vars['mod_settings'][ $key ][ $i ][ $field_name ] = $value;
$value = self::get_value( $options );
if ( in_array( $value, array( '__disable_module__', '__disable_row__' ) ) ) {
// special flags, return the string instead of replacing
} else if ( '__disable_subrow__' === $value ) {
if ( $ignore_disable_subrow_condition ) {
// replace field with empty string
$vars['mod_settings'][ $key ] = '';
// flag the subrow to be removed
return '__disable_subrow__';
$vars['mod_settings'][ $key ] = $value;
* Get value from saved DC settings
* Calls Tbp_Dynamic_Content::get_value for $options['item']
private static function get_value( $options ) {
if ( isset( $options['item'] ) && ( $item = self::get( $options['item'] ) ) ) {
unset( $options['item'] );
$value = $item->get_value( $options );
if ( ! empty( $options['condition'] ) && ! Themify_Builder::$frontedit_active ) {
if ( $options['condition'] === 'hide_module' ) {
return '__disable_module__'; // flag to remove the module
} else if ( $options['condition'] === 'hide_row' ) {
return '__disable_row__'; // flag to remove the row
} else if ( $options['condition'] === 'hide_subrow' ) {
return '__disable_subrow__'; // flag to remove the subrow
// general formatting for various field types
if ( isset( $options['text_before'] ) ) {
$value = $options['text_before'] . $value;
if ( isset( $options['text_after'] ) ) {
$value .= $options['text_after'];
if ( ! empty( $options['uri_scheme'] ) ) {
$value = $options['uri_scheme'] . ':' . $value;
public static function admin_enqueue() {
wp_enqueue_script( 'tbp-dynamic-content', themify_enque(TBP_URL . 'admin/js/tbp-dynamic-content.js') , array( 'themify-builder-app-js' ), $v, true );
wp_localize_script( 'tbp-dynamic-content', 'tbpDynamic',
'items' => self::get_list(),
'field_name' => self::$field_name,
'd_label'=>__('Dynamic','tbp'),
'emptyVal'=>__('Empty Value','tbp'),
'placeholder_image' => TBP_URL . 'admin/img/template-placeholder.png',
'excludes' =>self::get_option_excludes()
* list of option IDs that will not have DC enabled on them
private static function get_option_excludes() {
* Hooked to "wp_ajax_tpb_get_dynamic_content_preview"
public static function preview() {
check_ajax_referer( 'tb_load_nonce', 'tb_load_nonce' );
Themify_Builder::$frontedit_active = true;
// before rendering the dynamic value, first set up the WP Loop
if ( isset( $_POST['pid'] )) {
$post_id = (int) $_POST['pid'];
if ( $post_object = get_post( $post_id ) ) {
setup_postdata( $GLOBALS['post'] =& $post_object );
$options = ! empty( $_POST['values'] )? json_decode( stripslashes_deep( $_POST['values'] ), true ) : array();
if ( isset( $options['item'] ) ) {
$value = array( 'value' => self::get_value( $options ) );
$value = array( 'error' => __( 'Invalid value.', 'tbp' ) );
die( json_encode( $value ) );
public static function options() {
check_ajax_referer('tb_load_nonce', 'tb_load_nonce');
$items_list = $items_settings = array();
'general' => __( 'General', 'tbp' ),
'post' => __( 'Post', 'tbp' ),
'wc' => __( 'WooCommerce', 'tbp' ),
'advanced' => __( 'Advanced', 'tbp' ),
'ptb' => __( 'Themify Post Type Builder', 'tbp' ),
'acf' => __( 'Advanced Custom Fields', 'tbp' ),
$items_list['empty'] = array( 'options' => array( '' => '' ) );
foreach ( $items as $id => $class ) {
$cat_id = $class->get_category();
if ( ! isset( $items_list[ $cat_id ] ) ) {
$items_list[ $cat_id ] = array(
'label' => $categories[ $cat_id ],
$items_list[ $cat_id ]['options'][ $id ] = $class->get_label();
if ( $options = $class->get_options() ) {
$items_settings[ $id ] = array(
'wrap_class' => 'field_' . $id,
foreach($categories as $k=>$v){
if(isset($items_list[$k])){
$data[$k]=$items_list[$k];
$items=$categories=$items_list=null;
$items_settings['general_text'] = array(
'label' => __( 'Text Before', 'tbp' ),
'label' => __( 'Text After', 'tbp' ),
'wrap_class' => 'field_general_text field_general_textarea field_general_wp_editor'
$items_settings['general_url'] = array(
'label' => __( 'URI Scheme', 'tbp' ),
'0' => __( 'None', 'tbp' ),
'tel' => __( 'Telephone', 'tbp' ),
'mailto' => __( 'Email', 'tbp' ),
'sms' => __( 'Text Message', 'tbp' ),
'fax' => __( 'Fax', 'tbp' ),
'wrap_class' => 'field_general_url',
$items_settings['general_condition'] = array(