Make WordPress Core


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/theme.php

    r19251 r21010  
    88
    99/**
    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 }
    48 
    49 /**
    5010 * Remove a theme
    5111 *
    5212 * @since 2.8.0
    5313 *
    54  * @param string $template Template directory of the theme to delete
     14 * @param string $stylesheet Stylesheet of the theme to delete
    5515 * @param string $redirect Redirect to page when complete.
    5616 * @return mixed
    5717 */
    58 function delete_theme($template, $redirect = '') {
     18function delete_theme($stylesheet, $redirect = '') {
    5919        global $wp_filesystem;
    6020
    61         if ( empty($template) )
     21        if ( empty($stylesheet) )
    6222                return false;
    6323
    6424        ob_start();
    6525        if ( empty( $redirect ) )
    66                 $redirect = wp_nonce_url('themes.php?action=delete&template=' . $template, 'delete-theme_' . $template);
     26                $redirect = wp_nonce_url('themes.php?action=delete&stylesheet=' . $stylesheet, 'delete-theme_' . $stylesheet);
    6727        if ( false === ($credentials = request_filesystem_credentials($redirect)) ) {
    6828                $data = ob_get_contents();
    … …  
    9050        }
    9151
    92 
    9352        if ( ! is_object($wp_filesystem) )
    9453                return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
    … …  
    10362
    10463        $themes_dir = trailingslashit( $themes_dir );
    105         $theme_dir = trailingslashit($themes_dir . $template);
     64        $theme_dir = trailingslashit($themes_dir . $stylesheet);
    10665        $deleted = $wp_filesystem->delete($theme_dir, true);
    10766
    10867        if ( ! $deleted )
    109                 return new WP_Error('could_not_remove_theme', sprintf(__('Could not fully remove the theme %s.'), $template) );
     68                return new WP_Error('could_not_remove_theme', sprintf(__('Could not fully remove the theme %s.'), $stylesheet) );
    11069
    11170        // Force refresh of theme update information
    … …  
    11675
    11776/**
    118  * {@internal Missing Short Description}}
     77 * Get the Page Templates available in this theme
    11978 *
    12079 * @since 1.5.0
    12180 *
    122  * @return unknown
    123  */
    124 function get_broken_themes() {
    125         global $wp_broken_themes;
    126 
    127         get_themes();
    128         return $wp_broken_themes;
    129 }
    130 
    131 /**
    132  * Get the allowed themes for the current blog.
    133  *
    134  * @since 3.0.0
    135  *
    136  * @uses get_themes()
    137  * @uses current_theme_info()
    138  * @uses get_site_allowed_themes()
    139  * @uses wpmu_get_blog_allowedthemes
    140  *
    141  * @return array $themes Array of allowed themes.
    142  */
    143 function get_allowed_themes() {
    144         if ( !is_multisite() )
    145                 return get_themes();
    146 
    147         $themes = get_themes();
    148         $ct = current_theme_info();
    149         $allowed_themes = apply_filters("allowed_themes", get_site_allowed_themes() );
    150         if ( $allowed_themes == false )
    151                 $allowed_themes = array();
    152 
    153         $blog_allowed_themes = wpmu_get_blog_allowedthemes();
    154         if ( is_array( $blog_allowed_themes ) )
    155                 $allowed_themes = array_merge( $allowed_themes, $blog_allowed_themes );
    156 
    157         if ( isset( $allowed_themes[ esc_html( $ct->stylesheet ) ] ) == false )
    158                 $allowed_themes[ esc_html( $ct->stylesheet ) ] = true;
    159 
    160         reset( $themes );
    161         foreach ( $themes as $key => $theme ) {
    162                 if ( isset( $allowed_themes[ esc_html( $theme[ 'Stylesheet' ] ) ] ) == false )
    163                         unset( $themes[ $key ] );
    164         }
    165         reset( $themes );
    166 
    167         return $themes;
    168 }
    169 
    170 /**
    171  * Get the Page Templates available in this theme
    172  *
    173  * @since 1.5.0
    174  *
    17581 * @return array Key is the template name, value is the filename of the template
    17682 */
    17783function get_page_templates() {
    178         $themes = get_themes();
    179         $theme = get_current_theme();
    180         $templates = $themes[$theme]['Template Files'];
    181         $page_templates = array();
    182 
    183         if ( is_array( $templates ) ) {
    184                 $base = array( trailingslashit(get_template_directory()), trailingslashit(get_stylesheet_directory()) );
    185 
    186                 foreach ( $templates as $template ) {
    187                         $basename = str_replace($base, '', $template);
    188 
    189                         // don't allow template files in subdirectories
    190                         if ( false !== strpos($basename, '/') )
    191                                 continue;
    192 
    193                         if ( 'functions.php' == $basename )
    194                                 continue;
    195 
    196                         $template_data = implode( '', file( $template ));
    197 
    198                         $name = '';
    199                         if ( preg_match( '|Template Name:(.*)$|mi', $template_data, $name ) )
    200                                 $name = _cleanup_header_comment($name[1]);
    201 
    202                         if ( !empty( $name ) ) {
    203                                 $page_templates[trim( $name )] = $basename;
    204                         }
    205                 }
    206         }
    207 
    208         return $page_templates;
     84        return array_flip( wp_get_theme()->get_page_templates() );
    20985}
    21086
    … …  
    242118                $themes_update = get_site_transient('update_themes');
    243119
    244         if ( is_object($theme) && isset($theme->stylesheet) )
    245                 $stylesheet = $theme->stylesheet;
    246         elseif ( is_array($theme) && isset($theme['Stylesheet']) )
    247                 $stylesheet = $theme['Stylesheet'];
    248         else
    249                 return false; //No valid info passed.
     120        if ( ! is_a( $theme, 'WP_Theme' ) )
     121                return;
     122
     123        $stylesheet = $theme->get_stylesheet();
    250124
    251125        if ( isset($themes_update->response[ $stylesheet ]) ) {
    252126                $update = $themes_update->response[ $stylesheet ];
    253                 $theme_name = is_object($theme) ? $theme->name : (is_array($theme) ? $theme['Name'] : '');
     127                $theme_name = $theme->display('Name');
    254128                $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.
    255129                $update_url = wp_nonce_url('update.php?action=upgrade-theme&theme=' . urlencode($stylesheet), 'upgrade-theme_' . $stylesheet);
    256                 $update_onclick = 'onclick="if ( confirm(\'' . esc_js( __("Updating this theme will lose any customizations you have made.  'Cancel' to stop, 'OK' to update.") ) . '\') ) {return true;}return false;"';
     130                $update_onclick = 'onclick="if ( confirm(\'' . esc_js( __("Updating this theme will lose any customizations you have made. 'Cancel' to stop, 'OK' to update.") ) . '\') ) {return true;}return false;"';
    257131
    258132                if ( !is_multisite() ) {
    … …  
    262136                                printf( '<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s details</a>. <em>Automatic update is unavailable for this theme.</em>') . '</strong></p>', $theme_name, $details_url, $update['new_version']);
    263137                        else
    264                                 printf( '<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s details</a> or <a href="%4$s" %5$s>update automatically</a>.') . '</strong></p>', $theme_name, $details_url, $update['new_version'], $update_url, $update_onclick );
     138                                printf( '<p><strong>' . __('There is a new version of %1$s available. <a href="%2$s" class="thickbox" title="%1$s">View version %3$s details</a> or <a href="%4$s" %5$s>update now</a>.') . '</strong></p>', $theme_name, $details_url, $update['new_version'], $update_url, $update_onclick );
    265139                }
    266140        }
    … …  
    272146 * @since 3.1.0
    273147 *
    274  * @return array  Array of features keyed by category with translations keyed by slug.
    275  */
    276 function get_theme_feature_list() {
     148 * @param bool $api Optional. Whether try to fetch tags from the WP.org API. Defaults to true.
     149 * @return array Array of features keyed by category with translations keyed by slug.
     150 */
     151function get_theme_feature_list( $api = true ) {
    277152        // Hard-coded list is used if api not accessible.
    278153        $features = array(
    … …  
    292167                                'yellow'  => __( 'Yellow' ),
    293168                                'dark'    => __( 'Dark' ),
    294                                 'light'   => __( 'Light ')
     169                                'light'   => __( 'Light' ),
    295170                        ),
    296171
    … …  
    301176                        'four-columns'  => __( 'Four Columns' ),
    302177                        'left-sidebar'  => __( 'Left Sidebar' ),
    303                         'right-sidebar' => __( 'Right Sidebar' )
     178                        'right-sidebar' => __( 'Right Sidebar' ),
    304179                ),
    305180
    306181                __('Width') => array(
    307182                        'fixed-width'    => __( 'Fixed Width' ),
    308                         'flexible-width' => __( 'Flexible Width' )
     183                        'flexible-width' => __( 'Flexible Width' ),
    309184                ),
    310185
    … …  
    327202                        'theme-options'         => __( 'Theme Options' ),
    328203                        'threaded-comments'     => __( 'Threaded Comments' ),
    329                         'translation-ready'     => __( 'Translation Ready' )
     204                        'translation-ready'     => __( 'Translation Ready' ),
    330205                ),
    331206
    … …  
    333208                        'holiday'       => __( 'Holiday' ),
    334209                        'photoblogging' => __( 'Photoblogging' ),
    335                         'seasonal'      => __( 'Seasonal' )
     210                        'seasonal'      => __( 'Seasonal' ),
    336211                )
    337212        );
    338213
    339         if ( !current_user_can('install_themes') )
     214        if ( ! $api || ! current_user_can( 'install_themes' ) )
    340215                return $features;
    341216
    342217        if ( !$feature_list = get_site_transient( 'wporg_theme_feature_list' ) )
    343                 set_site_transient( 'wporg_theme_feature_list', array( ),  10800);
     218                set_site_transient( 'wporg_theme_feature_list', array( ), 10800);
    344219
    345220        if ( !$feature_list ) {
    … …  
    409284                $request = wp_remote_post('http://api.wordpress.org/themes/info/1.0/', array( 'body' => array('action' => $action, 'request' => serialize($args))) );
    410285                if ( is_wp_error($request) ) {
    411                         $res = new WP_Error('themes_api_failed', __('An Unexpected HTTP Error occurred during the API request.'), $request->get_error_message() );
     286                        $res = new WP_Error('themes_api_failed', __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="http://wordpress.org/support/">support forums</a>.' ), $request->get_error_message() );
    412287                } else {
    413                         $res = unserialize( wp_remote_retrieve_body( $request ) );
    414                         if ( ! $res )
    415                         $res = new WP_Error('themes_api_failed', __('An unknown error occurred.'), wp_remote_retrieve_body( $request ) );
    416                 }
    417         }
    418         //var_dump(array($args, $res));
     288                        $res = maybe_unserialize( wp_remote_retrieve_body( $request ) );
     289                        if ( ! is_object( $res ) && ! is_array( $res ) )
     290                                $res = new WP_Error('themes_api_failed', __( 'An unexpected error occurred. Something may be wrong with WordPress.org or this server&#8217;s configuration. If you continue to have problems, please try the <a href="http://wordpress.org/support/">support forums</a>.' ), wp_remote_retrieve_body( $request ) );
     291                }
     292        }
     293
    419294        return apply_filters('themes_api_result', $res, $action, $args);
    420295}
    421 
    422 ?>
Note: See TracChangeset for help on using the changeset viewer.