Making WordPress.org


Ignore:
Timestamp:
03/16/2020 02:00:51 AM (5 years ago)
Author:
dd32
Message:

Theme Directory: Import the Requires & Requires at least headers from style.css rather than from the readme.txt file.

Fixes #5099.

File:
1 edited

Legend:

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

    r9384 r9588  
    9191    protected $readme_header_fields = array(
    9292        'tested'       => 'tested up to',
    93         'requires'     => 'requires at least',
    94         'requires_php' => 'requires php',
    9593        'contributors' => 'contributors',
    9694        'license'      => 'license',
     
    436434        }
    437435
    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;
     436        if ( isset( $data['tested'] ) ) {
     437            $data['tested'] = $this->sanitize_version_like_field( $data['tested'], 'tested' );
     438            if ( ! $data['tested'] ) {
     439                unset( $data['tested'] );
    461440            }
    462441        }
    463442
    464443        return $data;
     444    }
     445
     446    /**
     447     * Sanitize/strip a field back to it's bare-basics version-like string.
     448     *
     449     * @param string $value The field value.
     450     * @param string $field The name of the field being processed.
     451     * @return bool|string The version-like field or false on failure.
     452     */
     453    public function sanitize_version_like_field( $value, $field = false ) {
     454        // Strip 'WP', 'WordPress', and 'PHP' from the fields.
     455        $value = trim( str_ireplace( array( 'PHP', 'WP', 'WordPress', '+' ), '', $value ) );
     456
     457        // Require a version-like value, x.y or x.y.z
     458        if ( ! preg_match( '!^\d+\.\d(\.\d+)?$!', $value ) ) {
     459            return false;
     460        }
     461
     462        // Allow themes to mark themselves as compatible with Stable+0.1 (trunk/master) but not higher
     463        if (
     464            ( 'requires' === $field || 'tested' === $field ) &&
     465            defined( 'WP_CORE_STABLE_BRANCH' ) &&
     466            version_compare( (float)$value, (float)WP_CORE_STABLE_BRANCH+0.1, '>' )
     467        ) {
     468            return false;
     469        }
     470
     471        return $value;
    465472    }
    466473
     
    821828        // Finally, add post meta.
    822829        $post_meta = array(
    823             '_theme_url'   => $this->theme->get( 'ThemeURI' ),
    824             '_author_url'  => $this->theme->get( 'AuthorURI' ),
    825             '_upload_date' => $upload_date,
    826             '_ticket_id'   => $ticket_id,
    827             '_screenshot'  => $this->theme->screenshot,
     830            '_theme_url'    => $this->theme->get( 'ThemeURI' ),
     831            '_author_url'   => $this->theme->get( 'AuthorURI' ),
     832            '_requires'     => $this->sanitize_version_like_field( $this->theme->get( 'RequiresWP' ), 'requires' ),
     833            '_requires_php' => $this->sanitize_version_like_field( $this->theme->get( 'RequiresPHP' ) ),
     834            '_upload_date'  => $upload_date,
     835            '_ticket_id'    => $ticket_id,
     836            '_screenshot'   => $this->theme->screenshot,
    828837        );
    829838
Note: See TracChangeset for help on using the changeset viewer.