mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-05 02:10:45 +01:00
c3ea09ebb8
It contains several changes in addition to regular update to WordPress packages: - All newly exposed blocks are now registered on the server. - Dutone block support was added. - Border block support was updated. - New shared function `construct_wp_query_args` was added for the family of Query blocks - it might need some further work. Props youknowriad. See #52991. Built from https://develop.svn.wordpress.org/trunk@50929 git-svn-id: http://core.svn.wordpress.org/trunk@50538 1a063a9b-81f0-0310-95a4-ce76da25c4cd
64 lines
1.9 KiB
PHP
64 lines
1.9 KiB
PHP
<?php
|
|
/**
|
|
* Server-side rendering of the `core/post-excerpt` block.
|
|
*
|
|
* @package WordPress
|
|
*/
|
|
|
|
/**
|
|
* Renders the `core/post-excerpt` 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 excerpt for the current post wrapped inside "p" tags.
|
|
*/
|
|
function render_block_core_post_excerpt( $attributes, $content, $block ) {
|
|
if ( ! isset( $block->context['postId'] ) ) {
|
|
return '';
|
|
}
|
|
|
|
$more_text = isset( $attributes['moreText'] ) ? '<a class="wp-block-post-excerpt__more-link" href="' . esc_url( get_the_permalink( $block->context['postId'] ) ) . '">' . $attributes['moreText'] . '</a>' : '';
|
|
|
|
$filter_excerpt_length = function() use ( $attributes ) {
|
|
return isset( $attributes['wordCount'] ) ? $attributes['wordCount'] : 55;
|
|
};
|
|
add_filter(
|
|
'excerpt_length',
|
|
$filter_excerpt_length
|
|
);
|
|
|
|
$classes = '';
|
|
if ( isset( $attributes['textAlign'] ) ) {
|
|
$classes .= 'has-text-align-' . $attributes['textAlign'];
|
|
}
|
|
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );
|
|
|
|
$content = '<p class="wp-block-post-excerpt__excerpt">' . get_the_excerpt( $block->context['postId'] );
|
|
if ( ! isset( $attributes['showMoreOnNewLine'] ) || $attributes['showMoreOnNewLine'] ) {
|
|
$content .= '</p><p class="wp-block-post-excerpt__more-text">' . $more_text . '</p>';
|
|
} else {
|
|
$content .= " $more_text</p>";
|
|
}
|
|
|
|
remove_filter(
|
|
'excerpt_length',
|
|
$filter_excerpt_length
|
|
);
|
|
|
|
return sprintf( '<div %1$s>%2$s</div>', $wrapper_attributes, $content );
|
|
}
|
|
|
|
/**
|
|
* Registers the `core/post-excerpt` block on the server.
|
|
*/
|
|
function register_block_core_post_excerpt() {
|
|
register_block_type_from_metadata(
|
|
__DIR__ . '/post-excerpt',
|
|
array(
|
|
'render_callback' => 'render_block_core_post_excerpt',
|
|
)
|
|
);
|
|
}
|
|
add_action( 'init', 'register_block_core_post_excerpt' );
|