Make WordPress Core

Ticket #48515: 48515.patch

File 48515.patch, 3.1 KB (added by afragen, 4 years ago)
  • wp-includes/class-wp-theme.php

    diff --git a/wp-includes/class-wp-theme.php b/wp-includes/class-wp-theme.php
    index fe8dbb142b..7cfb611fae 100644
    a b final class WP_Theme implements ArrayAccess { 
    3535                'Tags'        => 'Tags',
    3636                'TextDomain'  => 'Text Domain',
    3737                'DomainPath'  => 'Domain Path',
     38                'Requires'    => 'Requires at least',
     39                'RequiresPHP' => 'Requires PHP',
    3840        );
    3941
    4042        /**
    final class WP_Theme implements ArrayAccess { 
    267269                        );
    268270                        return;
    269271                } else {
    270                         $this->headers = get_file_data( $this->theme_root . '/' . $theme_file, self::$file_headers, 'theme' );
     272                        $this->headers = $this->get_theme_headers( $theme_dir, $theme_file );
     273
    271274                        // Default themes always trump their pretenders.
    272275                        // Properly identify default themes that are inside a directory within wp-content/themes.
    273276                        $default_theme_slug = array_search( $this->headers['Name'], self::$default_themes );
    final class WP_Theme implements ArrayAccess { 
    850853                                $value = array_filter( array_map( 'trim', explode( ',', strip_tags( $value ) ) ) );
    851854                                break;
    852855                        case 'Version':
     856                        case 'Requires':
     857                        case 'RequiresPHP':
    853858                                $value = strip_tags( $value );
    854859                                break;
    855860                }
    final class WP_Theme implements ArrayAccess { 
    11101115                return $this->theme_root_uri;
    11111116        }
    11121117
     1118        /**
     1119         * Get headers from theme's style.css and readme.txt files.
     1120         *
     1121         * Uses `get_file_data()` to get and combine the theme headers
     1122         * from the theme's style.css and readme.txt files. Then checks
     1123         * the Theme API for WP and PHP compatibility data.
     1124         *
     1125         * Precedence order: API > readme.txt > style.css
     1126         *
     1127         * @since 5.x.x
     1128         *
     1129         * @param string $theme_dir  Directory of the theme within the theme_root.
     1130         * @param string $theme_file Main theme file.
     1131         *
     1132         * @return array Theme headers.
     1133         */
     1134        public function get_theme_headers( $theme_dir, $theme_file ) {
     1135                $theme_headers = get_file_data( $this->theme_root . '/' . $theme_file, self::$file_headers, 'theme' );
     1136
     1137                $readme = $this->theme_root . '/'. $theme_dir . '/readme.txt';
     1138                if ( file_exists( $readme ) ) {
     1139                        $readme_headers = get_file_data( $readme, self::$file_headers, 'theme' );
     1140
     1141                        // Precedence to headers in readme.txt over style.css file.
     1142                        foreach ( $theme_headers as $header => $value ) {
     1143                                if ( ! empty( $readme_headers[ $header ] ) ) {
     1144                                        $theme_headers[ $header ] = $readme_headers[ $header ];
     1145                                }
     1146                        }
     1147                }
     1148
     1149                // Get Theme API data.
     1150                $response = wp_remote_get( "https://api.wordpress.org/themes/info/1.2/?action=theme_information&request[slug]=$theme_dir" );
     1151                $response = wp_remote_retrieve_body( $response );
     1152                $response = json_decode( $response );
     1153
     1154                if ( ! property_exists( $response, 'error' ) ) {
     1155                        // Precedence to Theme API.
     1156                        $theme_headers['Requires']    = ! empty( $response->requires ) ? $response->requires : $theme_headers['Requires'];
     1157                        $theme_headers['RequiresPHP'] = ! empty( $response->requires ) ? $response->requires_php : $theme_headers['RequiresPHP'];
     1158                }
     1159
     1160                return $theme_headers;
     1161        }
     1162
    11131163        /**
    11141164         * Returns the main screenshot file for the theme.
    11151165         *