3 * WordPress Theme Administration API
6 * @subpackage Administration
10 * {@internal Missing Short Description}}
16 function current_theme_info() {
17 $themes = get_themes();
18 $current_theme = get_current_theme();
19 $ct->name = $current_theme;
20 $ct->title = $themes[$current_theme]['Title'];
21 $ct->version = $themes[$current_theme]['Version'];
22 $ct->parent_theme = $themes[$current_theme]['Parent Theme'];
23 $ct->template_dir = $themes[$current_theme]['Template Dir'];
24 $ct->stylesheet_dir = $themes[$current_theme]['Stylesheet Dir'];
25 $ct->template = $themes[$current_theme]['Template'];
26 $ct->stylesheet = $themes[$current_theme]['Stylesheet'];
27 $ct->screenshot = $themes[$current_theme]['Screenshot'];
28 $ct->description = $themes[$current_theme]['Description'];
29 $ct->author = $themes[$current_theme]['Author'];
30 $ct->tags = $themes[$current_theme]['Tags'];
31 $ct->theme_root = $themes[$current_theme]['Theme Root'];
32 $ct->theme_root_uri = $themes[$current_theme]['Theme Root URI'];
41 * @param string $template Template directory of the theme to delete
44 function delete_theme($template) {
45 global $wp_filesystem;
47 if ( empty($template) )
51 $url = wp_nonce_url('themes.php?action=delete&template=' . $template, 'delete-theme_' . $template);
52 if ( false === ($credentials = request_filesystem_credentials($url)) ) {
53 $data = ob_get_contents();
55 if ( ! empty($data) ){
56 include_once( ABSPATH . 'wp-admin/admin-header.php');
58 include( ABSPATH . 'wp-admin/admin-footer.php');
64 if ( ! WP_Filesystem($credentials) ) {
65 request_filesystem_credentials($url, '', true); // Failed to connect, Error and request again
66 $data = ob_get_contents();
69 include_once( ABSPATH . 'wp-admin/admin-header.php');
71 include( ABSPATH . 'wp-admin/admin-footer.php');
78 if ( ! is_object($wp_filesystem) )
79 return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
81 if ( is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code() )
82 return new WP_Error('fs_error', __('Filesystem error'), $wp_filesystem->errors);
84 //Get the base plugin folder
85 $themes_dir = $wp_filesystem->wp_themes_dir();
86 if ( empty($themes_dir) )
87 return new WP_Error('fs_no_themes_dir', __('Unable to locate WordPress theme directory.'));
89 $themes_dir = trailingslashit( $themes_dir );
93 $theme_dir = trailingslashit($themes_dir . $template);
94 $deleted = $wp_filesystem->delete($theme_dir, true);
97 return new WP_Error('could_not_remove_theme', sprintf(__('Could not fully remove the theme %s'), $template) );
99 // Force refresh of theme update information
100 delete_transient('update_themes');
106 * {@internal Missing Short Description}}
112 function get_broken_themes() {
113 global $wp_broken_themes;
116 return $wp_broken_themes;
120 * Get the Page Templates available in this theme
124 * @return array Key is template name, Value is template name
126 function get_page_templates() {
127 $themes = get_themes();
128 $theme = get_current_theme();
129 $templates = $themes[$theme]['Template Files'];
130 $page_templates = array();
132 if ( is_array( $templates ) ) {
133 $base = array( trailingslashit(get_template_directory()), trailingslashit(get_stylesheet_directory()) );
135 foreach ( $templates as $template ) {
136 $basename = str_replace($base, '', $template);
138 // don't allow template files in subdirectories
139 if ( false !== strpos($basename, '/') )
142 $template_data = implode( '', file( $template ));
145 if ( preg_match( '|Template Name:(.*)$|mi', $template_data, $name ) )
146 $name = _cleanup_header_comment($name[1]);
148 if ( !empty( $name ) ) {
149 $page_templates[trim( $name )] = $basename;
154 return $page_templates;
158 * Tidies a filename for url display by the theme editor.
163 * @param string $fullpath Full path to the theme file
164 * @param string $containingfolder Path of the theme parent folder
167 function _get_template_edit_filename($fullpath, $containingfolder) {
168 return str_replace(dirname(dirname( $containingfolder )) , '', $fullpath);