PluginProbe
Gutenberg / 12.1.0
Gutenberg v12.1.0
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / build / block-library / blocks / post-comments-form.php

post-comments-form.php in Gutenberg 12.1.0, at build/block-library/blocks/post-comments-form.php

64 lines 1.9 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 the `core/post-comments-form` block.
4 *
5 * @package WordPress
6 */
7
8 /**
9 * Renders the `core/post-comments-form` block on the server.
10 *
11 * @param array $attributes Block attributes.
12 * @param string $content Block default content.
13 * @param WP_Block $block Block instance.
14 * @return string Returns the filtered post comments form for the current post.
15 */
16 function gutenberg_render_block_core_post_comments_form( $attributes, $content, $block ) {
17 if ( ! isset( $block->context['postId'] ) ) {
18 return '';
19 }
20
21 $classes = '';
22 if ( isset( $attributes['textAlign'] ) ) {
23 $classes .= 'has-text-align-' . $attributes['textAlign'];
24 }
25
26 ob_start();
27 comment_form( array(), $block->context['postId'] );
28 $form = ob_get_clean();
29 $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );
30
31 // Enqueue the comment-reply script.
32 wp_enqueue_script( 'comment-reply' );
33
34 return sprintf( '<div %1$s>%2$s</div>', $wrapper_attributes, $form );
35 }
36
37 /**
38 * Registers the `core/post-comments-form` block on the server.
39 */
40 function gutenberg_register_block_core_post_comments_form() {
41 register_block_type_from_metadata(
42 __DIR__ . '/post-comments-form',
43 array(
44 'render_callback' => 'gutenberg_render_block_core_post_comments_form',
45 )
46 );
47 }
48 add_action( 'init', 'gutenberg_register_block_core_post_comments_form', 20 );
49
50 /**
51 * Use the button block classes for the form-submit button.
52 *
53 * @param array $fields The default comment form arguments.
54 *
55 * @return array Returns the modified fields.
56 */
57 function gutenberg_gutenberg_comment_form_block_form_defaults( $fields ) {
58 $fields['submit_button'] = '<input name="%1$s" type="submit" id="%2$s" class="%3$s wp-block-button__link" value="%4$s" />';
59 $fields['submit_field'] = '<p class="form-submit wp-block-button">%1$s %2$s</p>';
60
61 return $fields;
62 }
63 add_filter( 'comment_form_defaults', 'gutenberg_gutenberg_comment_form_block_form_defaults' );
64