Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
CRAP
n/a
0 / 0
Automattic\Jetpack\Jetpack_Mu_Wpcom\Wpcom_Legacy_FSE\render_template_block
0.00% covered (danger)
0.00%
0 / 14
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2/**
3 * Render template block file.
4 *
5 * @package automattic/jetpack-mu-wpcom
6 */
7
8namespace Automattic\Jetpack\Jetpack_Mu_Wpcom\Wpcom_Legacy_FSE;
9
10use Automattic\Jetpack\Jetpack_Mu_Wpcom\Common;
11
12/**
13 * Renders template.
14 *
15 * @param array $attributes Block attributes.
16 * @return string
17 */
18function render_template_block( $attributes ) {
19    if ( ! isset( $attributes['templateId'] ) || ! is_int( $attributes['templateId'] ) ) {
20        return '';
21    }
22
23    Common\wpcom_record_tracks_event( 'wpcom_legacy_fse_render_block', array( 'block_name' => 'a8c/template' ) );
24
25    $template = get_post( $attributes['templateId'] );
26
27    $align = isset( $attributes['align'] ) ? ' align' . $attributes['align'] : '';
28
29    setup_postdata( $template );
30    ob_start();
31    ?>
32
33        <div class="template<?php echo esc_attr( $align ); ?>">
34            <?php
35            // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
36            echo apply_filters( 'the_content', get_the_content() );
37            ?>
38        </div><!-- .template -->
39
40    <?php
41    $content = ob_get_clean();
42    wp_reset_postdata();
43
44    return $content;
45}