Making WordPress.org

Changeset 10316


Ignore:
Timestamp:
09/29/2020 06:46:43 AM (5 years ago)
Author:
dd32
Message:

Plugin Directory: When splitting the post content into sections, trim any leading newlines off the content to prevent the section -> content pairs being off.

This prevents a PHP Notice when the resulting array was previously [ '', 'description', 'content here..', .. instead of [ 'description', '..

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
Files:
2 edited

Legend:

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

    r10100 r10316  
    139139        $result['sections']                 = array();
    140140
    141         $_pages = preg_split( '#<!--section=(.+?)-->#', $post->post_content, - 1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
     141        $_pages = preg_split( '#<!--section=(.+?)-->#', ltrim( $post->post_content ), - 1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
    142142        for ( $i = 0; $i < count( $_pages ); $i += 2 ) {
    143143            $result['sections'][ $_pages[ $i ] ] = apply_filters( 'the_content', $_pages[ $i + 1 ] ?? '', $_pages[ $i ] );
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/class-plugin-directory.php

    r10267 r10316  
    15181518     */
    15191519    public function split_post_content_into_pages( $content ) {
    1520         $_pages        = preg_split( '#<!--section=(.+?)-->#', $content, - 1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
     1520        $_pages        = preg_split( '#<!--section=(.+?)-->#', ltrim( $content ), - 1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
    15211521        $content_pages = array(
    15221522            'screenshots' => '[wporg-plugins-screenshots]',
     
    15291529            // Don't overwrite existing tabs.
    15301530            if ( ! isset( $content_pages[ $_pages[ $i ] ] ) ) {
    1531                 $content_pages[ $_pages[ $i ] ] = $_pages[ $i + 1 ];
     1531                $content_pages[ $_pages[ $i ] ] = $_pages[ $i + 1 ] ?? '';
    15321532            }
    15331533        }
Note: See TracChangeset for help on using the changeset viewer.