WordPress/wp-includes/blocks/post-comments.php
noisysocks 935058d178 Update @wordpress packages
Update packages to include these bug fixes from Gutenberg:

- Image block: Set image display to grid when no alignment sent to properly align caption on resize
- Update and align template descriptions
- Site Editor - prevent loading state from showing the admin menu.
- Add client side routing for Site Editor
- Navigation: Add clearance for appender in submenus.
- Fix CSS Custom Properties for presets in the site editor
- Add/navigation blocks post processing after migration from menu items
- Allow selector ordering to ensure theme.json root selector margin takes precedence 
- Do not remove theme presets if defaults are hidden
- Format library: fix unsetting highlight color
- FSE: Fix template resolution to give precedence to child theme PHP templates over parent theme block templates with equal specificity
- ColorPalette: Improving accessibility and visibility
- Update: Make the color popover on the gradient picker appear as expected
- Site Editor: Display a notice if export fails
- Fix docs and function naming for gallery block registration in PHP
- Switch to addEventListener for load event in the navigation block view script
- Fix mistake in _remove_theme_attribute_in_block_template_content
- Better synchronisation between Gutenberg and Core code
- Move the block page templates hook into compat/5.9 folder
- Moves to the template loader hooks and functions into lib/compat folder
- Refactor the gutenberg_is_fse_theme function to use wp_is_block_theme
- Site Editor: Update support doc URL in Welcome Guide
- Global Styles: Add Welcome Guide toggle
- Hide remove control point when removing would break gradient control
- Don't request the deprecated navigation areas endpoint outside of the Gutenberg plugin
- Image: Fix resizer controls being hidden in Safari when switching between alignments
- Remove Navigation Menus from WP Admin sidebar
- Site Editor: Hide the block appender in the Template Part editor
- Site Editor: Use server definition for the Template Areas
- Synchronize wp_is_block_theme and block-templates block support with Core
- E2E: Retry login again after a bad nonce request to prevent intermittent test failures 
- Fix theme requirement validation with WP 5.8
- Fix WP 5.9 check for conditionally running code
- Fix post comment form input width
- Border Style Control: Update styling for consistency with border width control
- Fix form-submit styles by adding button classes to the submit-button in post-comments block
- Site Editor: Fix edit template part link in header dropdown
- Move duotone palette to the bottom of global styles gradients
- Fix how appearanceTools works
- Move WP 5.9 wp-admin menus compatibility code to lib/compat folder
- Revert "Site Editor: Set the <title> on the list page to be same as the CPT name"
- Site Editor: Document Actions: add SR text to heading 1
- Do not register global styles CPT in WordPress 5.9
- Global Styles: Move the 'Edit colors' button to a standard menu item
- Fix styles for previews and patterns
- Site Editor: Fix failing E2E test
- Templates: Search for old template names in the parent theme too
- Remove 4 instances of 'gutenberg' text domain from WordPress core
- Fix content loss when ungrouping template parts or reusable blocks
- Simplify the RESET_BLOCK action to fix template part focus mode content loss
- [Global Styles]: Make Blocks section more distinguishable
- Only use block markup for comment form button when using a block theme
- Navigation: Fix vertical alignment of page list in modal.
- Fix: ToggleGroupControl active state
- Remove gutenberg_ prefix from @wordpress/block-library

Props ocean90, oandregal, hellofromtonya, youknowriad.
See #54487.

Built from https://develop.svn.wordpress.org/trunk@52364


git-svn-id: http://core.svn.wordpress.org/trunk@51956 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2021-12-14 01:57:26 +00:00

86 lines
2.4 KiB
PHP

<?php
/**
* Server-side rendering of the `core/post-comments` block.
*
* @package WordPress
*/
/**
* Renders the `core/post-comments` block on the server.
*
* @param array $attributes Block attributes.
* @param string $content Block default content.
* @param WP_Block $block Block instance.
* @return string Returns the filtered post comments for the current post wrapped inside "p" tags.
*/
function render_block_core_post_comments( $attributes, $content, $block ) {
global $post;
$post_id = $block->context['postId'];
if ( ! isset( $post_id ) ) {
return '';
}
$comment_args = array(
'post_id' => $post_id,
'count' => true,
);
// Return early if there are no comments and comments are closed.
if ( ! comments_open( $post_id ) && get_comments( $comment_args ) === 0 ) {
return '';
}
$post_before = $post;
$post = get_post( $post_id );
setup_postdata( $post );
ob_start();
// There's a deprecation warning generated by WP Core.
// Ideally this deprecation is removed from Core.
// In the meantime, this removes it from the output.
add_filter( 'deprecated_file_trigger_error', '__return_false' );
comments_template();
remove_filter( 'deprecated_file_trigger_error', '__return_false' );
$post = $post_before;
$classes = '';
if ( isset( $attributes['textAlign'] ) ) {
$classes .= 'has-text-align-' . $attributes['textAlign'];
}
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );
$output = ob_get_clean();
return sprintf( '<div %1$s>%2$s</div>', $wrapper_attributes, $output );
}
/**
* Registers the `core/post-comments` block on the server.
*/
function register_block_core_post_comments() {
register_block_type_from_metadata(
__DIR__ . '/post-comments',
array(
'render_callback' => 'render_block_core_post_comments',
)
);
}
add_action( 'init', 'register_block_core_post_comments' );
/**
* Use the button block classes for the form-submit button.
*
* @param array $fields The default comment form arguments.
*
* @return array Returns the modified fields.
*/
function post_comments_block_form_defaults( $fields ) {
if ( wp_is_block_theme() ) {
$fields['submit_button'] = '<input name="%1$s" type="submit" id="%2$s" class="%3$s wp-block-button__link" value="%4$s" />';
$fields['submit_field'] = '<p class="form-submit wp-block-button">%1$s %2$s</p>';
}
return $fields;
}
add_filter( 'comment_form_defaults', 'post_comments_block_form_defaults' );