WordPress.org

Making WordPress.org

Changeset 5253


Ignore:
Timestamp:
04/05/2017 06:30:53 AM (2 years ago)
Author:
dd32
Message:

Plugin Directory: Prefix Installation Instructions as a FAQ entry when they exist in the readme.

See #2645

File:
1 edited

Legend:

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

    r5205 r5253  
    341341            $this->faq = $this->parse_section( $this->sections['faq'] );
    342342            $this->sections['faq'] = '';
     343        }
     344
     345        // Prefix Installation Instructions as a FAQ entry
     346        if ( $this->has_unique_installation_instructions() ) {
     347            $this->faq = array_merge(
     348                array(
     349                    __( 'Installation Instructions', 'wporg-plugins' ) => $this->sections['installation']
     350                ),
     351                $this->faq
     352            );
     353            unset( $this->sections['installation'] );
     354            $this->sections['faq'] = ''; // Ensure it's set as per faq section above.
    343355        }
    344356
     
    632644        return $markdown->transform( $text );
    633645    }
     646
     647    /**
     648     * Determine if the readme contains unique installation instructions.
     649     *
     650     * When phrases are added here, the affected plugins will need to be reparsed to pick it up.
     651     *
     652     * @return bool Whether the instructions differ from default instructions.
     653     */
     654    protected function has_unique_installation_instructions() {
     655        if ( ! isset( $this->sections['installation'] ) ) {
     656            return false;
     657        }
     658
     659        // If the plugin installation section contains any of these phrases, skip it as it's not useful.
     660        $common_phrases = array(
     661            'This section describes how to install the plugin and get it working.', // Default readme.txt content
     662        );
     663        foreach ( $common_phrases as $phrase ) {
     664            if ( false !== stripos( $this->sections['installation'], $phrase ) ) {
     665                return false;
     666            }
     667        }
     668
     669        return true;
     670    }
    634671}
Note: See TracChangeset for help on using the changeset viewer.