mirror of
https://github.com/WordPress/WordPress.git
synced 2024-08-28 16:49:40 +02:00
- [Block Library - Query Pagination Next]: Hide block if custom query has no results - [WP 5.9] Fix: HTML tags like inline images in nav links break submenu layout - Check for nextpage to display page links for paginated posts - Navigation: Set the default for --navigation-layout-align to "flex-start" when using vertical orientation - [Block Library - Query Loop]: Use gap for the grid view - Update page list flex variables to match navigation. - Site logo: Fix range control on landscape logo - Restore canvas padding for classic themes - RichText: Fix dead key input on Windows - Fix: Impossible to clear colors if color palettes are removed. - Gallery block: pass any custom attributes through the gallery v2 migration script - Reduce specificity of legacy font sizes defined by core - Update: Improve escaping on the search block See #54487. Props isabel_brison. Built from https://develop.svn.wordpress.org/trunk@52551 git-svn-id: http://core.svn.wordpress.org/trunk@52141 1a063a9b-81f0-0310-95a4-ce76da25c4cd
83 lines
2.4 KiB
PHP
83 lines
2.4 KiB
PHP
<?php
|
|
/**
|
|
* Server-side rendering of the `core/post-content` block.
|
|
*
|
|
* @package WordPress
|
|
*/
|
|
|
|
/**
|
|
* Renders the `core/post-content` 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 content of the current post.
|
|
*/
|
|
function render_block_core_post_content( $attributes, $content, $block ) {
|
|
static $seen_ids = array();
|
|
|
|
if ( ! isset( $block->context['postId'] ) ) {
|
|
return '';
|
|
}
|
|
|
|
$post_id = $block->context['postId'];
|
|
|
|
if ( isset( $seen_ids[ $post_id ] ) ) {
|
|
// WP_DEBUG_DISPLAY must only be honored when WP_DEBUG. This precedent
|
|
// is set in `wp_debug_mode()`.
|
|
$is_debug = defined( 'WP_DEBUG' ) && WP_DEBUG &&
|
|
defined( 'WP_DEBUG_DISPLAY' ) && WP_DEBUG_DISPLAY;
|
|
|
|
return $is_debug ?
|
|
// translators: Visible only in the front end, this warning takes the place of a faulty block.
|
|
__( '[block rendering halted]' ) :
|
|
'';
|
|
}
|
|
|
|
$seen_ids[ $post_id ] = true;
|
|
|
|
// Check is needed for backward compatibility with third-party plugins
|
|
// that might rely on the `in_the_loop` check; calling `the_post` sets it to true.
|
|
if ( ! in_the_loop() && have_posts() ) {
|
|
the_post();
|
|
}
|
|
|
|
// When inside the main loop, we want to use queried object
|
|
// so that `the_preview` for the current post can apply.
|
|
// We force this behavior by omitting the third argument (post ID) from the `get_the_content`.
|
|
$content = get_the_content( null, false );
|
|
// Check for nextpage to display page links for paginated posts.
|
|
if ( has_block( 'core/nextpage' ) ) {
|
|
$content .= wp_link_pages( array( 'echo' => 0 ) );
|
|
}
|
|
|
|
/** This filter is documented in wp-includes/post-template.php */
|
|
$content = apply_filters( 'the_content', str_replace( ']]>', ']]>', $content ) );
|
|
unset( $seen_ids[ $post_id ] );
|
|
|
|
if ( empty( $content ) ) {
|
|
return '';
|
|
}
|
|
|
|
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => 'entry-content' ) );
|
|
|
|
return (
|
|
'<div ' . $wrapper_attributes . '>' .
|
|
$content .
|
|
'</div>'
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Registers the `core/post-content` block on the server.
|
|
*/
|
|
function register_block_core_post_content() {
|
|
register_block_type_from_metadata(
|
|
__DIR__ . '/post-content',
|
|
array(
|
|
'render_callback' => 'render_block_core_post_content',
|
|
)
|
|
);
|
|
}
|
|
add_action( 'init', 'register_block_core_post_content' );
|