136
|
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 unknown |
|
13 |
* |
|
14 |
* @return unknown |
|
15 |
*/ |
|
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']; |
|
33 |
return $ct; |
|
34 |
} |
|
35 |
|
|
36 |
/** |
|
37 |
* Remove a theme |
|
38 |
* |
|
39 |
* @since 2.8.0 |
|
40 |
* |
|
41 |
* @param string $template Template directory of the theme to delete |
|
42 |
* @return mixed |
|
43 |
*/ |
|
44 |
function delete_theme($template) { |
|
45 |
global $wp_filesystem; |
|
46 |
|
|
47 |
if ( empty($template) ) |
|
48 |
return false; |
|
49 |
|
|
50 |
ob_start(); |
|
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(); |
|
54 |
ob_end_clean(); |
|
55 |
if ( ! empty($data) ){ |
|
56 |
include_once( ABSPATH . 'wp-admin/admin-header.php'); |
|
57 |
echo $data; |
|
58 |
include( ABSPATH . 'wp-admin/admin-footer.php'); |
|
59 |
exit; |
|
60 |
} |
|
61 |
return; |
|
62 |
} |
|
63 |
|
|
64 |
if ( ! WP_Filesystem($credentials) ) { |
|
65 |
request_filesystem_credentials($url, '', true); // Failed to connect, Error and request again |
|
66 |
$data = ob_get_contents(); |
|
67 |
ob_end_clean(); |
|
68 |
if( ! empty($data) ){ |
|
69 |
include_once( ABSPATH . 'wp-admin/admin-header.php'); |
|
70 |
echo $data; |
|
71 |
include( ABSPATH . 'wp-admin/admin-footer.php'); |
|
72 |
exit; |
|
73 |
} |
|
74 |
return; |
|
75 |
} |
|
76 |
|
|
77 |
|
|
78 |
if ( ! is_object($wp_filesystem) ) |
|
79 |
return new WP_Error('fs_unavailable', __('Could not access filesystem.')); |
|
80 |
|
|
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); |
|
83 |
|
|
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.')); |
|
88 |
|
|
89 |
$themes_dir = trailingslashit( $themes_dir ); |
|
90 |
|
|
91 |
$errors = array(); |
|
92 |
|
|
93 |
$theme_dir = trailingslashit($themes_dir . $template); |
|
94 |
$deleted = $wp_filesystem->delete($theme_dir, true); |
|
95 |
|
|
96 |
if ( ! $deleted ) |
|
97 |
return new WP_Error('could_not_remove_theme', sprintf(__('Could not fully remove the theme %s'), $template) ); |
|
98 |
|
|
99 |
// Force refresh of theme update information |
|
100 |
delete_transient('update_themes'); |
|
101 |
|
|
102 |
return true; |
|
103 |
} |
|
104 |
|
|
105 |
/** |
|
106 |
* {@internal Missing Short Description}} |
|
107 |
* |
|
108 |
* @since unknown |
|
109 |
* |
|
110 |
* @return unknown |
|
111 |
*/ |
|
112 |
function get_broken_themes() { |
|
113 |
global $wp_broken_themes; |
|
114 |
|
|
115 |
get_themes(); |
|
116 |
return $wp_broken_themes; |
|
117 |
} |
|
118 |
|
|
119 |
/** |
|
120 |
* Get the Page Templates available in this theme |
|
121 |
* |
|
122 |
* @since unknown |
|
123 |
* |
|
124 |
* @return array Key is template name, Value is template name |
|
125 |
*/ |
|
126 |
function get_page_templates() { |
|
127 |
$themes = get_themes(); |
|
128 |
$theme = get_current_theme(); |
|
129 |
$templates = $themes[$theme]['Template Files']; |
|
130 |
$page_templates = array(); |
|
131 |
|
|
132 |
if ( is_array( $templates ) ) { |
|
133 |
$base = array( trailingslashit(get_template_directory()), trailingslashit(get_stylesheet_directory()) ); |
|
134 |
|
|
135 |
foreach ( $templates as $template ) { |
|
136 |
$basename = str_replace($base, '', $template); |
|
137 |
|
|
138 |
// don't allow template files in subdirectories |
|
139 |
if ( false !== strpos($basename, '/') ) |
|
140 |
continue; |
|
141 |
|
|
142 |
$template_data = implode( '', file( $template )); |
|
143 |
|
|
144 |
$name = ''; |
|
145 |
if ( preg_match( '|Template Name:(.*)$|mi', $template_data, $name ) ) |
|
146 |
$name = _cleanup_header_comment($name[1]); |
|
147 |
|
|
148 |
if ( !empty( $name ) ) { |
|
149 |
$page_templates[trim( $name )] = $basename; |
|
150 |
} |
|
151 |
} |
|
152 |
} |
|
153 |
|
|
154 |
return $page_templates; |
|
155 |
} |
|
156 |
|
|
157 |
/** |
|
158 |
* Tidies a filename for url display by the theme editor. |
|
159 |
* |
|
160 |
* @since 2.9.0 |
|
161 |
* @private |
|
162 |
* |
|
163 |
* @param string $fullpath Full path to the theme file |
|
164 |
* @param string $containingfolder Path of the theme parent folder |
|
165 |
* @return string |
|
166 |
*/ |
|
167 |
function _get_template_edit_filename($fullpath, $containingfolder) { |
|
168 |
return str_replace(dirname(dirname( $containingfolder )) , '', $fullpath); |
|
169 |
} |
|
170 |
|
|
171 |
?> |