2 require_once('admin.php');
4 $title = __("Edit Themes");
5 $parent_file = 'themes.php';
7 wp_reset_vars(array('action', 'redirect', 'profile', 'error', 'warning', 'a', 'file', 'theme'));
9 wp_admin_css( 'theme-editor' );
11 $themes = get_themes();
14 $theme = get_current_theme();
16 $theme = stripslashes($theme);
20 if ( ! isset($themes[$theme]) )
21 wp_die(__('The requested theme does not exist.'));
23 $allowed_files = array_merge($themes[$theme]['Stylesheet Files'], $themes[$theme]['Template Files']);
26 $file = $allowed_files[0];
29 $file = validate_file_to_edit($file, $allowed_files);
30 $real_file = get_real_file_to_edit($file);
32 $file_show = basename( $file );
38 check_admin_referer('edit-theme_' . $file . $theme);
40 if ( !current_user_can('edit_themes') )
41 wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this blog.').'</p>');
43 $newcontent = stripslashes($_POST['newcontent']);
44 $theme = urlencode($theme);
45 if (is_writeable($real_file)) {
46 //is_writable() not always reliable, check return value. see comments @ http://uk.php.net/is_writable
47 $f = fopen($real_file, 'w+');
49 fwrite($f, $newcontent);
51 $location = "theme-editor.php?file=$file&theme=$theme&a=te";
53 $location = "theme-editor.php?file=$file&theme=$theme";
56 $location = "theme-editor.php?file=$file&theme=$theme";
59 $location = wp_kses_no_null($location);
60 $strip = array('%0d', '%0a');
61 $location = str_replace($strip, '', $location);
62 header("Location: $location");
69 if ( !current_user_can('edit_themes') )
70 wp_die('<p>'.__('You do not have sufficient permissions to edit themes for this blog.').'</p>');
72 require_once('admin-header.php');
74 update_recently_edited($file);
76 if (!is_file($real_file))
79 if (!$error && filesize($real_file) > 0) {
80 $f = fopen($real_file, 'r');
81 $content = fread($f, filesize($real_file));
82 $content = htmlspecialchars($content);
86 <?php if (isset($_GET['a'])) : ?>
87 <div id="message" class="updated fade"><p><?php _e('File edited successfully.') ?></p></div>
90 $description = get_file_description($file);
91 $desc_header = ( $description != $file_show ) ? "$description</strong> (%s)" : "%s";
94 <div class="bordertitle">
95 <h2><?php _e('Theme Editor'); ?></h2>
96 <form id="themeselector" name="theme" action="theme-editor.php" method="post">
97 <strong><label for="theme"><?php _e('Select theme to edit:'); ?> </label></strong>
98 <select name="theme" id="theme">
100 foreach ($themes as $a_theme) {
101 $theme_name = $a_theme['Name'];
102 if ($theme_name == $theme) $selected = " selected='selected'";
104 $theme_name = attribute_escape($theme_name);
105 echo "\n\t<option value=\"$theme_name\" $selected>$theme_name</option>";
109 <input type="submit" name="Submit" value="<?php _e('Select') ?>" class="button" />
112 <div class="tablenav">
113 <div class="alignleft">
114 <big><strong><?php echo sprintf($desc_header, $file_show); ?></big>
119 <div id="templateside">
120 <h3 id="bordertitle"><?php _e("Theme Files"); ?></h3>
123 if ($allowed_files) :
125 <h4><?php _e('Templates'); ?></h4>
127 <?php foreach($themes[$theme]['Template Files'] as $template_file) :
128 $description = get_file_description($template_file);
129 $template_show = basename($template_file);
130 $filedesc = ( $description != $template_file ) ? "$description <span class='nonessential'>($template_show)</span>" : "$description";
131 $filedesc = ( $template_file == $file ) ? "<span class='highlight'>$description <span class='nonessential'>($template_show)</span></span>" : $filedesc;
133 <li><a href="theme-editor.php?file=<?php echo "$template_file"; ?>&theme=<?php echo urlencode($theme) ?>"><?php echo $filedesc ?></a></li>
136 <h4><?php echo _c('Styles|Theme stylesheets in theme editor'); ?></h4>
138 <?php foreach($themes[$theme]['Stylesheet Files'] as $style_file) :
139 $description = get_file_description($style_file);
140 $style_show = basename($style_file);
141 $filedesc = ( $description != $style_file ) ? "$description <span class='nonessential'>($style_show)</span>" : "$description";
142 $filedesc = ( $style_file == $file ) ? "<span class='highlight'>$description <span class='nonessential'>($style_show)</span></span>" : $filedesc;
144 <li><a href="theme-editor.php?file=<?php echo "$style_file"; ?>&theme=<?php echo urlencode($theme) ?>"><?php echo $filedesc ?></a></li>
152 <form name="template" id="template" action="theme-editor.php" method="post">
153 <?php wp_nonce_field('edit-theme_' . $file . $theme) ?>
154 <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1"><?php echo $content ?></textarea>
155 <input type="hidden" name="action" value="update" />
156 <input type="hidden" name="file" value="<?php echo $file ?>" />
157 <input type="hidden" name="theme" value="<?php echo $theme ?>" />
161 <?php if ( is_writeable($real_file) ) : ?>
164 echo "<input type='submit' name='submit' value='" . __('Update File') . "' tabindex='2' />";
168 <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>
174 echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>';
177 <div class="clear"> </div>
183 include("admin-footer.php") ?>