You've already forked wp-fedistream
fix: Complete memory leak fix for shortcode context handling
All checks were successful
Create Release Package / build-release (push) Successful in 58s
All checks were successful
Create Release Package / build-release (push) Successful in 58s
- Changed shortcode context from boolean to depth counter for nested shortcodes - Added shortcode context protection to template-wrapper.php for single page views - Fixes remaining recursion path in single FediStream post views Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -36,12 +36,13 @@ class TemplateLoader {
|
||||
private const MAX_RECURSION_DEPTH = 3;
|
||||
|
||||
/**
|
||||
* Whether we're currently in a shortcode rendering context.
|
||||
* When true, the_content filter is skipped to prevent recursive shortcode processing.
|
||||
* Shortcode rendering context depth counter.
|
||||
* When > 0, the_content filter is skipped to prevent recursive shortcode processing.
|
||||
* Using a counter instead of boolean to handle nested shortcodes properly.
|
||||
*
|
||||
* @var bool
|
||||
* @var int
|
||||
*/
|
||||
private static bool $in_shortcode_context = false;
|
||||
private static int $shortcode_context_depth = 0;
|
||||
|
||||
/**
|
||||
* Enter shortcode rendering context.
|
||||
@@ -50,7 +51,7 @@ class TemplateLoader {
|
||||
* @return void
|
||||
*/
|
||||
public static function enter_shortcode_context(): void {
|
||||
self::$in_shortcode_context = true;
|
||||
++self::$shortcode_context_depth;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,7 +61,9 @@ class TemplateLoader {
|
||||
* @return void
|
||||
*/
|
||||
public static function exit_shortcode_context(): void {
|
||||
self::$in_shortcode_context = false;
|
||||
if ( self::$shortcode_context_depth > 0 ) {
|
||||
--self::$shortcode_context_depth;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,7 +72,7 @@ class TemplateLoader {
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_in_shortcode_context(): bool {
|
||||
return self::$in_shortcode_context;
|
||||
return self::$shortcode_context_depth > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -253,7 +256,7 @@ class TemplateLoader {
|
||||
// Skip the_content filter if:
|
||||
// 1. We're in a shortcode context (prevents recursive shortcode processing)
|
||||
// 2. We're at depth > 1 (nested data loading)
|
||||
$skip_content_filter = self::$in_shortcode_context || self::$recursion_depth > 1;
|
||||
$skip_content_filter = self::$shortcode_context_depth > 0 || self::$recursion_depth > 1;
|
||||
|
||||
$data = array(
|
||||
'id' => $post->ID,
|
||||
|
||||
Reference in New Issue
Block a user