Skip to content

Instantly share code, notes, and snippets.

@imath
Created May 12, 2021
Embed
What would you like to do?
Workaround to load BP Templates into WP FSE
<?php
function g_buddypress_template( $template ) {
if ( ! function_exists( 'gutenberg_dir_path' ) ) {
return $template;
}
return gutenberg_dir_path() . 'lib/template-canvas.php';
}
add_filter( 'bp_buddypress_template', 'g_buddypress_template', 10, 1 );
function g_buddypress_render_post_content( $attributes, $content = '', $block ) {
if ( ! in_the_loop() ) {
the_post();
}
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => 'entry-content' ) );
/** This filter is documented in wp-includes/post-template.php */
$content = apply_filters( 'the_content', str_replace( ']]>', ']]&gt;', $content ) );
return (
'<div ' . $wrapper_attributes . '>' .
$content .
'</div>'
);
}
function g_buddypress_override_post_content_renderer( $settings = array(), $metadata = array() ) {
if ( 'core/post-content' === $metadata['name'] && is_buddypress() ) {
$settings['render_callback'] = 'g_buddypress_render_post_content';
}
return $settings;
}
add_filter( 'block_type_metadata_settings', 'g_buddypress_override_post_content_renderer', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment