diff --git a/includes/class-geodir-block-theme.php b/includes/class-geodir-block-theme.php index 873eaf5c..0272517a 100644 --- a/includes/class-geodir-block-theme.php +++ b/includes/class-geodir-block-theme.php @@ -952,11 +952,10 @@ public static function gutenberg_build_template_result_from_file( $template_file $template_is_from_theme = 'theme' === $template_file->source; $theme_name = wp_get_theme()->get( 'TextDomain' ); - $template_content = file_get_contents( $template_file->path ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents - $template = new \WP_Block_Template(); - $template->id = $template_is_from_theme ? $theme_name . '//' . $template_file->slug : self::PLUGIN_SLUG . '//' . $template_file->slug; - $template->theme = $template_is_from_theme ? $theme_name : self::PLUGIN_SLUG; - $template->content = _inject_theme_attribute_in_block_template_content( $template_content ); + $template = new \WP_Block_Template(); + $template->id = $template_is_from_theme ? $theme_name . '//' . $template_file->slug : self::PLUGIN_SLUG . '//' . $template_file->slug; + $template->theme = $template_is_from_theme ? $theme_name : self::PLUGIN_SLUG; + $template->content = @file_get_contents( $template_file->path ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents $template->source = $template_file->source ? $template_file->source : 'plugin'; $template->slug = $template_file->slug; $template->type = $template_type; @@ -970,6 +969,20 @@ public static function gutenberg_build_template_result_from_file( $template_file $template->area = 'uncategorized'; } + if ( function_exists( '_inject_theme_attribute_in_template_part_block' ) ) { + $before_block_visitor = '_inject_theme_attribute_in_template_part_block'; + $after_block_visitor = null; + $hooked_blocks = get_hooked_blocks(); + if ( ! empty( $hooked_blocks ) || has_filter( 'hooked_block_types' ) ) { + $before_block_visitor = make_before_block_visitor( $hooked_blocks, $template ); + $after_block_visitor = make_after_block_visitor( $hooked_blocks, $template ); + } + $blocks = parse_blocks( $template->content ); + $template->content = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor ); + } else if ( function_exists( '_inject_theme_attribute_in_block_template_content' ) ) { + $template->content = _inject_theme_attribute_in_block_template_content( $template->content ); + } + return $template; } @@ -1255,7 +1268,15 @@ public static function get_default_wp_template_html( $page, $template_type = 'wp $content = @file_get_contents( $template_path ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents if ( $content ) { - $content = _inject_theme_attribute_in_block_template_content( $content ); + if ( function_exists( '_inject_theme_attribute_in_template_part_block' ) ) { + $before_block_visitor = '_inject_theme_attribute_in_template_part_block'; + $after_block_visitor = null; + + $blocks = parse_blocks( $content ); + $content = traverse_and_serialize_blocks( $blocks, $before_block_visitor, $after_block_visitor ); + } else if ( function_exists( '_inject_theme_attribute_in_block_template_content' ) ) { + $content = _inject_theme_attribute_in_block_template_content( $content ); + } } } diff --git a/readme.txt b/readme.txt index 9d6753b8..0edc6e8e 100644 --- a/readme.txt +++ b/readme.txt @@ -308,6 +308,7 @@ __WARNING: GDv2 is a significant update over GDv1 and may require manual work, s = GeoDirectory v2.3.38 - TBD = * GD > Post Features shows fields label special chars encoded incorrectly - FIXED * Category icon not generated from FontAweosme icons for some sites - FIXED +* Function _inject_theme_attribute_in_block_template_content is deprecated - FIXED = GeoDirectory v2.3.37 - 2024-01-25 = * OSM layer url shows apikey parameter twice for custom style map - FIXED