| [ XREF Home ] [ Index ] |
PHP Cross Reference of WordPress TrunkProvided by Yoast |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * WordPress Theme Administration API 4 * 5 * @package WordPress 6 * @subpackage Administration 7 */ 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 if ( ! isset( $themes[$current_theme] ) ) { 20 delete_option( 'current_theme' ); 21 $current_theme = get_current_theme(); 22 } 23 $ct->name = $current_theme; 24 $ct->title = $themes[$current_theme]['Title']; 25 $ct->version = $themes[$current_theme]['Version']; 26 $ct->parent_theme = $themes[$current_theme]['Parent Theme']; 27 $ct->template_dir = $themes[$current_theme]['Template Dir']; 28 $ct->stylesheet_dir = $themes[$current_theme]['Stylesheet Dir']; 29 $ct->template = $themes[$current_theme]['Template']; 30 $ct->stylesheet = $themes[$current_theme]['Stylesheet']; 31 $ct->screenshot = $themes[$current_theme]['Screenshot']; 32 $ct->description = $themes[$current_theme]['Description']; 33 $ct->author = $themes[$current_theme]['Author']; 34 $ct->tags = $themes[$current_theme]['Tags']; 35 $ct->theme_root = $themes[$current_theme]['Theme Root']; 36 $ct->theme_root_uri = $themes[$current_theme]['Theme Root URI']; 37 return $ct; 38 } 39 40 /** 41 * Remove a theme 42 * 43 * @since 2.8.0 44 * 45 * @param string $template Template directory of the theme to delete 46 * @param string $redirect Redirect to page when complete. 47 * @return mixed 48 */ 49 function delete_theme($template, $redirect = '') { 50 global $wp_filesystem; 51 52 if ( empty($template) ) 53 return false; 54 55 ob_start(); 56 if ( empty( $redirect ) ) 57 $redirect = wp_nonce_url('themes.php?action=delete&template=' . $template, 'delete-theme_' . $template); 58 if ( false === ($credentials = request_filesystem_credentials($redirect)) ) { 59 $data = ob_get_contents(); 60 ob_end_clean(); 61 if ( ! empty($data) ){ 62 include_once ( ABSPATH . 'wp-admin/admin-header.php'); 63 echo $data; 64 include ( ABSPATH . 'wp-admin/admin-footer.php'); 65 exit; 66 } 67 return; 68 } 69 70 if ( ! WP_Filesystem($credentials) ) { 71 request_filesystem_credentials($url, '', true); // Failed to connect, Error and request again 72 $data = ob_get_contents(); 73 ob_end_clean(); 74 if ( ! empty($data) ) { 75 include_once ( ABSPATH . 'wp-admin/admin-header.php'); 76 echo $data; 77 include ( ABSPATH . 'wp-admin/admin-footer.php'); 78 exit; 79 } 80 return; 81 } 82 83 84 if ( ! is_object($wp_filesystem) ) 85 return new WP_Error('fs_unavailable', __('Could not access filesystem.')); 86 87 if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() ) 88 return new WP_Error('fs_error', __('Filesystem error.'), $wp_filesystem->errors); 89 90 //Get the base plugin folder 91 $themes_dir = $wp_filesystem->wp_themes_dir(); 92 if ( empty($themes_dir) ) 93 return new WP_Error('fs_no_themes_dir', __('Unable to locate WordPress theme directory.')); 94 95 $themes_dir = trailingslashit( $themes_dir ); 96 $theme_dir = trailingslashit($themes_dir . $template); 97 $deleted = $wp_filesystem->delete($theme_dir, true); 98 99 if ( ! $deleted ) 100 return new WP_Error('could_not_remove_theme', sprintf(__('Could not fully remove the theme %s.'), $template) ); 101 102 // Force refresh of theme update information 103 delete_site_transient('update_themes'); 104 105 return true; 106 } 107 108 /** 109 * {@internal Missing Short Description}} 110 * 111 * @since 1.5.0 112 * 113 * @return unknown 114 */ 115 function get_broken_themes() { 116 global $wp_broken_themes; 117 118 get_themes(); 119 return $wp_broken_themes; 120 } 121 122 /** 123 * Get the allowed themes for the current blog. 124 * 125 * @since 3.0.0 126 * 127 * @uses get_themes() 128 * @uses current_theme_info() 129 * @uses get_site_allowed_themes() 130 * @uses wpmu_get_blog_allowedthemes 131 * 132 * @return array $themes Array of allowed themes. 133 */ 134 function get_allowed_themes() { 135 if ( !is_multisite() ) 136 return get_themes(); 137 138 $themes = get_themes(); 139 $ct = current_theme_info(); 140 $allowed_themes = apply_filters("allowed_themes", get_site_allowed_themes() ); 141 if ( $allowed_themes == false ) 142 $allowed_themes = array(); 143 144 $blog_allowed_themes = wpmu_get_blog_allowedthemes(); 145 if ( is_array( $blog_allowed_themes ) ) 146 $allowed_themes = array_merge( $allowed_themes, $blog_allowed_themes ); 147 148 if ( isset( $allowed_themes[ esc_html( $ct->stylesheet ) ] ) == false ) 149 $allowed_themes[ esc_html( $ct->stylesheet ) ] = true; 150 151 reset( $themes ); 152 foreach ( $themes as $key => $theme ) { 153 if ( isset( $allowed_themes[ esc_html( $theme[ 'Stylesheet' ] ) ] ) == false ) 154 unset( $themes[ $key ] ); 155 } 156 reset( $themes ); 157 158 return $themes; 159 } 160 161 /** 162 * Get the Page Templates available in this theme 163 * 164 * @since 1.5.0 165 * 166 * @return array Key is the template name, value is the filename of the template 167 */ 168 function get_page_templates() { 169 $themes = get_themes(); 170 $theme = get_current_theme(); 171 $templates = $themes[$theme]['Template Files']; 172 $page_templates = array(); 173 174 if ( is_array( $templates ) ) { 175 $base = array( trailingslashit(get_template_directory()), trailingslashit(get_stylesheet_directory()) ); 176 177 foreach ( $templates as $template ) { 178 $basename = str_replace($base, '', $template); 179 180 // don't allow template files in subdirectories 181 if ( false !== strpos($basename, '/') ) 182 continue; 183 184 if ( 'functions.php' == $basename ) 185 continue; 186 187 $template_data = implode( '', file( $template )); 188 189 $name = ''; 190 if ( preg_match( '|Template Name:(.*)$|mi', $template_data, $name ) ) 191 $name = _cleanup_header_comment($name[1]); 192 193 if ( !empty( $name ) ) { 194 $page_templates[trim( $name )] = $basename; 195 } 196 } 197 } 198 199 return $page_templates; 200 } 201 202 /** 203 * Tidies a filename for url display by the theme editor. 204 * 205 * @since 2.9.0 206 * @access private 207 * 208 * @param string $fullpath Full path to the theme file 209 * @param string $containingfolder Path of the theme parent folder 210 * @return string 211 */ 212 function _get_template_edit_filename($fullpath, $containingfolder) { 213 return str_replace(dirname(dirname( $containingfolder )) , '', $fullpath); 214 } 215 216 /** 217 * Check if there is an update for a theme available. 218 * 219 * Will display link, if there is an update available. 220 * 221 * @since 2.7.0 222 * 223 * @param object $theme Theme data object. 224 * @return bool False if no valid info was passed. 225 */ 226 function theme_update_available( $theme ) { 227 static $themes_update; 228 229 if ( !current_user_can('update_themes' ) ) 230 return; 231 232 if ( !isset($themes_update) ) 233 $themes_update = get_site_transient('update_themes'); 234 235 if ( is_object($theme) && isset($theme->stylesheet) ) 236 $stylesheet = $theme->stylesheet; 237 elseif ( is_array($theme) && isset($theme['Stylesheet']) ) 238 $stylesheet = $theme['Stylesheet']; 239 else 240 return false; //No valid info passed. 241 242 if ( isset($themes_update->response[ $stylesheet ]) ) { 243 $update = $themes_update->response[ $stylesheet ]; 244 $theme_name = is_object($theme) ? $theme->name : (is_array($theme) ? $theme['Name'] : ''); 245 $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. 246 $update_url = wp_nonce_url('update.php?action=upgrade-theme&theme=' . urlencode($stylesheet), 'upgrade-theme_' . $stylesheet); 247 $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;"'; 248 249 if ( !is_multisite() ) { 250 if ( ! current_user_can('update_themes') ) 251 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>.') . '</strong></p>', $theme_name, $details_url, $update['new_version']); 252 else if ( empty($update['package']) ) 253 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']); 254 else 255 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 ); 256 } 257 } 258 } 259 260 /** 261 * Retrieve list of WordPress theme features (aka theme tags) 262 * 263 * @since 3.1.0 264 * 265 * @return array Array of features keyed by category with translations keyed by slug. 266 */ 267 function get_theme_feature_list() { 268 // Hard-coded list is used if api not accessible. 269 $features = array( 270 __('Colors') => array( 271 'black' => __( 'Black' ), 272 'blue' => __( 'Blue' ), 273 'brown' => __( 'Brown' ), 274 'green' => __( 'Green' ), 275 'orange' => __( 'Orange' ), 276 'pink' => __( 'Pink' ), 277 'purple' => __( 'Purple' ), 278 'red' => __( 'Red' ), 279 'silver' => __( 'Silver' ), 280 'tan' => __( 'Tan' ), 281 'white' => __( 'White' ), 282 'yellow' => __( 'Yellow' ), 283 'dark' => __( 'Dark' ), 284 'light' => __( 'Light ') 285 ), 286 287 __('Columns') => array( 288 'one-column' => __( 'One Column' ), 289 'two-columns' => __( 'Two Columns' ), 290 'three-columns' => __( 'Three Columns' ), 291 'four-columns' => __( 'Four Columns' ), 292 'left-sidebar' => __( 'Left Sidebar' ), 293 'right-sidebar' => __( 'Right Sidebar' ) 294 ), 295 296 __('Width') => array( 297 'fixed-width' => __( 'Fixed Width' ), 298 'flexible-width' => __( 'Flexible Width' ) 299 ), 300 301 __( 'Features' ) => array( 302 'blavatar' => __( 'Blavatar' ), 303 'buddypress' => __( 'BuddyPress' ), 304 'custom-background' => __( 'Custom Background' ), 305 'custom-colors' => __( 'Custom Colors' ), 306 'custom-header' => __( 'Custom Header' ), 307 'custom-menu' => __( 'Custom Menu' ), 308 'editor-style' => __( 'Editor Style' ), 309 'front-page-post-form' => __( 'Front Page Posting' ), 310 'microformats' => __( 'Microformats' ), 311 'sticky-post' => __( 'Sticky Post' ), 312 'theme-options' => __( 'Theme Options' ), 313 'threaded-comments' => __( 'Threaded Comments' ), 314 'translation-ready' => __( 'Translation Ready' ), 315 'rtl-language-support' => __( 'RTL Language Support' ) 316 ), 317 318 __( 'Subject' ) => array( 319 'holiday' => __( 'Holiday' ), 320 'photoblogging' => __( 'Photoblogging' ), 321 'seasonal' => __( 'Seasonal' ) 322 ) 323 ); 324 325 if ( !current_user_can('install_themes') ) 326 return $features; 327 328 if ( !$feature_list = get_site_transient( 'wporg_theme_feature_list' ) ) 329 set_site_transient( 'wporg_theme_feature_list', array( ), 10800); 330 331 if ( !$feature_list ) { 332 $feature_list = themes_api( 'feature_list', array( ) ); 333 if ( is_wp_error( $feature_list ) ) 334 return $features; 335 } 336 337 if ( !$feature_list ) 338 return $features; 339 340 set_site_transient( 'wporg_theme_feature_list', $feature_list, 10800 ); 341 342 $category_translations = array( 'Colors' => __('Colors'), 'Columns' => __('Columns'), 'Width' => __('Width'), 343 'Features' => __('Features'), 'Subject' => __('Subject') ); 344 345 // Loop over the wporg canonical list and apply translations 346 $wporg_features = array(); 347 foreach ( (array) $feature_list as $feature_category => $feature_items ) { 348 if ( isset($category_translations[$feature_category]) ) 349 $feature_category = $category_translations[$feature_category]; 350 $wporg_features[$feature_category] = array(); 351 352 foreach ( $feature_items as $feature ) { 353 if ( isset($features[$feature_category][$feature]) ) 354 $wporg_features[$feature_category][$feature] = $features[$feature_category][$feature]; 355 else 356 $wporg_features[$feature_category][$feature] = $feature; 357 } 358 } 359 360 return $wporg_features; 361 } 362 363 /** 364 * Retrieve theme installer pages from WordPress Themes API. 365 * 366 * It is possible for a theme to override the Themes API result with three 367 * filters. Assume this is for themes, which can extend on the Theme Info to 368 * offer more choices. This is very powerful and must be used with care, when 369 * overridding the filters. 370 * 371 * The first filter, 'themes_api_args', is for the args and gives the action as 372 * the second parameter. The hook for 'themes_api_args' must ensure that an 373 * object is returned. 374 * 375 * The second filter, 'themes_api', is the result that would be returned. 376 * 377 * @since 2.8.0 378 * 379 * @param string $action 380 * @param array|object $args Optional. Arguments to serialize for the Theme Info API. 381 * @return mixed 382 */ 383 function themes_api($action, $args = null) { 384 385 if ( is_array($args) ) 386 $args = (object)$args; 387 388 if ( !isset($args->per_page) ) 389 $args->per_page = 24; 390 391 $args = apply_filters('themes_api_args', $args, $action); //NOTE: Ensure that an object is returned via this filter. 392 $res = apply_filters('themes_api', false, $action, $args); //NOTE: Allows a theme to completely override the builtin WordPress.org API. 393 394 if ( ! $res ) { 395 $request = wp_remote_post('http://api.wordpress.org/themes/info/1.0/', array( 'body' => array('action' => $action, 'request' => serialize($args))) ); 396 if ( is_wp_error($request) ) { 397 $res = new WP_Error('themes_api_failed', __('An Unexpected HTTP Error occurred during the API request.'), $request->get_error_message() ); 398 } else { 399 $res = unserialize( wp_remote_retrieve_body( $request ) ); 400 if ( ! $res ) 401 $res = new WP_Error('themes_api_failed', __('An unknown error occurred.'), wp_remote_retrieve_body( $request ) ); 402 } 403 } 404 //var_dump(array($args, $res)); 405 return apply_filters('themes_api_result', $res, $action, $args); 406 } 407 408 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jun 1 08:30:02 2011 |
Cross-referenced by PHPXref 0.7 Provided by Yoast and awesome WordPress Hosting |