0 ) { return $template; } // Use our wrapper as last resort. $wrapper = FORUMAX_PATH . 'templates/bbpress-wrapper.php'; if ( file_exists( $wrapper ) ) { return $wrapper; } return $template; } /** * Handle bbPress shortcode on regular pages in block themes. * * Edge Case: When bbPress shortcode [bbp-forum-index] is used on a regular * page (not bbPress archive), we need to ensure styles are loaded. */ add_action( 'wp', 'forumax_handle_bbpress_shortcode_pages' ); function forumax_handle_bbpress_shortcode_pages() { if ( ! forumax_is_block_theme() ) { return; } // Check if current page/post has bbPress shortcodes. if ( ! is_singular() ) { return; } $post = get_post(); if ( ! $post ) { return; } // List of bbPress shortcodes. $bbpress_shortcodes = array( 'bbp-forum-index', 'bbp-forum-form', 'bbp-single-forum', 'bbp-topic-index', 'bbp-topic-form', 'bbp-single-topic', 'bbp-reply-form', 'bbp-single-reply', 'bbp-single-view', 'bbp-search-form', 'bbp-search', 'bbp-login', 'bbp-register', 'bbp-lost-pass', ); $has_bbpress_shortcode = false; foreach ( $bbpress_shortcodes as $shortcode ) { if ( has_shortcode( $post->post_content, $shortcode ) ) { $has_bbpress_shortcode = true; break; } } // Also check for bbPress blocks. if ( ! $has_bbpress_shortcode && function_exists( 'has_block' ) ) { $bbpress_blocks = array( 'bbpress/forum-index', 'bbpress/topic-index', 'forumax/forums' ); foreach ( $bbpress_blocks as $block ) { if ( has_block( $block, $post ) ) { $has_bbpress_shortcode = true; break; } } } if ( $has_bbpress_shortcode ) { // Add body class for styling. add_filter( 'body_class', function( $classes ) { $classes[] = 'forumax-shortcode-page'; $classes[] = 'forumax-fse'; return $classes; } ); // Ensure bbPress styles are loaded. add_action( 'wp_enqueue_scripts', 'forumax_fse_ensure_assets', 100 ); } } /** * Add bbPress body classes even on block themes. * * @param array $classes Existing body classes. * @return array Modified body classes. */ add_filter( 'body_class', 'forumax_add_bbpress_body_classes_on_fse', 20 ); function forumax_add_bbpress_body_classes_on_fse( $classes ) { if ( ! forumax_is_block_theme() ) { return $classes; } if ( ! function_exists( 'is_bbpress' ) || ! is_bbpress() ) { return $classes; } if ( ! in_array( 'bbpress', $classes, true ) ) { $classes[] = 'bbpress'; } if ( ! in_array( 'forumax-fse', $classes, true ) ) { $classes[] = 'forumax-fse'; } // Edge Case: Add specific page type classes for better styling control. if ( function_exists( 'bbp_is_single_forum' ) && bbp_is_single_forum() ) { $classes[] = 'forumax-single-forum'; } elseif ( function_exists( 'bbp_is_single_topic' ) && bbp_is_single_topic() ) { $classes[] = 'forumax-single-topic'; } elseif ( function_exists( 'bbp_is_forum_archive' ) && bbp_is_forum_archive() ) { $classes[] = 'forumax-forum-archive'; } elseif ( function_exists( 'bbp_is_topic_archive' ) && bbp_is_topic_archive() ) { $classes[] = 'forumax-topic-archive'; } elseif ( function_exists( 'bbp_is_single_user' ) && bbp_is_single_user() ) { $classes[] = 'forumax-user-profile'; } elseif ( function_exists( 'bbp_is_search' ) && bbp_is_search() ) { $classes[] = 'forumax-search'; } return $classes; } /** * Add critical inline CSS for FSE themes. * * Ensures basic layout works even if external CSS fails to load. */ add_action( 'wp_head', 'forumax_fse_critical_css', 5 ); function forumax_fse_critical_css() { if ( ! forumax_is_block_theme() ) { return; } // Check for bbPress page OR shortcode page. $is_bbpress_page = function_exists( 'is_bbpress' ) && is_bbpress(); $is_shortcode_page = in_array( 'forumax-shortcode-page', get_body_class(), true ); if ( ! $is_bbpress_page && ! $is_shortcode_page ) { return; } ?>