Make WordPress Core

Ticket #22252: 22252.2.patch

File 22252.2.patch, 1.6 KB (added by johnjamesjacoby, 12 years ago)

Compare against transient, loop through themes, check for mismatched roots, delete option if $root = '/theme' to prevent useless database entries

  • wp-includes/theme.php

     
    666666        if ( is_array( $sidebars_widgets ) )
    667667                set_theme_mod( 'sidebars_widgets', array( 'time' => time(), 'data' => $sidebars_widgets ) );
    668668
    669         $old_theme  = wp_get_theme();
     669        $old_theme = wp_get_theme();
    670670        $new_theme = wp_get_theme( $stylesheet );
    671671
    672672        if ( func_num_args() > 1 ) {
     
    679679        update_option( 'template', $template );
    680680        update_option( 'stylesheet', $stylesheet );
    681681
    682         if ( count( $wp_theme_directories ) > 1 ) {
    683                 update_option( 'template_root', get_raw_theme_root( $template, true ) );
    684                 update_option( 'stylesheet_root', get_raw_theme_root( $stylesheet, true ) );
     682        // Get current theme roots
     683        $template_root   = get_option( 'template_root' );
     684        $stylesheet_root = get_option( 'stylesheet_root' );
     685
     686        // Loop through themes and check for root mismatch. If we find a mismatch,
     687        // only update the option if the root is not '/themes' to prevent adding
     688        // useless options to the database.
     689        foreach ( get_site_transient( 'theme_roots' ) as $theme => $root ) {
     690
     691                // Template
     692                if ( ( $template == $theme ) && ( $root != $template_root ) ) {
     693
     694                        // Don't set root to default location
     695                        if ( '/themes' == $root  ) {
     696                                delete_option( 'template_root' );
     697                        } else {
     698                                update_option( 'template_root', $root );
     699                        }
     700                }
     701
     702                // Stylesheet
     703                if ( ( $stylesheet == $theme ) && ( $root != $stylesheet_root ) ) {
     704
     705                        // Don't set root to default location
     706                        if ( '/themes' == $root  ) {
     707                                delete_option( 'stylesheet_root' );
     708                        } else {
     709                                update_option( 'stylesheet_root', $root );
     710                        }
     711                }
    685712        }
    686713
    687714        $new_name  = $new_theme->get('Name');