Make WordPress Core

Ticket #48515: 48515.2.diff

File 48515.2.diff, 2.8 KB (added by afragen, 4 years ago)

remove call to API

  • wp-includes/class-wp-theme.php

    diff --git a/wp-includes/class-wp-theme.php b/wp-includes/class-wp-theme.php
    index 2697aaf521..96f67dbc72 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.
     1123         *
     1124         * Precedence order: readme.txt > style.css
     1125         *
     1126         * @since 5.x.x
     1127         *
     1128         * @param string $theme_dir  Directory of the theme within the theme_root.
     1129         * @param string $theme_file Main theme file.
     1130         *
     1131         * @return array Theme headers.
     1132         */
     1133        public function get_theme_headers( $theme_dir, $theme_file ) {
     1134                $theme_headers = get_file_data( $this->theme_root . '/' . $theme_file, self::$file_headers, 'theme' );
     1135
     1136                $readme = $this->theme_root . '/'. $theme_dir . '/readme.txt';
     1137                if ( file_exists( $readme ) ) {
     1138                        $readme_headers = get_file_data( $readme, self::$file_headers, 'theme' );
     1139
     1140                        // Precedence to headers in readme.txt over style.css file.
     1141                        foreach ( $theme_headers as $header => $value ) {
     1142                                if ( ! empty( $readme_headers[ $header ] ) ) {
     1143                                        $theme_headers[ $header ] = $readme_headers[ $header ];
     1144                                }
     1145                        }
     1146                }
     1147
     1148                // Many themes incorrectly use `Requires at least: WordPress x.x`, including default themes.
     1149                // It should only be the version number, `Requires at least: x.x`.
     1150                if ( false !== strpos( $theme_headers['Requires'], 'WordPress' ) ) {
     1151                        $theme_headers['Requires'] = trim( str_replace( 'WordPress', '', $theme_headers['Requires'] ) );
     1152                }
     1153
     1154                return $theme_headers;
     1155        }
     1156
    11131157        /**
    11141158         * Returns the main screenshot file for the theme.
    11151159         *