3 * Theme editor administration panel.
6 * @subpackage Administration
9 /** WordPress Administration Bootstrap */
10 require_once('admin.php');
12 $title = __("Edit Themes");
13 $parent_file = 'themes.php';
15 wp_reset_vars(array('action', 'redirect', 'profile', 'error', 'warning', 'a', 'file', 'theme'));
17 wp_admin_css( 'theme-editor' );
19 $themes = get_themes();
22 $theme = get_current_theme();
24 $theme = stripslashes($theme);
28 if ( ! isset($themes[$theme]) )
29 wp_die(__('The requested theme does not exist.'));
31 $allowed_files = array_merge($themes[$theme]['Stylesheet Files'], $themes[$theme]['Template Files']);
34 $file = $allowed_files[0];
37 $file = validate_file_to_edit($file, $allowed_files);
38 $real_file = get_real_file_to_edit($file);
40 $file_show = basename( $file );
46 check_admin_referer('edit-theme_' . $file . $theme);
48 if ( !current_user_can('edit_themes') )
49 wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this blog.').'</p>');
51 $newcontent = stripslashes($_POST['newcontent']);
52 $theme = urlencode($theme);
53 if (is_writeable($real_file)) {
54 //is_writable() not always reliable, check return value. see comments @ http://uk.php.net/is_writable
55 $f = fopen($real_file, 'w+');
57 fwrite($f, $newcontent);
59 $location = "theme-editor.php?file=$file&theme=$theme&a=te";
61 $location = "theme-editor.php?file=$file&theme=$theme";
64 $location = "theme-editor.php?file=$file&theme=$theme";
67 $location = wp_kses_no_null($location);
68 $strip = array('%0d', '%0a');
69 $location = str_replace($strip, '', $location);
70 header("Location: $location");
77 if ( !current_user_can('edit_themes') )
78 wp_die('<p>'.__('You do not have sufficient permissions to edit themes for this blog.').'</p>');
80 require_once('admin-header.php');
82 update_recently_edited($file);
84 if (!is_file($real_file))
87 if (!$error && filesize($real_file) > 0) {
88 $f = fopen($real_file, 'r');
89 $content = fread($f, filesize($real_file));
90 $content = htmlspecialchars($content);
94 <?php if (isset($_GET['a'])) : ?>
95 <div id="message" class="updated fade"><p><?php _e('File edited successfully.') ?></p></div>
98 $description = get_file_description($file);
99 $desc_header = ( $description != $file_show ) ? "<strong>$description</strong> (%s)" : "%s";
102 <?php screen_icon(); ?>
103 <h2><?php echo wp_specialchars( $title ); ?></h2>
104 <div class="bordertitle">
105 <form id="themeselector" action="theme-editor.php" method="post">
106 <strong><label for="theme"><?php _e('Select theme to edit:'); ?> </label></strong>
107 <select name="theme" id="theme">
109 foreach ($themes as $a_theme) {
110 $theme_name = $a_theme['Name'];
111 if ($theme_name == $theme) $selected = " selected='selected'";
113 $theme_name = attribute_escape($theme_name);
114 echo "\n\t<option value=\"$theme_name\" $selected>$theme_name</option>";
118 <input type="submit" name="Submit" value="<?php _e('Select') ?>" class="button" />
121 <div class="tablenav">
122 <div class="alignleft">
123 <big><?php echo sprintf($desc_header, $file_show); ?></big>
128 <div id="templateside">
129 <h3 id="bordertitle"><?php _e("Theme Files"); ?></h3>
132 if ($allowed_files) :
134 <h4><?php _e('Templates'); ?></h4>
137 $template_mapping = array();
138 $template_dir = $themes[$theme]['Template Dir'];
139 foreach($themes[$theme]['Template Files'] as $template_file) {
140 $description = trim( get_file_description($template_file) );
141 $template_show = basename($template_file);
142 $filedesc = ( $description != $template_file ) ? "$description <span class='nonessential'>($template_show)</span>" : "$description";
143 $filedesc = ( $template_file == $file ) ? "<span class='highlight'>$description <span class='nonessential'>($template_show)</span></span>" : $filedesc;
145 // If we have two files of the same name prefer the one in the Template Directory
146 // This means that we display the correct files for child themes which overload Templates as well as Styles
147 if( array_key_exists($description, $template_mapping ) ) {
148 if ( false !== strpos( $template_file, $template_dir ) ) {
149 $template_mapping[ $description ] = array( $template_file, $filedesc );
152 $template_mapping[ $description ] = array( $template_file, $filedesc );
155 ksort( $template_mapping );
156 while ( list( $template_sorted_key, list( $template_file, $filedesc ) ) = each( $template_mapping ) ) :
158 <li><a href="theme-editor.php?file=<?php echo "$template_file"; ?>&theme=<?php echo urlencode($theme) ?>"><?php echo $filedesc ?></a></li>
161 <h4><?php echo _c('Styles|Theme stylesheets in theme editor'); ?></h4>
164 $template_mapping = array();
165 foreach($themes[$theme]['Stylesheet Files'] as $style_file) {
166 $description = trim( get_file_description($style_file) );
167 $style_show = basename($style_file);
168 $filedesc = ( $description != $style_file ) ? "$description <span class='nonessential'>($style_show)</span>" : "$description";
169 $filedesc = ( $style_file == $file ) ? "<span class='highlight'>$description <span class='nonessential'>($style_show)</span></span>" : $filedesc;
170 $template_mapping[ $description ] = array( $style_file, $filedesc );
172 ksort( $template_mapping );
173 while ( list( $template_sorted_key, list( $style_file, $filedesc ) ) = each( $template_mapping ) ) :
175 <li><a href="theme-editor.php?file=<?php echo "$style_file"; ?>&theme=<?php echo urlencode($theme) ?>"><?php echo $filedesc ?></a></li>
183 <form name="template" id="template" action="theme-editor.php" method="post">
184 <?php wp_nonce_field('edit-theme_' . $file . $theme) ?>
185 <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1"><?php echo $content ?></textarea>
186 <input type="hidden" name="action" value="update" />
187 <input type="hidden" name="file" value="<?php echo $file ?>" />
188 <input type="hidden" name="theme" value="<?php echo $theme ?>" />
192 <?php if ( is_writeable($real_file) ) : ?>
195 echo "<input type='submit' name='submit' class='button-primary' value='" . __('Update File') . "' tabindex='2' />";
199 <p><em><?php _e('You need to make this file writable before you can save your changes. See <a href="http://codex.wordpress.org/Changing_File_Permissions">the Codex</a> for more information.'); ?></em></p>
205 echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>';
208 <div class="clear"> </div>
214 include("admin-footer.php") ?>