Changes in trunk/wp-admin/includes/theme.php [19251:21010]
- File:
-
- 1 edited
-
trunk/wp-admin/includes/theme.php (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/theme.php
r19251 r21010 8 8 9 9 /** 10 * {@internal Missing Short Description}}11 *12 * @since 2.0.013 *14 * @return unknown15 */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 /**50 10 * Remove a theme 51 11 * 52 12 * @since 2.8.0 53 13 * 54 * @param string $ template Template directoryof the theme to delete14 * @param string $stylesheet Stylesheet of the theme to delete 55 15 * @param string $redirect Redirect to page when complete. 56 16 * @return mixed 57 17 */ 58 function delete_theme($ template, $redirect = '') {18 function delete_theme($stylesheet, $redirect = '') { 59 19 global $wp_filesystem; 60 20 61 if ( empty($ template) )21 if ( empty($stylesheet) ) 62 22 return false; 63 23 64 24 ob_start(); 65 25 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); 67 27 if ( false === ($credentials = request_filesystem_credentials($redirect)) ) { 68 28 $data = ob_get_contents(); … … 90 50 } 91 51 92 93 52 if ( ! is_object($wp_filesystem) ) 94 53 return new WP_Error('fs_unavailable', __('Could not access filesystem.')); … … 103 62 104 63 $themes_dir = trailingslashit( $themes_dir ); 105 $theme_dir = trailingslashit($themes_dir . $ template);64 $theme_dir = trailingslashit($themes_dir . $stylesheet); 106 65 $deleted = $wp_filesystem->delete($theme_dir, true); 107 66 108 67 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) ); 110 69 111 70 // Force refresh of theme update information … … 116 75 117 76 /** 118 * {@internal Missing Short Description}}77 * Get the Page Templates available in this theme 119 78 * 120 79 * @since 1.5.0 121 80 * 122 * @return unknown123 */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.0135 *136 * @uses get_themes()137 * @uses current_theme_info()138 * @uses get_site_allowed_themes()139 * @uses wpmu_get_blog_allowedthemes140 *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 theme172 *173 * @since 1.5.0174 *175 81 * @return array Key is the template name, value is the filename of the template 176 82 */ 177 83 function 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() ); 209 85 } 210 86 … … 242 118 $themes_update = get_site_transient('update_themes'); 243 119 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(); 250 124 251 125 if ( isset($themes_update->response[ $stylesheet ]) ) { 252 126 $update = $themes_update->response[ $stylesheet ]; 253 $theme_name = is_object($theme) ? $theme->name : (is_array($theme) ? $theme['Name'] : '');127 $theme_name = $theme->display('Name'); 254 128 $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. 255 129 $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;"'; 257 131 258 132 if ( !is_multisite() ) { … … 262 136 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']); 263 137 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 ); 265 139 } 266 140 } … … 272 146 * @since 3.1.0 273 147 * 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 */ 151 function get_theme_feature_list( $api = true ) { 277 152 // Hard-coded list is used if api not accessible. 278 153 $features = array( … … 292 167 'yellow' => __( 'Yellow' ), 293 168 'dark' => __( 'Dark' ), 294 'light' => __( 'Light ')169 'light' => __( 'Light' ), 295 170 ), 296 171 … … 301 176 'four-columns' => __( 'Four Columns' ), 302 177 'left-sidebar' => __( 'Left Sidebar' ), 303 'right-sidebar' => __( 'Right Sidebar' ) 178 'right-sidebar' => __( 'Right Sidebar' ), 304 179 ), 305 180 306 181 __('Width') => array( 307 182 'fixed-width' => __( 'Fixed Width' ), 308 'flexible-width' => __( 'Flexible Width' ) 183 'flexible-width' => __( 'Flexible Width' ), 309 184 ), 310 185 … … 327 202 'theme-options' => __( 'Theme Options' ), 328 203 'threaded-comments' => __( 'Threaded Comments' ), 329 'translation-ready' => __( 'Translation Ready' ) 204 'translation-ready' => __( 'Translation Ready' ), 330 205 ), 331 206 … … 333 208 'holiday' => __( 'Holiday' ), 334 209 'photoblogging' => __( 'Photoblogging' ), 335 'seasonal' => __( 'Seasonal' ) 210 'seasonal' => __( 'Seasonal' ), 336 211 ) 337 212 ); 338 213 339 if ( ! current_user_can('install_themes') )214 if ( ! $api || ! current_user_can( 'install_themes' ) ) 340 215 return $features; 341 216 342 217 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); 344 219 345 220 if ( !$feature_list ) { … … 409 284 $request = wp_remote_post('http://api.wordpress.org/themes/info/1.0/', array( 'body' => array('action' => $action, 'request' => serialize($args))) ); 410 285 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’s configuration. If you continue to have problems, please try the <a href="http://wordpress.org/support/">support forums</a>.' ), $request->get_error_message() ); 412 287 } 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’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 419 294 return apply_filters('themes_api_result', $res, $action, $args); 420 295 } 421 422 ?>
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)