WordPress.org

Make WordPress Core

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

File 13780-check-theme-version-on-activate.diff, 1.6 KB (added by pdclark, 16 months ago)

Check theme version before switching themes. Checks for "Requires at least:" in theme style.css head.

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

    diff --git wp-includes/class-wp-theme.php wp-includes/class-wp-theme.php
    index dfff705..853ae43 100644
    final class WP_Theme implements ArrayAccess { 
    2222                'Author'      => 'Author', 
    2323                'AuthorURI'   => 'Author URI', 
    2424                'Version'     => 'Version', 
     25                'Requires'    => 'Requires at least', 
    2526                'Template'    => 'Template', 
    2627                'Status'      => 'Status', 
    2728                'Tags'        => 'Tags', 
  • wp-includes/theme.php

    diff --git wp-includes/theme.php wp-includes/theme.php
    index 8b8f42c..f8ea55a 100644
    function preview_theme_ob_filter_callback( $matches ) { 
    661661 * @param string $stylesheet Stylesheet name 
    662662 */ 
    663663function switch_theme( $stylesheet ) { 
    664         global $wp_theme_directories, $sidebars_widgets; 
    665  
    666         if ( is_array( $sidebars_widgets ) ) 
    667                 set_theme_mod( 'sidebars_widgets', array( 'time' => time(), 'data' => $sidebars_widgets ) ); 
     664        global $wp_theme_directories, $sidebars_widgets, $wp_version; 
    668665 
    669666        $old_theme  = wp_get_theme(); 
    670667        $new_theme = wp_get_theme( $stylesheet ); 
    671668 
     669        if ( version_compare( $wp_version, $new_theme->get('Requires'), '<' ) ) { 
     670                wp_die( sprintf( __('The theme %s requires WordPress %s or higher. Please <a href="%s">update WordPress</a>.'), '<strong>' . $new_theme->get('Name') . '</strong>', $new_theme->get('Requires'), network_admin_url('update-core.php') ) ); 
     671        } 
     672 
     673        if ( is_array( $sidebars_widgets ) ) 
     674                set_theme_mod( 'sidebars_widgets', array( 'time' => time(), 'data' => $sidebars_widgets ) ); 
     675 
    672676        if ( func_num_args() > 1 ) { 
    673677                $template = $stylesheet; 
    674678                $stylesheet = func_get_arg( 1 );