Edit File by line
/home/zeestwma/richards.../wp-inclu.../blocks
File: post-excerpt.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Server-side rendering of the `core/post-excerpt` block.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Renders the `core/post-excerpt` block on the server.
[8] Fix | Delete
*
[9] Fix | Delete
* @since 5.8.0
[10] Fix | Delete
*
[11] Fix | Delete
* @param array $attributes Block attributes.
[12] Fix | Delete
* @param string $content Block default content.
[13] Fix | Delete
* @param WP_Block $block Block instance.
[14] Fix | Delete
* @return string Returns the filtered post excerpt for the current post wrapped inside "p" tags.
[15] Fix | Delete
*/
[16] Fix | Delete
function render_block_core_post_excerpt( $attributes, $content, $block ) {
[17] Fix | Delete
if ( ! isset( $block->context['postId'] ) ) {
[18] Fix | Delete
return '';
[19] Fix | Delete
}
[20] Fix | Delete
[21] Fix | Delete
/*
[22] Fix | Delete
* The purpose of the excerpt length setting is to limit the length of both
[23] Fix | Delete
* automatically generated and user-created excerpts.
[24] Fix | Delete
* Because the excerpt_length filter only applies to auto generated excerpts,
[25] Fix | Delete
* wp_trim_words is used instead.
[26] Fix | Delete
*/
[27] Fix | Delete
$excerpt_length = $attributes['excerptLength'];
[28] Fix | Delete
$excerpt = get_the_excerpt( $block->context['postId'] );
[29] Fix | Delete
if ( isset( $excerpt_length ) ) {
[30] Fix | Delete
$excerpt = wp_trim_words( $excerpt, $excerpt_length );
[31] Fix | Delete
}
[32] Fix | Delete
[33] Fix | Delete
$more_text = ! empty( $attributes['moreText'] ) ? '<a class="wp-block-post-excerpt__more-link" href="' . esc_url( get_the_permalink( $block->context['postId'] ) ) . '">' . wp_kses_post( $attributes['moreText'] ) . '</a>' : '';
[34] Fix | Delete
$filter_excerpt_more = static function ( $more ) use ( $more_text ) {
[35] Fix | Delete
return empty( $more_text ) ? $more : '';
[36] Fix | Delete
};
[37] Fix | Delete
/**
[38] Fix | Delete
* Some themes might use `excerpt_more` filter to handle the
[39] Fix | Delete
* `more` link displayed after a trimmed excerpt. Since the
[40] Fix | Delete
* block has a `more text` attribute we have to check and
[41] Fix | Delete
* override if needed the return value from this filter.
[42] Fix | Delete
* So if the block's attribute is not empty override the
[43] Fix | Delete
* `excerpt_more` filter and return nothing. This will
[44] Fix | Delete
* result in showing only one `read more` link at a time.
[45] Fix | Delete
*/
[46] Fix | Delete
add_filter( 'excerpt_more', $filter_excerpt_more );
[47] Fix | Delete
$classes = array();
[48] Fix | Delete
if ( isset( $attributes['textAlign'] ) ) {
[49] Fix | Delete
$classes[] = 'has-text-align-' . $attributes['textAlign'];
[50] Fix | Delete
}
[51] Fix | Delete
if ( isset( $attributes['style']['elements']['link']['color']['text'] ) ) {
[52] Fix | Delete
$classes[] = 'has-link-color';
[53] Fix | Delete
}
[54] Fix | Delete
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) );
[55] Fix | Delete
[56] Fix | Delete
$content = '<p class="wp-block-post-excerpt__excerpt">' . $excerpt;
[57] Fix | Delete
$show_more_on_new_line = ! isset( $attributes['showMoreOnNewLine'] ) || $attributes['showMoreOnNewLine'];
[58] Fix | Delete
if ( $show_more_on_new_line && ! empty( $more_text ) ) {
[59] Fix | Delete
$content .= '</p><p class="wp-block-post-excerpt__more-text">' . $more_text . '</p>';
[60] Fix | Delete
} else {
[61] Fix | Delete
$content .= " $more_text</p>";
[62] Fix | Delete
}
[63] Fix | Delete
remove_filter( 'excerpt_more', $filter_excerpt_more );
[64] Fix | Delete
return sprintf( '<div %1$s>%2$s</div>', $wrapper_attributes, $content );
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
/**
[68] Fix | Delete
* Registers the `core/post-excerpt` block on the server.
[69] Fix | Delete
*
[70] Fix | Delete
* @since 5.8.0
[71] Fix | Delete
*/
[72] Fix | Delete
function register_block_core_post_excerpt() {
[73] Fix | Delete
register_block_type_from_metadata(
[74] Fix | Delete
__DIR__ . '/post-excerpt',
[75] Fix | Delete
array(
[76] Fix | Delete
'render_callback' => 'render_block_core_post_excerpt',
[77] Fix | Delete
)
[78] Fix | Delete
);
[79] Fix | Delete
}
[80] Fix | Delete
add_action( 'init', 'register_block_core_post_excerpt' );
[81] Fix | Delete
[82] Fix | Delete
/**
[83] Fix | Delete
* If themes or plugins filter the excerpt_length, we need to
[84] Fix | Delete
* override the filter in the editor, otherwise
[85] Fix | Delete
* the excerpt length block setting has no effect.
[86] Fix | Delete
* Returns 100 because 100 is the max length in the setting.
[87] Fix | Delete
*/
[88] Fix | Delete
if ( is_admin() ||
[89] Fix | Delete
defined( 'REST_REQUEST' ) && REST_REQUEST ) {
[90] Fix | Delete
add_filter(
[91] Fix | Delete
'excerpt_length',
[92] Fix | Delete
static function () {
[93] Fix | Delete
return 100;
[94] Fix | Delete
},
[95] Fix | Delete
PHP_INT_MAX
[96] Fix | Delete
);
[97] Fix | Delete
}
[98] Fix | Delete
[99] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function