PluginProbe
Forumax – AI Powered Advanced Community Forum Plugin / 2.5.1
Forumax – AI Powered Advanced Community Forum Plugin v2.5.1
2.5.1 2.5.0 2.4.4 2.4.3 2.4.2 2.4.1 2.4.0 trunk 1.0.8 1.1.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 All 31 releases
bbp-core / templates / bbpress-wrapper.php

bbpress-wrapper.php in Forumax – AI Powered Advanced Community Forum Plugin 2.5.1, at templates/bbpress-wrapper.php

132 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Forumax – bbPress Wrapper Template for Block / FSE Themes
4 *
5 * Provides a complete page scaffold that works with block (FSE) themes which do
6 * not ship classic PHP template files (header.php, footer.php, etc.).
7 *
8 * NOTE: We do NOT manually render the sidebar here. Forumax's own templates
9 * (content-archive-forum.php, content-single-topic.php, etc.) already render
10 * the sidebar via their own layout containers. Rendering it again here would
11 * produce duplicate sidebars. We only provide the outer page chrome.
12 *
13 * @package Forumax
14 * @since 2.3.1
15 */
16
17 defined( 'ABSPATH' ) || exit;
18
19 /**
20 * Safely get rendered block template part HTML with fallback.
21 *
22 * In block (FSE) themes, template parts must be rendered before wp_head() so
23 * that Gutenberg layout styles (flex, space-between, gap, constrained layout, etc.)
24 * are registered in the Style Engine and enqueued via wp_enqueue_stored_styles() in <head>.
25 *
26 * @param string $part The template part name (e.g., 'header', 'footer').
27 * @param string $tag_name Optional HTML tag name (e.g., 'header', 'footer').
28 * @return string Rendered HTML.
29 */
30 function forumax_get_block_template_part_html( $part, $tag_name = '' ) {
31 if ( empty( $tag_name ) ) {
32 $tag_name = ( 'header' === $part || 'footer' === $part ) ? $part : 'div';
33 }
34
35 if ( function_exists( 'get_block_template' ) ) {
36 $template_part = get_block_template( get_stylesheet() . '//' . $part, 'wp_template_part' );
37 if ( ! $template_part && get_stylesheet() !== get_template() ) {
38 $template_part = get_block_template( get_template() . '//' . $part, 'wp_template_part' );
39 }
40
41 if ( $template_part && function_exists( 'do_blocks' ) ) {
42 return do_blocks( '<!-- wp:template-part {"slug":"' . esc_attr( $part ) . '","tagName":"' . esc_attr( $tag_name ) . '"} /-->' );
43 }
44 }
45
46 // Fallback if no block template part found.
47 ob_start();
48 if ( 'header' === $part ) {
49 forumax_minimal_header();
50 } elseif ( 'footer' === $part ) {
51 forumax_minimal_footer();
52 }
53 return ob_get_clean();
54 }
55
56 /**
57 * Safely render a block template part with fallback.
58 *
59 * @param string $part The template part name (e.g., 'header', 'footer').
60 */
61 function forumax_render_block_template_part( $part ) {
62 echo forumax_get_block_template_part_html( $part );
63 }
64
65 /**
66 * Minimal header fallback when theme has no header template part.
67 */
68 function forumax_minimal_header() {
69 ?>
70 <header class="forumax-fallback-header" style="padding: 20px 40px; border-bottom: 1px solid #eee;">
71 <div style="max-width: 1200px; margin: 0 auto;">
72 <a href="<?php echo esc_url( home_url( '/' ) ); ?>" style="text-decoration: none; color: inherit;">
73 <strong><?php bloginfo( 'name' ); ?></strong>
74 </a>
75 </div>
76 </header>
77 <?php
78 }
79
80 /**
81 * Minimal footer fallback when theme has no footer template part.
82 */
83 function forumax_minimal_footer() {
84 ?>
85 <footer class="forumax-fallback-footer" style="padding: 20px 40px; border-top: 1px solid #eee; margin-top: 40px;">
86 <div style="max-width: 1200px; margin: 0 auto; text-align: center; color: #666;">
87 &copy; <?php echo esc_html( gmdate( 'Y' ) ); ?> <?php bloginfo( 'name' ); ?>
88 </div>
89 </footer>
90 <?php
91 }
92
93 // Pre-render header and footer before wp_head() so Gutenberg collects block support layout styles.
94 $forumax_header_html = forumax_get_block_template_part_html( 'header', 'header' );
95 $forumax_footer_html = forumax_get_block_template_part_html( 'footer', 'footer' );
96 ?><!DOCTYPE html>
97 <html <?php language_attributes(); ?>>
98 <head>
99 <meta charset="<?php bloginfo( 'charset' ); ?>">
100 <meta name="viewport" content="width=device-width, initial-scale=1">
101 <?php wp_head(); ?>
102 </head>
103 <body <?php body_class(); ?>>
104 <?php wp_body_open(); ?>
105
106 <?php echo $forumax_header_html; ?>
107
108 <main id="frmx-bbpress-main" class="frmx-bbpress-page">
109 <?php
110 // Check if bbPress has content to display
111 if ( function_exists( 'bbp_is_single_forum' ) && ( bbp_is_single_forum() || bbp_is_single_topic() || bbp_is_single_reply() || bbp_is_topic_archive() || bbp_is_forum_archive() || bbp_is_single_user() || bbp_is_single_view() || bbp_is_search() || bbp_is_topic_tag() ) ) {
112 // Use bbPress content
113 while ( have_posts() ) :
114 the_post();
115 the_content();
116 endwhile;
117 } else {
118 // Fallback - just show the content
119 while ( have_posts() ) :
120 the_post();
121 the_content();
122 endwhile;
123 }
124 ?>
125 </main>
126
127 <?php echo $forumax_footer_html; ?>
128
129 <?php wp_footer(); ?>
130 </body>
131 </html>
132