Make WordPress Core


Ignore:
Timestamp:
07/15/2021 06:53:34 PM (6 months ago)
Author:
youknowriad
Message:

Block Editor: Backport fixes targetted for WordPress 5.8 RC4.

This includes:

  • Suggestion List: Check if a node exists to scroll into view.
  • Autocomplete: reset state for empty text.
  • Adds auxiliary class names for editor styles in the widgets editor.
  • Extract snackbars into a separate component.
  • Rich text: run input rules after composition end.
  • iframe: load inline styles.
  • Multi select: select all: restore ref callback.
  • Writing flow: allow select all from empty selection.
  • Post Excerpt: Fix excerpt_more filter conflict and remove wordCount attribute.
  • Add the percent unit to the default units in Core.

Props desrosj.
See #53397.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/blocks/post-excerpt.php

    r50929 r51443  
    1919    }
    2020
    21     $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>' : '';
    22 
    23     $filter_excerpt_length = function() use ( $attributes ) {
    24         return isset( $attributes['wordCount'] ) ? $attributes['wordCount'] : 55;
     21    $more_text           = ! empty( $attributes['moreText'] ) ? '<a class="wp-block-post-excerpt__more-link" href="' . esc_url( get_the_permalink( $block->context['postId'] ) ) . '">' . $attributes['moreText'] . '</a>' : '';
     22    $filter_excerpt_more = function( $more ) use ( $more_text ) {
     23        return empty( $more_text ) ? $more : '';
    2524    };
    26     add_filter(
    27         'excerpt_length',
    28         $filter_excerpt_length
    29     );
    30 
     25    /**
     26     * Some themes might use `excerpt_more` filter to handle the
     27     * `more` link displayed after a trimmed excerpt. Since the
     28     * block has a `more text` attribute we have to check and
     29     * override if needed the return value from this filter.
     30     * So if the block's attribute is not empty override the
     31     * `excerpt_more` filter and return nothing. This will
     32     * result in showing only one `read more` link at a time.
     33     */
     34    add_filter( 'excerpt_more', $filter_excerpt_more );
    3135    $classes = '';
    3236    if ( isset( $attributes['textAlign'] ) ) {
    33         $classes .= 'has-text-align-' . $attributes['textAlign'];
     37        $classes .= "has-text-align-{$attributes['textAlign']}";
    3438    }
    3539    $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $classes ) );
    3640
    37     $content = '<p class="wp-block-post-excerpt__excerpt">' . get_the_excerpt( $block->context['postId'] );
    38     if ( ! isset( $attributes['showMoreOnNewLine'] ) || $attributes['showMoreOnNewLine'] ) {
     41    $content               = '<p class="wp-block-post-excerpt__excerpt">' . get_the_excerpt( $block->context['postId'] );
     42    $show_more_on_new_line = ! isset( $attributes['showMoreOnNewLine'] ) || $attributes['showMoreOnNewLine'];
     43    if ( $show_more_on_new_line && ! empty( $more_text ) ) {
    3944        $content .= '</p><p class="wp-block-post-excerpt__more-text">' . $more_text . '</p>';
    4045    } else {
    4146        $content .= " $more_text</p>";
    4247    }
    43 
    44     remove_filter(
    45         'excerpt_length',
    46         $filter_excerpt_length
    47     );
    48 
     48    remove_filter( 'excerpt_more', $filter_excerpt_more );
    4949    return sprintf( '<div %1$s>%2$s</div>', $wrapper_attributes, $content );
    5050}
Note: See TracChangeset for help on using the changeset viewer.