WordPress.org

Making WordPress.org

Changeset 8794


Ignore:
Timestamp:
05/15/2019 06:32:48 AM (3 years ago)
Author:
dd32
Message:

Theme Directory: Sanitize version numbers in the Theme readme.txt import process.

A number of themes include extra details in the fields such as 'WordPress', and others don't follow the plugin/theme readme stanard at all, this change validates the data a little more before importing.

It also removes the importing of the 'Tags' header as there's no immediate plans for it's use and we defer to the style.css Tags header instead.

See #3718.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/class-wporg-themes-upload.php

    r8789 r8794  
    9393        'requires'     => 'requires at least',
    9494        'requires_php' => 'requires php',
    95         'readme_tags'  => 'tags',
    9695        'contributors' => 'contributors',
    9796        'license'      => 'license',
     
    434433            if ( ! $data['contributors'] ) {
    435434                unset( $data['contributors'] );
     435            }
     436        }
     437
     438        // Sanitize some version-like data.
     439        foreach ( array( 'requires', 'requires_php', 'tested' ) as $field ) {
     440            if ( ! isset( $data[ $field ] ) ) {
     441                continue;
     442            }
     443
     444            // Strip 'WP', 'WordPress', and 'PHP' from the fields.
     445            $data[ $field ] = trim( str_ireplace( array( 'PHP', 'WP', 'WordPress', '+' ), '', $data[ $field ] ) );
     446
     447            // Require a version-like value, x.y or x.y.z
     448            if ( ! preg_match( '!^\d+\.\d(\.\d+)?$!', $data[ $field ] ) ) {
     449                unset( $data[ $field ] );
     450                continue;
     451            }
     452
     453            // Allow themes to mark themselves as compatible with Stable+0.1 (trunk/master) but not higher
     454            if (
     455                ( 'requires' === $field || 'tested' === $field ) &&
     456                defined( 'WP_CORE_STABLE_BRANCH' ) &&
     457                version_compare( (float)$data[ $field ], (float)WP_CORE_STABLE_BRANCH+0.1, '>' )
     458            ) {
     459                unset( $data[ $field ] );
     460                continue;
    436461            }
    437462        }
Note: See TracChangeset for help on using the changeset viewer.