Make WordPress Core

Ticket #13780: 13780-check-theme-version-on-upload.diff

File 13780-check-theme-version-on-upload.diff, 1.9 KB (added by pdclark, 12 years ago)

Check theme version when uploading .zip. Checks for "Requires at least:" in theme style.css head.

  • wp-admin/includes/class-wp-upgrader.php

    diff --git wp-admin/includes/class-wp-upgrader.php wp-admin/includes/class-wp-upgrader.php
    index 4f45050..e803ae8 100644
    class Theme_Upgrader extends WP_Upgrader { 
    902902        }
    903903
    904904        function check_package($source) {
    905                 global $wp_filesystem;
     905                global $wp_filesystem, $wp_version;
    906906
    907907                if ( is_wp_error($source) )
    908908                        return $source;
    class Theme_Upgrader extends WP_Upgrader { 
    916916                if ( ! file_exists( $working_directory . 'style.css' ) )
    917917                        return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __('The theme is missing the <code>style.css</code> stylesheet.') );
    918918
    919                 $info = get_file_data( $working_directory . 'style.css', array( 'Name' => 'Theme Name', 'Template' => 'Template' ) );
     919                $info = get_file_data( $working_directory . 'style.css', array( 'Name' => 'Theme Name', 'Template' => 'Template', 'Requires' => 'Requires at least', ) );
    920920
    921921                if ( empty( $info['Name'] ) )
    922922                        return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __("The <code>style.css</code> stylesheet doesn't contain a valid theme header.") );
    class Theme_Upgrader extends WP_Upgrader { 
    925925                if ( empty( $info['Template'] ) && ! file_exists( $working_directory . 'index.php' ) )
    926926                        return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], __('The theme is missing the <code>index.php</code> file.') );
    927927
     928                // Check WordPress version requirements
     929                if ( version_compare( $wp_version, $info['Requires'], '<' ) )
     930                        return new WP_Error( 'incompatible_archive', $this->strings['incompatible_archive'], sprintf( __('The theme requires WordPress %s or higher. Please <a href="%s">update WordPress</a>.'), $info['Requires'], network_admin_url('update-core.php') ) );
     931
    928932                return $source;
    929933        }
    930934