PluginProbe
WP Discourse / trunk
WP Discourse vtrunk
2.6.4 2.6.3 1.2.1 1.2.2 1.2.5 1.2.6 1.2.7 1.2.8 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.85 1.4.0 1.4.15 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 All 150 releases
wp-discourse / blocks / comments / comments.php

comments.php in WP Discourse trunk, at blocks/comments/comments.php

56 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Server-side rendering of wp-discourse blocks.
4 *
5 * @package WPDiscourse
6 */
7
8 use WPDiscourse\DiscourseCommentFormatter\DiscourseCommentFormatter;
9 use WPDiscourse\DiscourseComment\DiscourseComment;
10
11 /**
12 * Renders the `wp-discourse/comments` block on the server.
13 *
14 * @param array $attributes Block attributes.
15 * @param string $content Block default content.
16 * @param WP_Block $block Block instance.
17 * @return string Returns the filtered post comments for the current post wrapped inside "p" tags.
18 */
19 function render_block_wpdc_comments( $attributes, $content, $block ) {
20 $post_id = $block->context['postId'];
21 if ( ! isset( $post_id ) ) {
22 return '';
23 }
24
25 $comment_formatter = new DiscourseCommentFormatter();
26 $comment = new DiscourseComment( $comment_formatter );
27 $default = '';
28
29 $comment->setup_options();
30 $comment_formatter->setup_options();
31
32 ob_start();
33
34 $comment->comments_template( $default );
35 $result = ob_get_contents();
36
37 ob_end_clean();
38
39 return $result;
40 }
41
42 /**
43 * Registers the `wp-discourse/comments` block on the server.
44 */
45 function register_wpdc_blocks() {
46 if ( version_compare( get_bloginfo( 'version' ), '5.5', '>=' ) ) {
47 register_block_type_from_metadata(
48 WPDISCOURSE_PATH . 'blocks/comments/build/block.json',
49 array(
50 'render_callback' => 'render_block_wpdc_comments',
51 )
52 );
53 }
54 }
55 add_action( 'init', 'register_wpdc_blocks' );
56