content ) ) { return $template; } // Render before wp_head(), so layout rules and block styles print in the head. self::$html = self::render( $block_template->content ); return Helper::plugin_path() . 'templates/block-template-classic.php'; } /** * The template saved in the Site Editor for this theme, or Academy's own. * * @param string $slug Template slug. * @return \WP_Block_Template|null */ public static function find( $slug ) { $saved = get_block_template( get_stylesheet() . '//' . $slug ); if ( $saved && ! empty( $saved->content ) ) { return $saved; } return get_block_template( ACADEMY_PLUGIN_SLUG . '//' . $slug ); } /** * Render a template body without its header and footer template parts, * which the classic theme provides. * * @param string $content Template content. * @return string */ private static function render( $content ) { $blocks = array_filter( parse_blocks( $content ), function ( $block ) { if ( 'core/template-part' !== $block['blockName'] ) { return true; } $slug = isset( $block['attrs']['slug'] ) ? $block['attrs']['slug'] : ''; $tag = isset( $block['attrs']['tagName'] ) ? $block['attrs']['tagName'] : ''; return ! in_array( $slug, [ 'header', 'footer' ], true ) && ! in_array( $tag, [ 'header', 'footer' ], true ); } ); $html = do_blocks( serialize_blocks( $blocks ) ); $html = wptexturize( $html ); $html = convert_smilies( $html ); return wp_filter_content_tags( $html, 'template' ); } /** * Rendered body for the wrapper template. * * @return string */ public static function content() { return (string) self::$html; } }