Making WordPress.org

Changeset 13236


Ignore:
Timestamp:
02/22/2024 06:10:37 AM (3 years ago)
Author:
dd32
Message:

Plugin Directory: Use a custom word split functionality due to wp_trim_words() eating whitespace.

Followup to [13235].
See #7477.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/readme/class-parser.php

    r13235 r13236  
    542542
    543543                if ( 'words' === $type ) {
    544                         return wp_trim_words( $desc, $length, ' …' );
     544                        // Split by whitespace, capturing it so we can put it back together.
     545                        $pieces = preg_split( '/(\s+)/u', $desc, -1, PREG_SPLIT_DELIM_CAPTURE );
     546
     547                        $word_count_with_spaces = $length * 2;
     548
     549                        if ( count( $pieces ) < $word_count_with_spaces ) {
     550                                return $desc;
     551                        }
     552
     553                        $pieces = array_slice( $pieces, 0, $word_count_with_spaces );
     554
     555                        return implode( '', $pieces ) . ' &hellip;';
    545556                }
    546557
Note: See TracChangeset for help on using the changeset viewer.