Make WordPress Core

Changeset 20029


Ignore:
Timestamp:
02/28/2012 09:24:44 PM (13 years ago)
Author:
nacin
Message:

Introduce WP_Theme, wp_get_themes(), and wp_get_theme() to replace get_themes(), get_theme(), get_theme_data(), current_theme_info(), and others.

  • Getters and Helpers: Introduces a series of methods to allow for easy generation of headers for display, and other theme metadata, including page templates.
  • Screenshots: Handles support for multiple screenshots. (see # Additional screenshots must be PNG and start with screenshot-2.png, and be sequential to be counted. see #19816.
  • Error Handling: Broken themes have a WP_Error object attached to them.
  • Caching: Introduces a wp_cache_themes_persistently filter (also in [20020]) to enable persistent caching of all filesystem and sanitization operations normally handled by WP_Theme (and formerly get_file_data() and get_themes()). Themes are cached individually and across five different cache keys for different data pieces.
  • Compatibility: A WP_Theme object is backwards compatible with a theme's array formerly returned by get_themes() and get_theme(), and an stdClass object formerly returned by current_theme_info().
  • i18n/L10n: Theme headers are now localizable with proper Text Domain and Domain Path headers, like plugins. (Language packs may remove the requirement for headers.) For page templates, see #6007 (not fixed yet, but will be easy now). For headers, fixes #15858.
  • PHP and CSS files: New methods that fetch a list of theme files (for the theme editor) only on demand, rather than only loading them into memory. fixes #11214.

Functions deprecated:

  • get_themes(), get_allowed_themes() and get_broken_themes() -- use wp_get_themes()
  • get_theme() and current_theme_info() -- use wp_get_theme()
  • get_site_allowed_themes() -- use WP_Theme::get_allowed_on_network()
  • wpmu_get_blog_allowedthemes() -- use WP_theme::get_allowed_on_site()

see also [20016], [20018], [20019], [20020], [20021], [20022], [20025], [20026], [20027]. also fixes #19244.

see #20103.

Location:
trunk
Files:
1 added
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/class-wp-ms-themes-list-table.php

    r20022 r20029  
    5151
    5252    function prepare_items() {
    53         global $status, $themes, $totals, $page, $orderby, $order, $s;
     53        global $status, $totals, $page, $orderby, $order, $s;
    5454
    5555        wp_reset_vars( array( 'orderby', 'order', 's' ) );
    5656
    5757        $themes = array(
    58             'all' => apply_filters( 'all_themes', get_themes() ),
     58            'all' => apply_filters( 'all_themes', wp_get_themes() ),
    5959            'search' => array(),
    6060            'enabled' => array(),
     
    6363        );
    6464
    65         $site_allowed_themes = get_site_allowed_themes();
    66         if ( !$this->is_site_themes ) {
    67             $allowed_themes = $site_allowed_themes;
     65        if ( $this->is_site_themes ) {
     66            $themes_per_page = $this->get_items_per_page( 'site_themes_network_per_page' );
     67            $allowed_where = 'site';
     68        } else {
    6869            $themes_per_page = $this->get_items_per_page( 'themes_network_per_page' );
    69         } else {
    70             $allowed_themes = wpmu_get_blog_allowedthemes( $this->site_id );
    71             $themes_per_page = $this->get_items_per_page( 'site_themes_network_per_page' );
    72         }
    73 
    74         $current = get_site_transient( 'update_themes' );
     70            $allowed_where = 'network';
     71        }
     72
     73        $current = current_user_can( 'update_themes' ) && ! $this->is_site_themes && get_site_transient( 'update_themes' );
    7574
    7675        foreach ( (array) $themes['all'] as $key => $theme ) {
    77             $theme_key = $theme['Stylesheet'];
    78 
    79             if ( isset( $allowed_themes [ $theme_key ] ) )  {
    80                 $themes['all'][$key]['enabled'] = true;
    81                 $themes['enabled'][$key] = $themes['all'][$key];
    82             }
    83             else {
    84                 $themes['all'][$key]['enabled'] = false;
    85                 $themes['disabled'][$key] = $themes['all'][$key];
    86             }
    87             if ( isset( $current->response[ $theme['Template'] ] ) )
    88                 $themes['upgrade'][$key] = $themes['all'][$key];
    89 
    90             if ( $this->is_site_themes && isset( $site_allowed_themes[$theme_key] ) ) {
    91                 unset( $themes['all'][$key] );
    92                 unset( $themes['enabled'][$key] );
    93                 unset( $themes['disabled'][$key] );
    94             }
    95         }
    96 
    97         if ( !current_user_can( 'update_themes' ) || $this->is_site_themes )
    98             $themes['upgrade'] = array();
     76            if ( $this->is_site_themes && $theme->is_allowed( 'network' ) ) {
     77                unset( $themes['all'][ $key ] );
     78                continue;
     79            }
     80
     81            $filter = $theme->is_allowed( $allowed_where, $this->site_id ) ? 'enabled' : 'disabled';
     82            $themes[ $filter ][ $key ] = $themes['all'][ $key ];
     83
     84            if ( $current && isset( $current->response[ $key ] ) )
     85                $themes['upgrade'][ $key ] = $themes['all'][ $key ];
     86        }
    9987
    10088        if ( $s ) {
     
    11199
    112100        $this->items = $themes[ $status ];
     101        WP_Theme::sort_by_name( $this->items );
     102
     103        $this->has_items = ! empty( $themes['all'] );
    113104        $total_this_page = $totals[ $status ];
    114105
     
    117108            $order = strtoupper( $order );
    118109
    119             uasort( $this->items, array( &$this, '_order_callback' ) );
     110            if ( $orderby == 'Name' ) {
     111                if ( 'ASC' == $order )
     112                    $this->items = array_reverse( $this->items );
     113            } else {
     114                uasort( $this->items, array( &$this, '_order_callback' ) );
     115            }
    120116        }
    121117
     
    123119
    124120        if ( $total_this_page > $themes_per_page )
    125             $this->items = array_slice( $this->items, $start, $themes_per_page );
     121            $this->items = array_slice( $this->items, $start, $themes_per_page, true );
    126122
    127123        $this->set_pagination_args( array(
     
    136132            $term = stripslashes( $_REQUEST['s'] );
    137133
    138         $search_fields = array( 'Name', 'Title', 'Description', 'Author', 'Author Name', 'Author URI', 'Template', 'Stylesheet' );
    139         foreach ( $search_fields as $field )
    140             if ( stripos( $theme[ $field ], $term ) !== false )
     134        foreach ( array( 'Name', 'Description', 'Author', 'Author', 'AuthorURI' ) as $field ) {
     135            // Don't mark up; Do translate.
     136            if ( false !== stripos( $theme->display( $field, false, true ), $term ) )
    141137                return true;
     138        }
     139
     140        if ( false !== stripos( $theme->get_stylesheet(), $term ) )
     141            return true;
     142
     143        if ( false !== stripos( $theme->get_template(), $term ) )
     144            return true;
    142145
    143146        return false;
    144147    }
    145148
     149    // Not used by any core columns.
    146150    function _order_callback( $theme_a, $theme_b ) {
    147151        global $orderby, $order;
    148152
    149         $a = $theme_a[$orderby];
    150         $b = $theme_b[$orderby];
     153        $a = $theme_a[ $orderby ];
     154        $b = $theme_b[ $orderby ];
    151155
    152156        if ( $a == $b )
     
    160164
    161165    function no_items() {
    162         global $themes;
    163 
    164         if ( !empty( $themes['all'] ) )
     166        if ( ! $$this->has_items )
    165167            _e( 'No themes found.' );
    166168        else
     
    260262        $context = $status;
    261263
    262         if ( $this->is_site_themes )
     264        if ( $this->is_site_themes ) {
    263265            $url = "site-themes.php?id={$this->site_id}&";
    264         else
     266            $allowed = $theme->is_allowed( 'site', $this->site_id );
     267        } else {
    265268            $url = 'themes.php?';
     269            $allowed = $theme->is_allowed( 'network' );
     270        }
    266271
    267272        // preorder
     
    273278        );
    274279
    275         $theme_key = $theme['Stylesheet'];
    276 
    277         if ( empty( $theme['enabled'] ) )
     280        $theme_key = $theme->get_stylesheet();
     281
     282        if ( ! $allowed )
    278283            $actions['enable'] = '<a href="' . esc_url( wp_nonce_url($url . 'action=enable&amp;theme=' . $theme_key . '&amp;paged=' . $page . '&amp;s=' . $s, 'enable-theme_' . $theme_key) ) . '" title="' . esc_attr__('Enable this theme') . '" class="edit">' . ( $this->is_site_themes ? __( 'Enable' ) : __( 'Network Enable' ) ) . '</a>';
    279284        else
     
    281286
    282287        if ( current_user_can('edit_themes') )
    283             $actions['edit'] = '<a href="' . esc_url('theme-editor.php?theme=' . urlencode( $theme['Name'] )) . '" title="' . esc_attr__('Open this theme in the Theme Editor') . '" class="edit">' . __('Edit') . '</a>';
    284 
    285         if ( empty( $theme['enabled'] ) && current_user_can( 'delete_themes' ) && ! $this->is_site_themes && $theme_key != get_option( 'stylesheet' ) && $theme_key != get_option( 'template' ) )
     288            $actions['edit'] = '<a href="' . esc_url('theme-editor.php?theme=' .  $theme_key ) . '" title="' . esc_attr__('Open this theme in the Theme Editor') . '" class="edit">' . __('Edit') . '</a>';
     289
     290        if ( ! $allowed && current_user_can( 'delete_themes' ) && ! $this->is_site_themes && $theme_key != get_option( 'stylesheet' ) && $theme_key != get_option( 'template' ) )
    286291            $actions['delete'] = '<a href="' . esc_url( wp_nonce_url( 'themes.php?action=delete-selected&amp;checked[]=' . $theme_key . '&amp;theme_status=' . $context . '&amp;paged=' . $page . '&amp;s=' . $s, 'bulk-themes' ) ) . '" title="' . esc_attr__( 'Delete this theme' ) . '" class="delete">' . __( 'Delete' ) . '</a>';
    287292
     
    289294        $actions = apply_filters( "theme_action_links_$theme_key", $actions, $theme_key, $theme, $context );
    290295
    291         $class = empty( $theme['enabled'] ) ? 'inactive' : 'active';
    292         $checkbox_id = "checkbox_" . md5($theme['Name']);
    293         $checkbox = "<input type='checkbox' name='checked[]' value='" . esc_attr( $theme_key ) . "' id='" . $checkbox_id . "' /><label class='screen-reader-text' for='" . $checkbox_id . "' >" . __('Select') . " " . $theme['Name'] . "</label>";
    294 
    295         $description = '<p>' . $theme['Description'] . '</p>';
    296         $theme_name = $theme['Name'];
    297 
    298         $id = sanitize_title( $theme_name );
     296        $class = ! $allowed ? 'inactive' : 'active';
     297        $checkbox_id = "checkbox_" . md5( $theme->get('Name') );
     298        $checkbox = "<input type='checkbox' name='checked[]' value='" . esc_attr( $theme_key ) . "' id='" . $checkbox_id . "' /><label class='screen-reader-text' for='" . $checkbox_id . "' >" . __('Select') . " " . $theme->display('Name') . "</label>";
     299
     300        $description = '<p>' . $theme->display( 'Description' ) . '</p>';
     301
     302        $id = sanitize_html_class( $theme->get_stylesheet() );
    299303
    300304        echo "<tr id='$id' class='$class'>";
     
    312316                    break;
    313317                case 'name':
    314                     echo "<td class='theme-title'$style><strong>$theme_name</strong>";
     318                    echo "<td class='theme-title'$style><strong>" . $theme->display('Name') . "</strong>";
    315319                    echo $this->row_actions( $actions, true );
    316320                    echo "</td>";
     
    318322                case 'description':
    319323                    echo "<td class='column-description desc'$style>
    320                         <div class='theme-description'>$description</div>
     324                        <div class='theme-description'>" . $theme->display( 'Description' ) . "</div>
    321325                        <div class='$class second theme-version-author-uri'>";
    322326
    323327                    $theme_meta = array();
    324328
    325                     if ( !empty( $theme['Version'] ) )
    326                         $theme_meta[] = sprintf( __( 'Version %s' ), $theme['Version'] );
    327 
    328                     if ( !empty( $theme['Author'] ) )
    329                         $theme_meta[] = sprintf( __( 'By %s' ), $theme['Author'] );
    330 
    331                     if ( !empty( $theme['Theme URI'] ) )
    332                         $theme_meta[] = '<a href="' . $theme['Theme URI'] . '" title="' . esc_attr__( 'Visit theme homepage' ) . '">' . __( 'Visit Theme Site' ) . '</a>';
     329                    if ( $theme->get('Version') )
     330                        $theme_meta[] = sprintf( __( 'Version %s' ), $theme->display('Version') );
     331
     332                    if ( $theme->get('Author') )
     333                        $theme_meta[] = sprintf( __( 'By %s' ), $theme->display('Author') );
     334
     335                    if ( $theme->get('ThemeURI') )
     336                        $theme_meta[] = '<a href="' . $theme->display('ThemeURI') . '" title="' . esc_attr__( 'Visit theme homepage' ) . '">' . __( 'Visit Theme Site' ) . '</a>';
    333337
    334338                    $theme_meta = apply_filters( 'theme_row_meta', $theme_meta, $theme_key, $theme, $status );
  • trunk/wp-admin/includes/class-wp-themes-list-table.php

    r20027 r20029  
    2525
    2626    function prepare_items() {
    27         global $ct;
    28 
    29         $ct = current_theme_info();
    30 
    31         $themes = get_allowed_themes();
     27        $themes = wp_get_themes( array( 'allowed' => true ) );
    3228
    3329        if ( ! empty( $_REQUEST['s'] ) ) {
     
    4642        if ( $this->search || $this->features ) {
    4743            foreach ( $themes as $key => $theme ) {
    48                 if ( !$this->search_theme( $theme ) )
     44                if ( ! $this->search_theme( $theme ) )
    4945                    unset( $themes[ $key ] );
    5046            }
    5147        }
    5248
    53         unset( $themes[$ct->name] );
    54         uksort( $themes, "strnatcasecmp" );
     49        unset( $themes[ get_option( 'stylesheet' ) ] );
     50        WP_Theme::sort_by_name( $themes );
    5551
    5652        $per_page = 999;
     
    126122    function display_rows() {
    127123        $themes = $this->items;
    128         $theme_names = array_keys( $themes );
    129         natcasesort( $theme_names );
    130 
    131     foreach ( $theme_names as $theme_name ) {
    132         $class = array( 'available-theme' );
    133     ?>
    134     <div class="<?php echo join( ' ', $class ); ?>">
    135     <?php if ( !empty( $theme_name ) ) :
    136     $template = $themes[$theme_name]['Template'];
    137     $stylesheet = $themes[$theme_name]['Stylesheet'];
    138     $title = $themes[$theme_name]['Title'];
    139     $version = $themes[$theme_name]['Version'];
    140     $description = $themes[$theme_name]['Description'];
    141     $author = $themes[$theme_name]['Author'];
    142     $screenshot = $themes[$theme_name]['Screenshot'];
    143     $stylesheet_dir = $themes[$theme_name]['Stylesheet Dir'];
    144     $template_dir = $themes[$theme_name]['Template Dir'];
    145     $parent_theme = $themes[$theme_name]['Parent Theme'];
    146     $theme_root = $themes[$theme_name]['Theme Root'];
    147     $theme_root_uri = $themes[$theme_name]['Theme Root URI'];
    148     $preview_link = esc_url( add_query_arg( array( 'preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'preview_iframe' => true, 'TB_iframe' => 'true' ), home_url( '/' ) ) );
    149     $preview_text = esc_attr( sprintf( __( 'Preview of &#8220;%s&#8221;' ), $title ) );
    150     $tags = $themes[$theme_name]['Tags'];
    151     $thickbox_class = 'thickbox thickbox-preview';
    152     $activate_link = wp_nonce_url( "themes.php?action=activate&amp;template=" . urlencode( $template ) . "&amp;stylesheet=" . urlencode( $stylesheet ), 'switch-theme_' . $template );
    153     $activate_text = esc_attr( sprintf( __( 'Activate &#8220;%s&#8221;' ), $title ) );
    154     $actions = array();
    155     $actions[] = '<a href="' . $activate_link . '" class="activatelink" title="' . $activate_text . '">' . __( 'Activate' ) . '</a>';
    156     $actions[] = '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="' . esc_attr( sprintf( __( 'Preview &#8220;%s&#8221;' ), $theme_name ) ) . '">' . __( 'Preview' ) . '</a>';
    157     if ( ! is_multisite() && current_user_can( 'delete_themes' ) )
    158         $actions[] = '<a class="submitdelete deletion" href="' . wp_nonce_url( "themes.php?action=delete&amp;template=$stylesheet", 'delete-theme_' . $stylesheet ) . '" onclick="' . "return confirm( '" . esc_js( sprintf( __( "You are about to delete this theme '%s'\n  'Cancel' to stop, 'OK' to delete." ), $theme_name ) ) . "' );" . '">' . __( 'Delete' ) . '</a>';
    159     $actions = apply_filters( 'theme_action_links', $actions, $themes[$theme_name] );
    160 
    161     $actions = implode ( ' | ', $actions );
    162 ?>
    163         <a href="<?php echo $preview_link; ?>" class="<?php echo $thickbox_class; ?> screenshot">
    164 <?php if ( $screenshot ) : ?>
    165             <img src="<?php echo $theme_root_uri . '/' . $stylesheet . '/' . $screenshot; ?>" alt="" />
    166 <?php endif; ?>
    167         </a>
    168 <h3><?php
    169     /* translators: 1: theme title, 2: theme version, 3: theme author */
    170     printf( __( '%1$s %2$s by %3$s' ), $title, $version, $author ) ; ?></h3>
    171 
    172 <span class='action-links'><?php echo $actions ?></span>
    173 <span class="separator hide-if-no-js">| </span><a href="#" class="theme-detail hide-if-no-js" tabindex='4'><?php _e('Details') ?></a>
    174 <div class="themedetaildiv hide-if-js">
    175 <p><?php echo $description; ?></p>
    176     <?php if ( current_user_can( 'edit_themes' ) && $parent_theme ) {
    177     /* translators: 1: theme title, 2:  template dir, 3: stylesheet_dir, 4: theme title, 5: parent_theme */ ?>
    178     <p><?php printf( __( 'The template files are located in <code>%2$s</code>. The stylesheet files are located in <code>%3$s</code>. <strong>%4$s</strong> uses templates from <strong>%5$s</strong>. Changes made to the templates will affect both themes.' ), $title, str_replace( WP_CONTENT_DIR, '', $template_dir ), str_replace( WP_CONTENT_DIR, '', $stylesheet_dir ), $title, $parent_theme ); ?></p>
    179 <?php } else { ?>
    180     <p><?php printf( __( 'All of this theme&#8217;s files are located in <code>%2$s</code>.' ), $title, str_replace( WP_CONTENT_DIR, '', $template_dir ), str_replace( WP_CONTENT_DIR, '', $stylesheet_dir ) ); ?></p>
    181 <?php } ?>
    182 <?php if ( $tags ) : ?>
    183 <p><?php _e( 'Tags:' ); ?> <?php echo join( ', ', $tags ); ?></p>
    184 <?php endif; ?>
    185 <?php endif; // end if not empty theme_name ?>
    186 </div>
    187     <?php theme_update_available( $themes[$theme_name] ); ?>
    188     </div>
    189 <?php } // end foreach $theme_names
     124
     125        foreach ( $themes as $theme ) {
     126            echo '<div class="available-theme">';
     127
     128            $template = $theme->get_template();
     129            $stylesheet = $theme->get_stylesheet();
     130
     131            $title = $theme->display('Name');
     132            $version = $theme->display('Version');
     133            $author = $theme->display('Author');
     134 
     135            $activate_link = wp_nonce_url( "themes.php?action=activate&amp;template=" . urlencode( $template ) . "&amp;stylesheet=" . urlencode( $stylesheet ), 'switch-theme_' . $template );
     136            $preview_link = esc_url( add_query_arg(
     137                array( 'preview' => 1, 'template' => $template, 'stylesheet' => $stylesheet, 'preview_iframe' => true, 'TB_iframe' => 'true' ),
     138                home_url( '/' ) ) );
     139 
     140            $actions = array();
     141            $actions[] = '<a href="' . $activate_link . '" class="activatelink" title="'
     142                . esc_attr( sprintf( __( 'Activate &#8220;%s&#8221;' ), $title ) ) . '">' . __( 'Activate' ) . '</a>';
     143            $actions[] = '<a href="' . $preview_link . '" class="thickbox thickbox-preview" title="'
     144                . esc_attr( sprintf( __( 'Preview &#8220;%s&#8221;' ), $title ) ) . '">' . __( 'Preview' ) . '</a>';
     145            if ( ! is_multisite() && current_user_can( 'delete_themes' ) )
     146                $actions[] = '<a class="submitdelete deletion" href="' . wp_nonce_url( "themes.php?action=delete&amp;template=$stylesheet", 'delete-theme_' . $stylesheet )
     147                    . '" onclick="' . "return confirm( '" . esc_js( sprintf( __( "You are about to delete this theme '%s'\n  'Cancel' to stop, 'OK' to delete." ), $title ) )
     148                    . "' );" . '">' . __( 'Delete' ) . '</a>';
     149 
     150            $actions = apply_filters( 'theme_action_links', $actions, $theme );
     151 
     152            $actions = implode ( ' | ', $actions );
     153            ?>
     154            <a href="<?php echo $preview_link; ?>" class="thickbox thickbox-preview screenshot">
     155            <?php if ( $theme->get_screenshot() ) : ?>
     156                <img src="<?php echo esc_url( $theme->get_screenshot( 'absolute' ) ); ?>" alt="" />
     157            <?php endif; ?>
     158            </a>
     159            <h3><?php
     160            /* translators: 1: theme title, 2: theme version, 3: theme author */
     161            printf( __( '%1$s %2$s by %3$s' ), $title, $version, $author ) ; ?></h3>
     162 
     163            <span class='action-links'><?php echo $actions ?></span>
     164            <span class="separator hide-if-no-js">| </span><a href="#" class="theme-detail hide-if-no-js" tabindex='4'><?php _e('Details') ?></a>
     165            <div class="themedetaildiv hide-if-js">
     166            <p><?php echo $theme->display('Description'); ?></p>
     167            <?php if ( current_user_can( 'edit_themes' ) && $theme->parent() ) :
     168                /* translators: 1: theme title, 2:  template dir, 3: stylesheet_dir, 4: theme title, 5: parent_theme */ ?>
     169                <p><?php printf( __( 'The template files are located in <code>%2$s</code>. The stylesheet files are located in <code>%3$s</code>. <strong>%4$s</strong> uses templates from <strong>%5$s</strong>. Changes made to the templates will affect both themes.' ),
     170                    $title, str_replace( WP_CONTENT_DIR, '', $theme->get_template_directory() ), str_replace( WP_CONTENT_DIR, '', $theme->get_stylesheet_directory() ), $title, $theme->parent()->display('Name') ); ?></p>
     171            <?php else :
     172                    /* translators: 1: theme title, 2:  template dir, 3: stylesheet_dir */ ?>
     173                <p><?php printf( __( 'All of this theme&#8217;s files are located in <code>%2$s</code>.' ),
     174                    $title, str_replace( WP_CONTENT_DIR, '', $theme->get_template_directory() ), str_replace( WP_CONTENT_DIR, '', $theme->get_stylesheet_directory() ) ); ?></p>
     175            <?php endif; ?>
     176            <?php
     177            if ( $theme->get('Tags') )
     178                printf( '<p>' . __( 'Tags: %s.' ) . '</p>', $theme->display('Tags') );
     179            ?>
     180            </div>
     181            <?php theme_update_available( $theme ); ?>
     182            </div>
     183        <?php
     184        }
    190185    }
    191186
     
    194189        if ( $this->features ) {
    195190            foreach ( $this->features as $word ) {
    196                 if ( ! in_array( $word, $theme['Tags'] ) )
     191                if ( ! in_array( $word, $theme->get('Tags') ) )
    197192                    return false;
    198193            }
     
    202197        if ( $this->search ) {
    203198            foreach ( $this->search as $word ) {
    204                 if ( in_array( $word, $theme['Tags'] ) )
     199                if ( in_array( $word, $theme->get('Tags') ) )
    205200                    continue;
    206             }
    207 
    208             foreach ( array( 'Name', 'Title', 'Description', 'Author', 'Template', 'Stylesheet' ) as $header ) {
    209                 if ( false !== stripos( $theme[ $header ], $word ) )
    210                     continue 2;
    211             }
    212 
    213             return false;
     201
     202                foreach ( array( 'Name', 'Description', 'Author', 'AuthorURI' ) as $header ) {
     203                    // Don't mark up; Do translate.
     204                    if ( false !== stripos( $theme->display( $header, false, true ), $word ) )
     205                        continue 2;
     206                }
     207
     208                if ( false !== stripos( $theme->get_stylesheet(), $word ) )
     209                    continue;
     210
     211                if ( false !== stripos( $theme->get_template(), $word ) )
     212                    continue;
     213 
     214                return false;
     215            }
    214216        }
    215217
  • trunk/wp-admin/includes/dashboard.php

    r19712 r20029  
    384384
    385385    echo "\n\t".'<div class="versions">';
    386     $ct = current_theme_info();
     386    $theme = wp_get_theme();
    387387
    388388    echo "\n\t<p>";
    389389
    390     if ( empty( $ct->stylesheet_dir ) ) {
     390    if ( $theme->errors() ) {
    391391        if ( ! is_multisite() || is_super_admin() )
    392392            echo '<span class="error-message">' . __('ERROR: The themes directory is either empty or doesn&#8217;t exist. Please check your installation.') . '</span>';
     
    402402        $num = number_format_i18n( $num_widgets );
    403403
    404         $switch_themes = $ct->title;
     404        $switch_themes = $theme->display('Name');
    405405        if ( current_user_can( 'switch_themes') )
    406406            $switch_themes = '<a href="themes.php">' . $switch_themes . '</a>';
     
    412412    } else {
    413413        if ( current_user_can( 'switch_themes' ) )
    414             printf( __('Theme <span class="b"><a href="themes.php">%1$s</a></span>'), $ct->title );
     414            printf( __('Theme <span class="b"><a href="themes.php">%1$s</a></span>'), $theme->display('Name') );
    415415        else
    416             printf( __('Theme <span class="b">%1$s</span>'), $ct->title );
     416            printf( __('Theme <span class="b">%1$s</span>'), $theme->display('Name') );
    417417    }
    418418    echo '</p>';
     
    13141314        <h4><span class="icon16 icon-appearance"></span> <?php _e( 'Customize Your Site' ); ?></h4>
    13151315        <?php
    1316         $ct = current_theme_info();
    1317         if ( empty ( $ct->stylesheet_dir ) ) :
     1316        $theme = wp_get_theme();
     1317        if ( $theme->errors() ) :
    13181318            echo '<p>';
    13191319            printf( __( '<a href="%s">Install a theme</a> to get started customizing your site.' ), esc_url( admin_url( 'themes.php' ) ) );
     
    13211321        else:
    13221322            $customize_links = array();
    1323             if ( 'twentyeleven' == $ct->stylesheet )
     1323            if ( 'twentyeleven' == $theme->get_stylesheet() )
    13241324                $customize_links[] = sprintf( __( '<a href="%s">Choose light or dark</a>' ), esc_url( admin_url( 'themes.php?page=theme_options' ) ) );
    13251325
     
    13351335            if ( ! empty( $customize_links ) ) {
    13361336                echo '<p>';
    1337                 printf( __( 'Use the current theme &mdash; %1$s &mdash; or <a href="%2$s">choose a new one</a>. If you stick with %3$s, here are a few ways to make your site look unique.' ), $ct->title, esc_url( admin_url( 'themes.php' ) ), $ct->title );
     1337                printf( __( 'Use the current theme &mdash; %1$s &mdash; or <a href="%2$s">choose a new one</a>. If you stick with %1$s, here are a few ways to make your site look unique.' ), $theme->display('Name'), esc_url( admin_url( 'themes.php' ) ) );
    13381338                echo '</p>';
    13391339            ?>
     
    13461346            } else {
    13471347                echo '<p>';
    1348                 printf( __( 'Use the current theme &mdash; %1$s &mdash; or <a href="%2$s">choose a new one</a>.' ), $ct->title, esc_url( admin_url( 'themes.php' ) ) );
     1348                printf( __( 'Use the current theme &mdash; %1$s &mdash; or <a href="%2$s">choose a new one</a>.' ), $this->display('Name'), esc_url( admin_url( 'themes.php' ) ) );
    13491349                echo '</p>';
    13501350            }
  • trunk/wp-admin/includes/deprecated.php

    r19684 r20029  
    881881    WP_Screen::add_old_compat_help( $screen, $help );
    882882}
     883
     884/**
     885 * Get the allowed themes for the current blog.
     886 *
     887 * @since 3.0.0
     888 * @deprecated 3.4.0
     889 * @deprecated Use wp_get_themes()
     890 * @see wp_get_themes()
     891 *
     892 * @return array $themes Array of allowed themes.
     893 */
     894function get_allowed_themes() {
     895    _deprecated_function( __FUNCTION__, '3.4', "wp_get_themes( array( 'allowed' => true ) )" );
     896
     897    $themes = wp_get_themes( array( 'allowed' => true ) );
     898
     899    $wp_themes = array();
     900    foreach ( $themes as $theme ) {
     901        $wp_themes[ $theme->get('Name') ] = $theme;
     902    }
     903
     904    return $wp_themes;
     905}
     906
     907/**
     908 * {@internal Missing Short Description}}
     909 *
     910 * @since 1.5.0
     911 *
     912 * @return unknown
     913 */
     914function get_broken_themes() {
     915    _deprecated_function( __FUNCTION__, '3.4', "wp_get_themes( array( 'errors' => true )" );
     916
     917    $themes = wp_get_themes( array( 'errors' => true ) );
     918    $broken = array();
     919    foreach ( $themes as $theme ) {
     920        $broken[ $theme->get('Name') ] = array(
     921            'Title' => $theme->get('Name'),
     922            'Description' => $theme->errors()->get_error_message(),
     923        );
     924    }
     925    return $broken;
     926}
     927
     928/**
     929 * {@internal Missing Short Description}}
     930 *
     931 * @since 2.0.0
     932 *
     933 * @return unknown
     934 */
     935function current_theme_info() {
     936    _deprecated_function( __FUNCTION__, '3.4', 'wp_get_theme()' );
     937
     938    return wp_get_theme();
     939}
  • trunk/wp-admin/includes/ms-deprecated.php

    r19712 r20029  
    6565    return is_network_only_plugin( $file );
    6666}
     67
     68function get_site_allowed_themes() {
     69    _deprecated_function( __FUNCTION__, '3.4', 'WP_Theme::get_allowed_on_network()' );
     70    return array_map( 'intval', WP_Theme::get_allowed_on_network() );
     71}
     72
     73function wpmu_get_blog_allowedthemes( $blog_id = 0 ) {
     74    _deprecated_function( __FUNCTION__, '3.4', 'WP_Theme::get_allowed_on_site()' );
     75    return array_map( 'intval', WP_Theme::get_allowed_on_site( $blog_id ) );
     76}
  • trunk/wp-admin/includes/ms.php

    r19712 r20029  
    170170}
    171171
    172 function wpmu_get_blog_allowedthemes( $blog_id = 0 ) {
    173     $themes = get_themes();
    174 
    175     if ( $blog_id != 0 )
    176         switch_to_blog( $blog_id );
    177 
    178     $blog_allowed_themes = get_option( 'allowedthemes' );
    179     if ( !is_array( $blog_allowed_themes ) || empty( $blog_allowed_themes ) ) { // convert old allowed_themes to new allowedthemes
    180         $blog_allowed_themes = get_option( 'allowed_themes' );
    181 
    182         if ( is_array( $blog_allowed_themes ) ) {
    183             foreach( (array) $themes as $key => $theme ) {
    184                 $theme_key = esc_html( $theme['Stylesheet'] );
    185                 if ( isset( $blog_allowed_themes[$key] ) == true ) {
    186                     $blog_allowedthemes[$theme_key] = 1;
    187                 }
    188             }
    189             $blog_allowed_themes = $blog_allowedthemes;
    190             add_option( 'allowedthemes', $blog_allowed_themes );
    191             delete_option( 'allowed_themes' );
    192         }
    193     }
    194 
    195     if ( $blog_id != 0 )
    196         restore_current_blog();
    197 
    198     return $blog_allowed_themes;
    199 }
    200 
    201172function update_option_new_admin_email( $old_value, $value ) {
    202173    $email = get_option( 'admin_email' );
     
    296267}
    297268add_action( 'admin_notices', 'new_user_email_admin_notice' );
    298 
    299 function get_site_allowed_themes() {
    300     $themes = get_themes();
    301     $allowed_themes = get_site_option( 'allowedthemes' );
    302     if ( !is_array( $allowed_themes ) || empty( $allowed_themes ) ) {
    303         $allowed_themes = get_site_option( 'allowed_themes' ); // convert old allowed_themes format
    304         if ( !is_array( $allowed_themes ) ) {
    305             $allowed_themes = array();
    306         } else {
    307             foreach( (array) $themes as $key => $theme ) {
    308                 $theme_key = esc_html( $theme['Stylesheet'] );
    309                 if ( isset( $allowed_themes[ $key ] ) == true ) {
    310                     $allowedthemes[ $theme_key ] = 1;
    311                 }
    312             }
    313             $allowed_themes = $allowedthemes;
    314         }
    315     }
    316     return $allowed_themes;
    317 }
    318269
    319270/**
  • trunk/wp-admin/includes/schema.php

    r20023 r20029  
    344344    $template = WP_DEFAULT_THEME;
    345345    // If default theme is a child theme, we need to get its template
    346     foreach ( (array) get_themes() as $theme ) {
    347         if ( WP_DEFAULT_THEME == $theme['Stylesheet'] ) {
    348             $template = $theme['Template'];
    349             break;
    350         }
    351     }
     346    $theme = wp_get_theme( $template );
     347    if ( ! $theme->errors() )
     348        $template = $theme->get_template();
    352349
    353350    $timezone_string = '';
  • trunk/wp-admin/includes/theme-install.php

    r19979 r20029  
    266266    }
    267267
    268     $themes = get_themes();
    269     foreach ( (array) $themes as $this_theme ) {
    270         if ( is_array($this_theme) && $this_theme['Stylesheet'] == $api->slug ) {
    271             if ( version_compare( $this_theme['Version'], $api->version, '=' ) ) {
     268    $theme = wp_get_theme( $api->slug );
     269    if ( is_a( $theme, 'WP_Theme' ) ) {
     270        switch ( version_compare( $theme->get('Version'), $api->version ) ) {
     271            case 0; // equal
    272272                $type = 'latest_installed';
    273             } elseif ( version_compare( $this_theme['Version'], $api->version, '>' ) ) {
     273            case 1: // installed theme > api version
    274274                $type = 'newer_installed';
    275                 $newer_version = $this_theme['Version'];
    276             }
    277             break;
     275                $newer_version = $theme->get('Version');
    278276        }
    279277    }
  • trunk/wp-admin/includes/theme.php

    r20025 r20029  
    66 * @subpackage Administration
    77 */
    8 
    9 /**
    10  * {@internal Missing Short Description}}
    11  *
    12  * @since 2.0.0
    13  *
    14  * @return unknown
    15  */
    16 function current_theme_info() {
    17     $themes = get_themes();
    18     $current_theme = get_current_theme();
    19 
    20     if ( ! $themes ) {
    21         $ct = new stdClass;
    22         $ct->name = $current_theme;
    23         return $ct;
    24     }
    25 
    26     if ( ! isset( $themes[$current_theme] ) ) {
    27         delete_option( 'current_theme' );
    28         $current_theme = get_current_theme();
    29     }
    30 
    31     $ct = new stdClass;
    32     $ct->name = $current_theme;
    33     $ct->title = $themes[$current_theme]['Title'];
    34     $ct->version = $themes[$current_theme]['Version'];
    35     $ct->parent_theme = $themes[$current_theme]['Parent Theme'];
    36     $ct->template_dir = $themes[$current_theme]['Template Dir'];
    37     $ct->stylesheet_dir = $themes[$current_theme]['Stylesheet Dir'];
    38     $ct->template = $themes[$current_theme]['Template'];
    39     $ct->stylesheet = $themes[$current_theme]['Stylesheet'];
    40     $ct->screenshot = $themes[$current_theme]['Screenshot'];
    41     $ct->description = $themes[$current_theme]['Description'];
    42     $ct->author = $themes[$current_theme]['Author'];
    43     $ct->tags = $themes[$current_theme]['Tags'];
    44     $ct->theme_root = $themes[$current_theme]['Theme Root'];
    45     $ct->theme_root_uri = $themes[$current_theme]['Theme Root URI'];
    46     return $ct;
    47 }
    488
    499/**
     
    11575
    11676/**
    117  * {@internal Missing Short Description}}
     77 * Get the Page Templates available in this theme
    11878 *
    11979 * @since 1.5.0
    12080 *
    121  * @return unknown
    122  */
    123 function get_broken_themes() {
    124     global $wp_broken_themes;
    125 
    126     get_themes();
    127     return $wp_broken_themes;
    128 }
    129 
    130 /**
    131  * Get the allowed themes for the current blog.
    132  *
    133  * @since 3.0.0
    134  *
    135  * @uses get_themes()
    136  * @uses current_theme_info()
    137  * @uses get_site_allowed_themes()
    138  * @uses wpmu_get_blog_allowedthemes
    139  *
    140  * @return array $themes Array of allowed themes.
    141  */
    142 function get_allowed_themes() {
    143     if ( !is_multisite() )
    144         return get_themes();
    145 
    146     $themes = get_themes();
    147     $ct = current_theme_info();
    148     $allowed_themes = apply_filters("allowed_themes", get_site_allowed_themes() );
    149     if ( $allowed_themes == false )
    150         $allowed_themes = array();
    151 
    152     $blog_allowed_themes = wpmu_get_blog_allowedthemes();
    153     if ( is_array( $blog_allowed_themes ) )
    154         $allowed_themes = array_merge( $allowed_themes, $blog_allowed_themes );
    155 
    156     if ( isset( $allowed_themes[ esc_html( $ct->stylesheet ) ] ) == false )
    157         $allowed_themes[ esc_html( $ct->stylesheet ) ] = true;
    158 
    159     reset( $themes );
    160     foreach ( $themes as $key => $theme ) {
    161         if ( isset( $allowed_themes[ esc_html( $theme[ 'Stylesheet' ] ) ] ) == false )
    162             unset( $themes[ $key ] );
    163     }
    164     reset( $themes );
    165 
    166     return $themes;
    167 }
    168 
    169 /**
    170  * Get the Page Templates available in this theme
    171  *
    172  * @since 1.5.0
    173  *
    17481 * @return array Key is the template name, value is the filename of the template
    17582 */
    17683function get_page_templates() {
    177     $themes = get_themes();
    178     $theme = get_current_theme();
    179     $templates = $themes[$theme]['Template Files'];
    180     $page_templates = array();
    181 
    182     if ( is_array( $templates ) ) {
    183         $base = array( trailingslashit(get_template_directory()), trailingslashit(get_stylesheet_directory()) );
    184 
    185         foreach ( $templates as $template ) {
    186             $basename = str_replace($base, '', $template);
    187 
    188             // don't allow template files in subdirectories
    189             if ( false !== strpos($basename, '/') )
    190                 continue;
    191 
    192             if ( 'functions.php' == $basename )
    193                 continue;
    194 
    195             $template_data = implode( '', file( $template ));
    196 
    197             $name = '';
    198             if ( preg_match( '|Template Name:(.*)$|mi', $template_data, $name ) )
    199                 $name = _cleanup_header_comment($name[1]);
    200 
    201             if ( !empty( $name ) ) {
    202                 $page_templates[trim( $name )] = $basename;
    203             }
    204         }
    205     }
    206 
    207     return $page_templates;
     84    return wp_get_theme()->get_page_templates();
    20885}
    20986
     
    241118        $themes_update = get_site_transient('update_themes');
    242119
    243     if ( is_object($theme) && isset($theme->stylesheet) )
    244         $stylesheet = $theme->stylesheet;
    245     elseif ( is_array($theme) && isset($theme['Stylesheet']) )
    246         $stylesheet = $theme['Stylesheet'];
    247     else
    248         return false; //No valid info passed.
     120    if ( ! is_a( $theme, 'WP_Theme' ) )
     121        return;
     122
     123    $stylesheet = $theme->get_stylesheet();
    249124
    250125    if ( isset($themes_update->response[ $stylesheet ]) ) {
    251126        $update = $themes_update->response[ $stylesheet ];
    252         $theme_name = is_object($theme) ? $theme->name : (is_array($theme) ? $theme['Name'] : '');
     127        $theme_name = $theme->get('Name');
    253128        $details_url = add_query_arg(array('TB_iframe' => 'true', 'width' => 1024, 'height' => 800), $update['url']); //Theme browser inside WP? replace this, Also, theme preview JS will override this on the available list.
    254129        $update_url = wp_nonce_url('update.php?action=upgrade-theme&amp;theme=' . urlencode($stylesheet), 'upgrade-theme_' . $stylesheet);
  • trunk/wp-admin/includes/update.php

    r19809 r20029  
    218218
    219219function get_theme_updates() {
    220     $themes = get_themes();
     220    $themes = wp_get_themes();
    221221    $current = get_site_transient('update_themes');
    222222    $update_themes = array();
    223223
    224     foreach ( $themes as $theme ) {
    225         $theme = (object) $theme;
    226         if ( isset($current->response[ $theme->Stylesheet ]) ) {
    227             $update_themes[$theme->Stylesheet] = $theme;
    228             $update_themes[$theme->Stylesheet]->update = $current->response[ $theme->Stylesheet ];
    229         }
     224    foreach ( $current->response as $stylesheet => $data ) {
     225        $update_themes[ $stylesheet ] = wp_get_theme( $stylesheet );
     226        $update_themes[ $stylesheet ]->update = $data;
    230227    }
    231228
  • trunk/wp-admin/themes.php

    r19941 r20029  
    9797<?php endif; ?>
    9898</h2>
    99 
    100 <h3><?php _e('Current Theme'); ?></h3>
     99<?php $ct = wp_get_theme(); ?>
     100<h3><?php _e( 'Current Theme' ); ?></h3>
    101101<div id="current-theme">
    102 <?php if ( $ct->screenshot ) : ?>
    103 <img src="<?php echo $ct->theme_root_uri . '/' . $ct->stylesheet . '/' . $ct->screenshot; ?>" alt="<?php esc_attr_e('Current theme preview'); ?>" />
     102<?php if ( $ct->get_screenshot() ) : ?>
     103<img src="<?php echo $ct->get_screenshot( 'absolute' ); ?>" alt="<?php esc_attr_e( 'Current theme preview'); ?>" />
    104104<?php endif; ?>
    105105<h4><?php
    106106    /* translators: 1: theme title, 2: theme version, 3: theme author */
    107     printf(__('%1$s %2$s by %3$s'), $ct->title, $ct->version, $ct->author) ; ?></h4>
    108 <p class="theme-description"><?php echo $ct->description; ?></p>
     107    printf( __( '%1$s %2$s by %3$s' ), $ct->display('Name'), $ct->display('Version'), $ct->display('Author') ) ; ?></h4>
     108<p class="theme-description"><?php echo $ct->display('Description'); ?></p>
    109109<div class="theme-options">
    110110    <span><?php _e( 'Options:' )?></span>
     
    118118                continue;
    119119            // 0 = name, 1 = capability, 2 = file
    120             if ( ( strcmp($self, $item[2]) == 0 && empty($parent_file)) || ($parent_file && ($item[2] == $parent_file)) ) $class = ' class="current"';
    121 
     120            if ( ( strcmp($self, $item[2]) == 0 && empty($parent_file)) || ($parent_file && ($item[2] == $parent_file)) )
     121                $class = ' class="current"';
    122122            if ( !empty($submenu[$item[2]]) ) {
    123123                $submenu[$item[2]] = array_values($submenu[$item[2]]); // Re-index.
     
    138138    echo implode ( ' | ', $options );
    139139
    140     if ( $ct->tags ) : ?>
    141     <p><?php _e('Tags:'); ?> <?php echo join(', ', $ct->tags); ?></p>
     140    if ( $ct->get('Tags') ) : ?>
     141    <p><?php _e('Tags:'); ?> <?php echo $ct->display('Tags'); ?></p>
    142142    <?php endif; ?>
    143143</div>
     
    219219<?php
    220220// List broken themes, if any.
    221 $broken_themes = get_broken_themes();
    222 if ( current_user_can('edit_themes') && count( $broken_themes ) ) {
     221if ( current_user_can('edit_themes') && $broken_themes = wp_get_themes( array( 'errors' => true ) ) ) {
    223222?>
    224223
     
    232231    </tr>
    233232<?php
    234     $theme = '';
    235 
    236     $theme_names = array_keys($broken_themes);
    237     natcasesort($theme_names);
    238 
    239     foreach ($theme_names as $theme_name) {
    240         $name = $broken_themes[$theme_name]['Title'];
    241         $description = $broken_themes[$theme_name]['Description'];
    242 
    243         $theme = ('class="alternate"' == $theme) ? '' : 'class="alternate"';
     233    $alt = '';
     234    foreach ( $broken_themes as $broken_theme ) {
     235        $alt = ('class="alternate"' == $alt) ? '' : 'class="alternate"';
    244236        echo "
    245         <tr $theme>
    246              <td>$name</td>
    247              <td>$description</td>
     237        <tr $alt>
     238             <td>" . $broken_theme->get('Name') ."</td>
     239             <td>" . $broken_theme->errors()->get_error_message() . "</td>
    248240        </tr>";
    249241    }
  • trunk/wp-includes/class-wp-customize.php

    r19995 r20029  
    243243     */
    244244    public function current_theme( $current_theme ) {
    245         $themes = get_themes();
    246 
    247         if ( ! $themes )
    248             return $current_theme;
    249 
    250         foreach ( $themes as $theme ) {
    251             if ( $theme['Stylesheet'] == $this->stylesheet && $theme['Template'] == $this->template )
    252                 return $theme['Name'];
    253         }
    254 
    255         return $current_theme;
     245        return wp_get_theme( $this->stylesheet )->get('Name');
    256246    }
    257247
  • trunk/wp-includes/deprecated.php

    r20000 r20029  
    29082908    _deprecated_function( __FUNCTION__, 'error_log()' );
    29092909}
     2910
     2911/**
     2912 * Retrieve list of themes with theme data in theme directory.
     2913 *
     2914 * The theme is broken, if it doesn't have a parent theme and is missing either
     2915 * style.css and, or index.php. If the theme has a parent theme then it is
     2916 * broken, if it is missing style.css; index.php is optional.
     2917 *
     2918 * @since 1.5.0
     2919 * @global array $wp_themes Stores the working themes.
     2920 *
     2921 * @return array Theme list with theme data.
     2922 */
     2923function get_themes() {
     2924    _deprecated_function( __FUNCTION__, '3.4', 'wp_get_themes()' );
     2925
     2926    global $wp_themes;
     2927    if ( isset( $wp_themes ) )
     2928        return $wp_themes;
     2929
     2930    $themes = wp_get_themes();
     2931    $wp_themes = array();
     2932
     2933    foreach ( $themes as $theme ) {
     2934        $wp_themes[ $theme->get('Name') ] = $theme;
     2935    }
     2936
     2937    return $wp_themes;
     2938}
     2939
     2940/**
     2941 * Retrieve theme data.
     2942 *
     2943 * @since 1.5.0
     2944 *
     2945 * @param string $theme Theme name.
     2946 * @return array|null Null, if theme name does not exist. Theme data, if exists.
     2947 */
     2948function get_theme( $theme ) {
     2949    _deprecated_function( __FUNCTION__, '3.4', 'wp_get_theme($stylesheet)' );
     2950
     2951    $themes = get_themes();
     2952    if ( is_array( $themes ) && array_key_exists( $theme, $themes ) )
     2953        return $themes[$theme];
     2954    return null;
     2955}
  • trunk/wp-includes/theme.php

    r20021 r20029  
    66 * @subpackage Theme
    77 */
     8
     9/**
     10 * Returns an array of WP_Theme objects based on the arguments.
     11 *
     12 * Despite advances over get_themes(), this function is still quite expensive, and grows
     13 * linearly with additional themes. Stick to wp_get_theme() if possible.
     14 *
     15 * @since 3.4.0
     16 *
     17 * @param array $args Arguments. Currently 'errors' (defaults to false), 'allowed'
     18 *  (true, false; null for either; defaults to null; only applies to multisite), and 'blog_id'
     19 *  (defaults to current blog; used to find allowed themes; only applies to multisite).
     20 * @return Array of WP_Theme objects.
     21 */
     22function wp_get_themes( $args = array() ) {
     23    global $wp_theme_directories;
     24
     25    $defaults = array( 'errors' => false, 'allowed' => null, 'blog_id' => 0 );
     26    $args = wp_parse_args( $args, $defaults );
     27
     28    static $_themes;
     29    if ( ! isset( $_themes ) ) {
     30        $_themes = array();
     31        $theme_data = search_theme_directories();
     32        // Make sure the current theme wins out, in case search_theme_directories() picks the wrong
     33        // one in the case of a conflict. (Normally, last registered theme root wins.)
     34        $current_theme = get_stylesheet();
     35        $current_theme_root = get_raw_theme_root( $current_theme );
     36        if ( ! in_array( $current_theme_root, $wp_theme_directories ) )
     37            $current_theme_root = WP_CONTENT_DIR . $current_theme_root;
     38        foreach ( (array) $theme_data as $theme_slug => $data ) {
     39            if ( $current_theme == $theme_slug && $current_theme_root != $data['theme_root'] )
     40                $_themes[ $theme_slug ] = new WP_Theme( $theme_slug, $current_theme_root );
     41            else
     42                $_themes[ $theme_slug ] = new WP_Theme( $theme_slug, $data['theme_root'] );
     43        }
     44    }
     45
     46    $themes = $_themes;
     47    if ( empty( $themes ) )
     48        return $themes;
     49
     50    if ( null !== $args['errors'] ) {
     51        foreach ( $themes as $theme_slug => $theme ) {
     52            if ( $theme->errors() != $args['errors'] )
     53                unset( $themes[ $theme_slug ] );
     54        }
     55    }
     56
     57    if ( is_multisite() && null !== $args['allowed'] ) {
     58        if ( $allowed = $args['allowed'] ) {
     59            if ( 'network' == $allowed )
     60                $themes = array_intersect_key( $themes, WP_Theme::get_allowed_on_network( $args['blog_id'] ) );
     61            elseif ( 'site' == $allowed )
     62                $themes = array_intersect_key( $themes, WP_Theme::get_allowed_on_site( $args['blog_id'] ) );
     63            else
     64                $themes = array_intersect_key( $themes, WP_Theme::get_allowed( $args['blog_id'] ) );
     65        } else {
     66            $themes = array_diff_key( $themes, WP_Theme::get_allowed( $args['blog_id'] ) );
     67        }
     68    }
     69
     70    return $themes;
     71}
     72
     73/**
     74 * Gets a WP_Theme object for a theme.
     75 *
     76 * @since 3.4.0
     77 *
     78 * @param string $stylesheet Directory name for the theme. Optional. Defaults to current theme.
     79 * @param string $theme_root Absolute path of the theme root to look in. Optional. If not specified, get_raw_theme_root()
     80 *  is used to calculate the theme root for the $stylesheet provided (or current theme).
     81 * @return WP_Theme
     82 */
     83function wp_get_theme( $stylesheet = null, $theme_root = null ) {
     84    global $wp_theme_directories;
     85
     86    if ( empty( $stylesheet ) )
     87        $stylesheet = get_stylesheet();
     88
     89    if ( empty( $theme_root ) ) {
     90        $theme_root = get_raw_theme_root( $stylesheet );
     91        if ( ! in_array( $theme_root, $wp_theme_directories ) )
     92            $theme_root = WP_CONTENT_DIR . $theme_root;
     93    }
     94
     95    return new WP_Theme( $stylesheet, $theme_root );
     96}
    897
    998/**
     
    248337
    249338/**
    250  * Retrieve list of themes with theme data in theme directory.
    251  *
    252  * The theme is broken, if it doesn't have a parent theme and is missing either
    253  * style.css and, or index.php. If the theme has a parent theme then it is
    254  * broken, if it is missing style.css; index.php is optional. The broken theme
    255  * list is saved in the {@link $wp_broken_themes} global, which is displayed on
    256  * the theme list in the administration panels.
    257  *
    258  * @since 1.5.0
    259  * @global array $wp_broken_themes Stores the broken themes.
    260  * @global array $wp_themes Stores the working themes.
    261  *
    262  * @return array Theme list with theme data.
    263  */
    264 function get_themes() {
    265     global $wp_themes, $wp_broken_themes;
    266 
    267     if ( isset($wp_themes) )
    268         return $wp_themes;
    269 
    270     if ( !$theme_files = search_theme_directories() )
    271         return false;
    272 
    273     asort( $theme_files );
    274 
    275     $wp_themes = array();
    276 
    277     foreach ( (array) $theme_files as $theme_file ) {
    278         $theme_root = $theme_file['theme_root'];
    279         $theme_file = $theme_file['theme_file'];
    280 
    281         if ( !is_readable("$theme_root/$theme_file") ) {
    282             $wp_broken_themes[$theme_file] = array('Name' => $theme_file, 'Title' => $theme_file, 'Description' => __('File not readable.'));
    283             continue;
    284         }
    285 
    286         $theme_data = get_theme_data("$theme_root/$theme_file");
    287 
    288         $name        = $theme_data['Name'];
    289         $title       = $theme_data['Title'];
    290         $description = wptexturize($theme_data['Description']);
    291         $version     = $theme_data['Version'];
    292         $author      = $theme_data['Author'];
    293         $template    = $theme_data['Template'];
    294         $stylesheet  = dirname($theme_file);
    295 
    296         $screenshot = false;
    297         foreach ( array('png', 'gif', 'jpg', 'jpeg') as $ext ) {
    298             if (file_exists("$theme_root/$stylesheet/screenshot.$ext")) {
    299                 $screenshot = "screenshot.$ext";
    300                 break;
    301             }
    302         }
    303 
    304         if ( empty($name) ) {
    305             $name = dirname($theme_file);
    306             $title = $name;
    307         }
    308 
    309         $parent_template = $template;
    310 
    311         if ( empty($template) ) {
    312             if ( file_exists("$theme_root/$stylesheet/index.php") )
    313                 $template = $stylesheet;
    314             else
    315                 continue;
    316         }
    317 
    318         $template = trim( $template );
    319 
    320         if ( !file_exists("$theme_root/$template/index.php") ) {
    321             $parent_dir = dirname(dirname($theme_file));
    322             if ( file_exists("$theme_root/$parent_dir/$template/index.php") ) {
    323                 $template = "$parent_dir/$template";
    324                 $template_directory = "$theme_root/$template";
    325             } else {
    326                 /**
    327                  * The parent theme doesn't exist in the current theme's folder or sub folder
    328                  * so lets use the theme root for the parent template.
    329                  */
    330                 if ( isset($theme_files[$template]) && file_exists( $theme_files[$template]['theme_root'] . "/$template/index.php" ) ) {
    331                     $template_directory = $theme_files[$template]['theme_root'] . "/$template";
    332                 } else {
    333                     if ( empty( $parent_template) )
    334                         $wp_broken_themes[$name] = array('Name' => $name, 'Title' => $title, 'Description' => __('Template is missing.'), 'error' => 'no_template');
    335                     else
    336                         $wp_broken_themes[$name] = array('Name' => $name, 'Title' => $title, 'Description' => sprintf( __('The parent theme is missing. Please install the "%s" parent theme.'),  $parent_template ), 'error' => 'no_parent', 'parent' => $parent_template );
    337                     continue;
    338                 }
    339 
    340             }
    341         } else {
    342             $template_directory = trim( $theme_root . '/' . $template );
    343         }
    344 
    345         $stylesheet_files = array();
    346         $template_files = array();
    347 
    348         $stylesheet_dir = @ dir("$theme_root/$stylesheet");
    349         if ( $stylesheet_dir ) {
    350             while ( ($file = $stylesheet_dir->read()) !== false ) {
    351                 if ( !preg_match('|^\.+$|', $file) ) {
    352                     if ( preg_match('|\.css$|', $file) )
    353                         $stylesheet_files[] = "$theme_root/$stylesheet/$file";
    354                     elseif ( preg_match('|\.php$|', $file) )
    355                         $template_files[] = "$theme_root/$stylesheet/$file";
    356                 }
    357             }
    358             @ $stylesheet_dir->close();
    359         }
    360 
    361         $template_dir = @ dir("$template_directory");
    362         if ( $template_dir ) {
    363             while ( ($file = $template_dir->read()) !== false ) {
    364                 if ( preg_match('|^\.+$|', $file) )
    365                     continue;
    366                 if ( preg_match('|\.php$|', $file) ) {
    367                     $template_files[] = "$template_directory/$file";
    368                 } elseif ( is_dir("$template_directory/$file") ) {
    369                     $template_subdir = @ dir("$template_directory/$file");
    370                     if ( !$template_subdir )
    371                         continue;
    372                     while ( ($subfile = $template_subdir->read()) !== false ) {
    373                         if ( preg_match('|^\.+$|', $subfile) )
    374                             continue;
    375                         if ( preg_match('|\.php$|', $subfile) )
    376                             $template_files[] = "$template_directory/$file/$subfile";
    377                     }
    378                     @ $template_subdir->close();
    379                 }
    380             }
    381             @ $template_dir->close();
    382         }
    383 
    384         //Make unique and remove duplicates when stylesheet and template are the same i.e. most themes
    385         $template_files = array_unique($template_files);
    386         $stylesheet_files = array_unique($stylesheet_files);
    387 
    388         $template_dir = $template_directory;
    389         $stylesheet_dir = $theme_root . '/' . $stylesheet;
    390 
    391         if ( empty($template_dir) )
    392             $template_dir = '/';
    393         if ( empty($stylesheet_dir) )
    394             $stylesheet_dir = '/';
    395 
    396         // Check for theme name collision. This occurs if a theme is copied to
    397         // a new theme directory and the theme header is not updated. Whichever
    398         // theme is first keeps the name. Subsequent themes get a suffix applied.
    399         // Default themes themes always trump their pretenders.
    400         if ( isset($wp_themes[$name]) ) {
    401             $trump_cards = array(
    402                 'classic'      => 'WordPress Classic',
    403                 'default'      => 'WordPress Default',
    404                 'twentyten'    => 'Twenty Ten',
    405                 'twentyeleven' => 'Twenty Eleven',
    406                 'twentytwelve' => 'Twenty Twelve',
    407             );
    408             if ( isset( $trump_cards[ $stylesheet ] ) && $name == $trump_cards[ $stylesheet ] ) {
    409                 // If another theme has claimed to be one of our default themes, move
    410                 // them aside.
    411                 $suffix = $wp_themes[$name]['Stylesheet'];
    412                 $new_name = "$name/$suffix";
    413                 $wp_themes[$new_name] = $wp_themes[$name];
    414                 $wp_themes[$new_name]['Name'] = $new_name;
    415             } else {
    416                 $name = "$name/$stylesheet";
    417             }
    418         }
    419 
    420         $wp_themes[$name] = array(
    421             'Name' => $name,
    422             'Title' => $title,
    423             'Description' => $description,
    424             'Author' => $author,
    425             'Author Name' => $theme_data['AuthorName'],
    426             'Author URI' => $theme_data['AuthorURI'],
    427             'Version' => $version,
    428             'Template' => $template,
    429             'Stylesheet' => $stylesheet,
    430             'Template Files' => $template_files,
    431             'Stylesheet Files' => $stylesheet_files,
    432             'Template Dir' => $template_dir,
    433             'Stylesheet Dir' => $stylesheet_dir,
    434             'Status' => $theme_data['Status'],
    435             'Screenshot' => $screenshot,
    436             'Tags' => $theme_data['Tags'],
    437             'Theme Root' => $theme_root,
    438             'Theme Root URI' => str_replace( WP_CONTENT_DIR, content_url(), $theme_root ),
    439         );
    440     }
    441 
    442     unset($theme_files);
    443 
    444     /* Resolve theme dependencies. */
    445     $theme_names = array_keys( $wp_themes );
    446     foreach ( (array) $theme_names as $theme_name ) {
    447         $wp_themes[$theme_name]['Parent Theme'] = '';
    448         if ( $wp_themes[$theme_name]['Stylesheet'] != $wp_themes[$theme_name]['Template'] ) {
    449             foreach ( (array) $theme_names as $parent_theme_name ) {
    450                 if ( ($wp_themes[$parent_theme_name]['Stylesheet'] == $wp_themes[$parent_theme_name]['Template']) && ($wp_themes[$parent_theme_name]['Template'] == $wp_themes[$theme_name]['Template']) ) {
    451                     $wp_themes[$theme_name]['Parent Theme'] = $wp_themes[$parent_theme_name]['Name'];
    452                     break;
    453                 }
    454             }
    455         }
    456     }
    457 
    458     return $wp_themes;
    459 }
    460 
    461 /**
    462339 * Retrieve theme roots.
    463340 *
     
    481358
    482359/**
    483  * Retrieve theme data.
    484  *
    485  * @since 1.5.0
    486  *
    487  * @param string $theme Theme name.
    488  * @return array|null Null, if theme name does not exist. Theme data, if exists.
    489  */
    490 function get_theme($theme) {
    491     $themes = get_themes();
    492 
    493     if ( is_array( $themes ) && array_key_exists( $theme, $themes ) )
    494         return $themes[$theme];
    495 
    496     return null;
    497 }
    498 
    499 /**
    500360 * Retrieve current theme display name.
    501361 *
     
    509369 */
    510370function get_current_theme() {
    511     if ( $theme = get_option('current_theme') )
     371    if ( $theme = get_option( 'current_theme' ) )
    512372        return $theme;
    513373
    514     $themes = get_themes();
    515     $current_theme = 'Twenty Eleven';
    516 
    517     if ( $themes ) {
    518         $theme_names = array_keys( $themes );
    519         $current_template = get_option( 'template' );
    520         $current_stylesheet = get_option( 'stylesheet' );
    521 
    522         foreach ( (array) $theme_names as $theme_name ) {
    523             if ( $themes[$theme_name]['Stylesheet'] == $current_stylesheet &&
    524                     $themes[$theme_name]['Template'] == $current_template ) {
    525                 $current_theme = $themes[$theme_name]['Name'];
    526                 break;
    527             }
    528         }
    529     }
    530 
    531     update_option('current_theme', $current_theme);
    532 
    533     return $current_theme;
     374    return wp_get_theme()->get('Name');
    534375}
    535376
  • trunk/wp-includes/update.php

    r20000 r20029  
    236236        return false;
    237237
    238     if ( !function_exists( 'get_themes' ) )
    239         require_once( ABSPATH . 'wp-includes/theme.php' );
    240 
    241     $installed_themes = get_themes( );
     238    $installed_themes = wp_get_themes();
    242239    $last_update = get_site_transient( 'update_themes' );
    243240    if ( ! is_object($last_update) )
     
    246243    $themes = array();
    247244    $checked = array();
    248     $exclude_fields = array('Template Files', 'Stylesheet Files', 'Status', 'Theme Root', 'Theme Root URI', 'Template Dir', 'Stylesheet Dir', 'Description', 'Tags', 'Screenshot');
    249245
    250246    // Put slug of current theme into request.
    251247    $themes['current_theme'] = get_option( 'stylesheet' );
    252248
    253     foreach ( (array) $installed_themes as $theme_title => $theme ) {
    254         $themes[$theme['Stylesheet']] = array();
    255         $checked[$theme['Stylesheet']] = $theme['Version'];
    256 
    257         $themes[$theme['Stylesheet']]['Name'] = $theme['Name'];
    258         $themes[$theme['Stylesheet']]['Version'] = $theme['Version'];
    259 
    260         foreach ( (array) $theme as $key => $value ) {
    261             if ( !in_array($key, $exclude_fields) )
    262                 $themes[$theme['Stylesheet']][$key] = $value;
    263         }
     249    foreach ( $installed_themes as $theme ) {
     250        $checked[ $theme->get_stylesheet() ] = $theme->get('Version');
     251
     252        $themes[ $theme->get_stylesheet() ] = array(
     253            'Name'       => $theme->get('Name'),
     254            'Title'      => $theme->get('Name'),
     255            'Version'    => $theme->get('Version'),
     256            'Author'     => $theme->get('Author'),
     257            'Author URI' => $theme->get('AuthorURI'),
     258            'Template'   => $theme->get_template(),
     259            'Stylesheet' => $theme->get_stylesheet(),
     260        );
    264261    }
    265262
  • trunk/wp-settings.php

    r20002 r20029  
    113113require( ABSPATH . WPINC . '/query.php' );
    114114require( ABSPATH . WPINC . '/theme.php' );
     115require( ABSPATH . WPINC . '/class-wp-theme.php' );
    115116require( ABSPATH . WPINC . '/template.php' );
    116117require( ABSPATH . WPINC . '/user.php' );
Note: See TracChangeset for help on using the changeset viewer.