: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
function et_theme_builder_decorate_page_resource_slug( $post_id, $resource_slug ) {
if ( ! is_numeric( $post_id ) || ! is_singular() ) {
$post_type = get_post_type( (int) $post_id );
if ( et_theme_builder_is_layout_post_type( $post_type ) ) {
$resource_slug .= '-tb-for-' . ET_Post_Stack::get_main_post_id();
$layout_types = et_theme_builder_get_layout_post_types();
$layouts = et_theme_builder_get_template_layouts();
foreach ( $layout_types as $type ) {
if ( ! isset( $layouts[ $type ] ) || ! $layouts[ $type ]['override'] ) {
$resource_slug .= '-tb-' . $layouts[ $type ]['id'];
add_filter( 'et_builder_cache_post_type', 'et_theme_builder_cache_post_type' );
* Clear cache of 3P caching plugins partially on the posts or all of them.
* @param string|array $post_ids 'all' or array of post IDs.
function et_theme_builder_clear_wp_cache( $post_ids = 'all' ) {
if ( ! et_pb_detect_cache_plugins() ) {
if ( empty( $post_ids ) ) {
if ( 'all' === $post_ids ) {
et_core_clear_wp_cache();
} else if ( is_array( $post_ids ) ) {
foreach( $post_ids as $post_id ) {
et_core_clear_wp_cache( $post_id );
* Clear cache of 3P caching plugins fully or partially after TB layouts saved.
* Clear all the cache when the template updated is:
* - Used on archive, 404, or all posts
function et_theme_builder_clear_wp_post_cache( $layout_id = '' ) {
$layout_type = get_post_type( $layout_id );
if ( ! et_theme_builder_is_layout_post_type( $layout_type ) ) {
if ( ! et_pb_detect_cache_plugins() ) {
// Get template of current TB layout.
$template = new WP_Query( array(
'post_type' => ET_THEME_BUILDER_TEMPLATE_POST_TYPE,
'post_status' => 'publish',
'update_post_meta_cache' => false,
'update_post_term_cache' => false,
'key' => "_{$layout_type}_id",
'key' => "_{$layout_type}_enabled",
'key' => '_et_theme_builder_marked_as_unused',
'compare' => 'NOT EXISTS',
if ( ! $template->have_posts() ) {
$template_id = $_->array_get( $template->posts, '0' );
$template_use_on = get_post_meta( $template_id, '_et_use_on', false );
$is_template_default = '1' === get_post_meta( $template_id, '_et_default', true );
// Unassigned Template - False or empty _et_use_on means it's unassigned.
if ( empty( $template_use_on ) ) {
// Clear All - If the template is 'default' because it's enabled globally.
if ( $is_template_default ) {
et_theme_builder_clear_wp_cache();
$target_post_ids = array();
foreach( $template_use_on as $location ) {
$location_pieces = explode( ':', $location );
$location_first = $_->array_get( $location_pieces, '0' );
$location_last = end( $location_pieces );
if ( in_array( $location_first, array( 'archive', '404' ) ) || 'all' === $location_last ) {
// Path: archive:user:id:{user_id}, singular:post_type:{post_type_slug}:all,
// archive:taxonomy:{taxonomy_name}:all, etc.
// Clear All - If the template is being used on 'archive:' or ':all' posts.
$target_post_ids = 'all';
} else if ( 'homepage' === $location_first ) {
$homepage_id = (int) get_option( 'page_on_front' );
$target_post_ids[] = $homepage_id;
// Clear All - If the homepage is non static page.
$target_post_ids = 'all';
} else if ( 'singular' === $location_first ) {
$singular_type = $_->array_get( $location_pieces, '3' );
if ( 'id' === $singular_type ) {
// Path: singular:post_type:{post_type_slug}:id:{post_id}
$target_post_ids[] = (int) $_->array_get( $location_pieces, '4' );
} else if ( 'children' === $singular_type ) {
// Path: singular:post_type:{post_type_slug}:children:id:{post_id}
$parent_id = (int) $_->array_get( $location_pieces, '5' );
$children_ids = get_children( array(
'post_parent' => $parent_id,
$target_post_ids = array_merge( $target_post_ids, $children_ids );
} else if ( 'term' === $singular_type ) {
// Path: singular:taxonomy:{taxonomy_name}:term:id:{term_id}
$taxonomy = $_->array_get( $location_pieces, '2' );
$taxonomy_object = get_taxonomy( $taxonomy );
$taxonomy_type = ! empty( $taxonomy_object->object_type ) ? $_->array_get( $taxonomy_object->object_type, '0' ) : 'post';
$term_id = (int) $_->array_get( $location_pieces, '5' );
$posts_ids = get_posts( array(
'post_type' => $taxonomy_type,
$target_post_ids = array_merge( $target_post_ids, $posts_ids );
} else if ( 'woocommerce' === $location_first && et_is_woocommerce_plugin_active() && function_exists( 'wc_get_page_id' ) ) {
// Path: woocommerce:my_account, woocommerce:cart, etc.
$woocommerce_page = str_replace( '_', '', $_->array_get( $location_pieces, '1' ) );
$woocommerce_page_id = wc_get_page_id( $woocommerce_page );
if ( $woocommerce_page_id ) {
$target_post_ids[] = $woocommerce_page_id;
// Remove duplicate posts.
if ( is_array( $target_post_ids ) ) {
$target_post_ids = array_unique( $target_post_ids );
et_theme_builder_clear_wp_cache( $target_post_ids );
add_action( 'et_save_post', 'et_theme_builder_clear_wp_post_cache' );