Skip to content

Control the flow based on fse theme or not, to avoid accidently using…#38

Merged
gin0115 merged 1 commit intotrunkfrom
fix/archive-template-issue
Aug 14, 2025
Merged

Control the flow based on fse theme or not, to avoid accidently using…#38
gin0115 merged 1 commit intotrunkfrom
fix/archive-template-issue

Conversation

@gin0115
Copy link
Collaborator

@gin0115 gin0115 commented Aug 14, 2025

… event archives on non event archives

Changes proposed in this Pull Request

  • Ensure that php template logic is ignored if an FSE theme
  • Ensure that we try to find archives as .html or .php nased on block theme.

Testing instructions

Mentions #

Summary by CodeRabbit

  • Bug Fixes
    • Improved compatibility with WordPress block (FSE) themes by no longer intercepting the theme’s canvas template, ensuring native rendering is preserved.
    • Corrected event archive template resolution to automatically choose the proper hierarchy for block vs. classic themes, delivering consistent layouts across environments.
    • Non-block themes retain existing behavior, avoiding regressions and ensuring stable template loading for single events, date-based archives, and other views.

@coderabbitai
Copy link

coderabbitai bot commented Aug 14, 2025

Walkthrough

  • Added an early return in SE_Template_Loader::template_include to skip custom template resolution when wp_is_block_theme() is true and the template path contains 'template-canvas.php'.
  • Updated se_fix_se_events_fse_archive_template to select between two hierarchies based on theme type: for block themes, return an HTML-based archive hierarchy; for non-block themes, return a PHP-based hierarchy. No public signatures changed.

Possibly related PRs

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🔭 Outside diff range comments (2)
src/classes/class-se-template-loader.php (2)

58-71: This condition hijacks all archives; use the proper taxonomy check.

is_archive() ignores its argument and returns true for any archive type, causing this branch to run on unrelated archives and return an events template. This is the likely source of “accidentally using event archives on non-event archives.”

Apply this diff:

-		if ( is_archive( 'se-event-category' ) ) {
+		if ( is_tax( 'se-event-category' ) ) {
 			$theme_templates = array(
 				'archive-se-event.php',
 			);
 
 			// Determine if any of these templates is available in the theme.
 			$archive_event_template = get_query_template( 'archive', $theme_templates );
 			if ( $archive_event_template ) {
 				return $archive_event_template;
 			} else {
 				return self::locate_template( array( 'archive.php' ) );
 			}
 		}

108-120: Use is_post_type_archive for the se-event-date archive branch.

Same issue as above: is_archive('se-event-date') doesn’t target the intended CPT archive and can run on any archive view.

Apply this diff:

-		if ( is_archive( 'se-event-date' ) ) {
+		if ( is_post_type_archive( 'se-event-date' ) ) {
 			$theme_templates = array(
 				'archive-se-event.php',
 			);
 
 			// Determine if any of these templates is available in the theme.
 			$archive_event_template = get_query_template( 'archive', $theme_templates );
 			if ( $archive_event_template ) {
 				return $archive_event_template;
 			}
 
 			$fallback_template = 'archive.php';
 		}
🧹 Nitpick comments (2)
src/template-functions.php (2)

640-649: Add explicit index fallbacks to both hierarchies.

If neither archive-se-event.* nor archive.* exists, having index.* as a final fallback is safer and mirrors WP’s standard hierarchy.

Apply this diff:

-			$custom_hierarchy_fse    = array(
+			$custom_hierarchy_fse    = array(
 				'archive-se-event.html',
-				'archive.html',
+				'archive.html',
+				'index.html',
 			);
-			$custom_hierarchy_legacy = array(
+			$custom_hierarchy_legacy = array(
 				'archive-se-event.php',
-				'archive.php',
+				'archive.php',
+				'index.php',
 			);

637-649: Prefer is_post_type_archive check over reading post_type query var.

Using the conditional API is more robust than get_query_var('post_type'), especially with complex queries or rewritten URLs.

Outside the selected range, consider:

if ( is_post_type_archive( 'se-event-date' ) ) {
    // existing hierarchy logic...
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these settings in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between a253b93 and 7609c49.

📒 Files selected for processing (2)
  • src/classes/class-se-template-loader.php (1 hunks)
  • src/template-functions.php (1 hunks)
🔇 Additional comments (1)
src/template-functions.php (1)

640-649: Good separation of FSE vs legacy hierarchies.

Choosing between .html and .php hierarchies based on wp_is_block_theme() is the right direction and aligns with WP’s template resolution paths.

Comment on lines +33 to +36
if ( wp_is_block_theme() && str_contains( $template, 'template-canvas.php' ) ) {
return $template;
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Avoid PHP 8-only str_contains and broaden the FSE guard to fully skip PHP template logic.

  • str_contains requires PHP 8; use strpos for broader compatibility.
  • Per the PR summary (“ignore PHP template logic when an FSE theme is active”), short-circuiting on any block theme is safer than only when template-canvas.php is present. The current guard is too narrow and may still hijack non-event archives via downstream logic.

Two options:

  • Option A (recommended): Bail early for all block themes.
-		if ( wp_is_block_theme() && str_contains( $template, 'template-canvas.php' ) ) {
-			return $template;
-		}
+		if ( wp_is_block_theme() ) {
+			return $template;
+		}
  • Option B (minimal): Keep the specific guard but switch to strpos for PHP 7.4 compatibility.
-		if ( wp_is_block_theme() && str_contains( $template, 'template-canvas.php' ) ) {
+		if ( wp_is_block_theme() && false !== strpos( $template, 'template-canvas.php' ) ) {
 			return $template;
 		}

Note: If you keep Option B, consider making the guard broader (additional known PHP-based canvas names) or adding a filter to let sites opt-out of the loader entirely on block themes.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if ( wp_is_block_theme() && str_contains( $template, 'template-canvas.php' ) ) {
return $template;
}
if ( wp_is_block_theme() ) {
return $template;
}
🤖 Prompt for AI Agents
In src/classes/class-se-template-loader.php around lines 33 to 36, the current
guard uses PHP 8-only str_contains and only short-circuits when
'template-canvas.php' is present; update this to either (recommended)
immediately return $template whenever wp_is_block_theme() is true to fully skip
any PHP template logic on FSE/block themes, or (minimal) replace str_contains
with a PHP 7.4-compatible strpos check (e.g. strpos($template,
'template-canvas.php') !== false) and consider expanding the needle list or
adding a filter for opt-out; implement the chosen change so the loader bails out
earlier and avoids hijacking non-event archives on block themes.

Comment on lines +640 to 649
$custom_hierarchy_fse = array(
'archive-se-event.html',
'archive.html',
);

return $custom_hierarchy;
$custom_hierarchy_legacy = array(
'archive-se-event.php',
'archive.php',
);
return wp_is_block_theme() ? $custom_hierarchy_fse : $custom_hierarchy_legacy;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Verify this function is actually hooked for both PHP and block template hierarchies.

Returning .html entries only helps if the function is tied to the appropriate hierarchy filter(s). Ensure you hook this for archives in both classic and block contexts (e.g., archive_template_hierarchy for PHP; verify whether your block theme path is reached by filters you control).

Run this script to confirm hooks:


🏁 Script executed:

#!/bin/bash
# Find where se_fix_se_events_fse_archive_template is hooked.
rg -n "se_fix_se_events_fse_archive_template" -A 3

# Check for archive hierarchy filters or similar
rg -n "add_filter\([^)]*archive_template_hierarchy" -A 2

# Look for block template related hooks (if any)
rg -n "add_filter\([^)]*block_template" -A 2

# Also check if se_event_archive_template() is hooked anywhere (to avoid conflicting paths).
rg -n "se_event_archive_template\s*\(" -A 2

Length of output: 1844


Hook se_fix_se_events_fse_archive_template into the block template hierarchy
You’re only filtering archive_template_hierarchy (classic PHP). To ensure your .html FSE archive templates are picked up in block themes, also register this callback on block_template_hierarchy.

• src/template-hooks.php—add alongside the existing hook:

 add_filter( 'archive_template_hierarchy', 'se_fix_se_events_fse_archive_template' );
+add_filter( 'block_template_hierarchy',   'se_fix_se_events_fse_archive_template', 10, 2 );

• src/template-functions.php—accept the extra parameter when hooked into block hierarchy:

- function se_fix_se_events_fse_archive_template( $templates ) {
+ function se_fix_se_events_fse_archive_template( $templates, $type = '' ) {
     if ( 'se-event-date' === get_query_var( 'post_type' ) ) {
         $custom_hierarchy_fse    = array(
             'archive-se-event.html',
             'archive.html',
         );
         $custom_hierarchy_legacy = array(
             'archive-se-event.php',
             'archive.php',
         );
         return wp_is_block_theme() ? $custom_hierarchy_fse : $custom_hierarchy_legacy;
     }
 }
🤖 Prompt for AI Agents
In src/template-functions.php around lines 640 to 649, the function returns
different hierarchies for block themes (.html) vs classic themes but is only
hooked into the classic PHP filter; update the hook registration in
src/template-hooks.php to also add this callback to the block_template_hierarchy
filter, and modify the function signature (or add handling) so it accepts the
extra parameter passed by block_template_hierarchy (typically $templates, $type
or similar) when used for block themes; ensure the function still returns the
same arrays but can accept and ignore the extra argument when invoked via
block_template_hierarchy.

@gin0115 gin0115 merged commit ec1beae into trunk Aug 14, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant