You've already forked wp-fedistream
fix: Block shortcode rendering during page template loading
All checks were successful
Create Release Package / build-release (push) Successful in 1m2s
All checks were successful
Create Release Package / build-release (push) Successful in 1m2s
- Added $loading_page_template flag in TemplateLoader - template-wrapper.php sets flag before loading theme header/footer - Shortcodes::render_template() returns early if flag is set - Prevents recursion from theme components, widgets, or other plugins Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -552,6 +552,12 @@ class Shortcodes {
|
||||
* @return string
|
||||
*/
|
||||
private function render_template( string $template, array $context ): string {
|
||||
// Block shortcode rendering while loading page template to prevent recursion.
|
||||
// This catches any shortcodes triggered by theme header/footer, widgets, etc.
|
||||
if ( TemplateLoader::is_loading_page_template() ) {
|
||||
return '<!-- FediStream: shortcode blocked during page template loading -->';
|
||||
}
|
||||
|
||||
// Check for unlicensed mode.
|
||||
if ( $this->unlicensed_mode ) {
|
||||
return $this->get_unlicensed_message();
|
||||
|
||||
@@ -44,6 +44,42 @@ class TemplateLoader {
|
||||
*/
|
||||
private static int $shortcode_context_depth = 0;
|
||||
|
||||
/**
|
||||
* Flag indicating we're currently loading a FediStream page template.
|
||||
* This completely blocks any nested FediStream shortcode rendering.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private static bool $loading_page_template = false;
|
||||
|
||||
/**
|
||||
* Enter page template loading mode.
|
||||
* This blocks ALL shortcode rendering during page template loading.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function enter_page_template_loading(): void {
|
||||
self::$loading_page_template = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exit page template loading mode.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function exit_page_template_loading(): void {
|
||||
self::$loading_page_template = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if we're loading a page template.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_loading_page_template(): bool {
|
||||
return self::$loading_page_template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enter shortcode rendering context.
|
||||
* Call this before rendering shortcode content to prevent recursive shortcode processing.
|
||||
|
||||
@@ -13,7 +13,10 @@ if ( ! defined( 'ABSPATH' ) ) {
|
||||
use WP_FediStream\Plugin;
|
||||
use WP_FediStream\Frontend\TemplateLoader;
|
||||
|
||||
// Enter shortcode context to prevent recursive shortcode processing in post content.
|
||||
// Enter page template loading mode - this completely blocks nested FediStream rendering.
|
||||
TemplateLoader::enter_page_template_loading();
|
||||
|
||||
// Also enter shortcode context to prevent recursive shortcode processing in post content.
|
||||
TemplateLoader::enter_shortcode_context();
|
||||
|
||||
// Get template context.
|
||||
@@ -78,7 +81,8 @@ get_header();
|
||||
</main>
|
||||
|
||||
<?php
|
||||
// Exit shortcode context.
|
||||
// Exit shortcode context and page template loading mode.
|
||||
TemplateLoader::exit_shortcode_context();
|
||||
TemplateLoader::exit_page_template_loading();
|
||||
|
||||
get_footer();
|
||||
|
||||
Reference in New Issue
Block a user