]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/theme.php
WordPress 3.3.2-scripts
[autoinstalls/wordpress.git] / wp-includes / theme.php
index 78d97395b51a128e8c0f402f8a556530d1aa98af..b132364b4b1caa42746a0f69c0f047de8a5680a6 100644 (file)
@@ -469,7 +469,7 @@ function get_themes() {
  *
  * @since 2.9.0
  *
- * @return array|string An arry of theme roots keyed by template/stylesheet or a single theme root if all themes have the same root.
+ * @return array|string An array of theme roots keyed by template/stylesheet or a single theme root if all themes have the same root.
  */
 function get_theme_roots() {
        global $wp_theme_directories;
@@ -496,7 +496,7 @@ function get_theme_roots() {
 function get_theme($theme) {
        $themes = get_themes();
 
-       if ( array_key_exists($theme, $themes) )
+       if ( is_array( $themes ) && array_key_exists( $theme, $themes ) )
                return $themes[$theme];
 
        return null;
@@ -518,12 +518,13 @@ function get_current_theme() {
                return $theme;
 
        $themes = get_themes();
-       $theme_names = array_keys($themes);
-       $current_template = get_option('template');
-       $current_stylesheet = get_option('stylesheet');
-       $current_theme = 'Twenty Ten';
+       $current_theme = 'Twenty Eleven';
 
        if ( $themes ) {
+               $theme_names = array_keys( $themes );
+               $current_template = get_option( 'template' );
+               $current_stylesheet = get_option( 'stylesheet' );
+
                foreach ( (array) $theme_names as $theme_name ) {
                        if ( $themes[$theme_name]['Stylesheet'] == $current_stylesheet &&
                                        $themes[$theme_name]['Template'] == $current_template ) {
@@ -1246,21 +1247,31 @@ function preview_theme_ob_filter_callback( $matches ) {
  * @param string $stylesheet Stylesheet name.
  */
 function switch_theme($template, $stylesheet) {
-       global $wp_theme_directories;
+       global $wp_theme_directories, $sidebars_widgets;
+
+       if ( is_array( $sidebars_widgets ) )
+               set_theme_mod( 'sidebars_widgets', array( 'time' => time(), 'data' => $sidebars_widgets ) );
+
+       $old_theme = get_current_theme();
 
        update_option('template', $template);
        update_option('stylesheet', $stylesheet);
+
        if ( count($wp_theme_directories) > 1 ) {
                update_option('template_root', get_raw_theme_root($template, true));
                update_option('stylesheet_root', get_raw_theme_root($stylesheet, true));
        }
+
        delete_option('current_theme');
        $theme = get_current_theme();
+
        if ( is_admin() && false === get_option( "theme_mods_$stylesheet" ) ) {
                $default_theme_mods = (array) get_option( "mods_$theme" );
                add_option( "theme_mods_$stylesheet", $default_theme_mods );
        }
-       do_action('switch_theme', $theme);
+
+       update_option( 'theme_switched', $old_theme );
+       do_action( 'switch_theme', $theme );
 }
 
 /**
@@ -1718,7 +1729,7 @@ function add_custom_background( $header_callback = '', $admin_header_callback =
        if ( ! is_admin() )
                return;
        require_once( ABSPATH . 'wp-admin/custom-background.php' );
-       $GLOBALS['custom_background'] =& new Custom_Background( $admin_header_callback, $admin_image_div_callback );
+       $GLOBALS['custom_background'] = new Custom_Background( $admin_header_callback, $admin_image_div_callback );
        add_action( 'admin_menu', array( &$GLOBALS['custom_background'], 'init' ) );
 }
 
@@ -1783,7 +1794,7 @@ function _custom_background_cb() {
        }
 ?>
 <style type="text/css">
-body { <?php echo trim( $style ); ?> }
+body.custom-background { <?php echo trim( $style ); ?> }
 </style>
 <?php
 }
@@ -1936,10 +1947,14 @@ function current_theme_supports( $feature ) {
                        if ( true === $_wp_theme_features[$feature] )  // Registered for all types
                                return true;
                        $content_type = $args[0];
-                       if ( in_array($content_type, $_wp_theme_features[$feature][0]) )
-                               return true;
-                       else
-                               return false;
+                       return in_array( $content_type, $_wp_theme_features[$feature][0] );
+                       break;
+
+               case 'post-formats':
+                       // specific post formats can be registered by passing an array of types to
+                       // add_theme_support()
+                       $post_format = $args[0];
+                       return in_array( $post_format, $_wp_theme_features[$feature][0] );
                        break;
        }
 
@@ -1982,4 +1997,14 @@ function _delete_attachment_theme_mod( $id ) {
 
 add_action( 'delete_attachment', '_delete_attachment_theme_mod' );
 
-?>
+/**
+ * Checks if a theme has been changed and runs 'after_switch_theme' hook on the next WP load
+ *
+ * @since 3.3
+ */
+function check_theme_switched() {
+       if ( false !== ( $old_theme = get_option( 'theme_switched' ) ) && !empty( $old_theme ) ) {
+               do_action( 'after_switch_theme', $old_theme );
+               update_option( 'theme_switched', false );
+       }
+}