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 add_action( 'admin_head', 'theme_editor_css' );
10 function theme_editor_css(){
11 wp_admin_css( 'css/theme-editor' );
14 $themes = get_themes();
17 $theme = get_current_theme();
19 $theme = stripslashes($theme);
23 if ( ! isset($themes[$theme]) )
24 wp_die(__('The requested theme does not exist.'));
26 $allowed_files = array_merge($themes[$theme]['Stylesheet Files'], $themes[$theme]['Template Files']);
29 $file = $allowed_files[0];
32 $file = validate_file_to_edit($file, $allowed_files);
33 $real_file = get_real_file_to_edit($file);
35 $file_show = basename( $file );
41 check_admin_referer('edit-theme_' . $file . $theme);
43 if ( !current_user_can('edit_themes') )
44 wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this blog.').'</p>');
46 $newcontent = stripslashes($_POST['newcontent']);
47 $theme = urlencode($theme);
48 if (is_writeable($real_file)) {
49 $f = fopen($real_file, 'w+');
50 fwrite($f, $newcontent);
52 $location = "theme-editor.php?file=$file&theme=$theme&a=te";
54 $location = "theme-editor.php?file=$file&theme=$theme";
57 $location = wp_kses_no_null($location);
58 $strip = array('%0d', '%0a');
59 $location = str_replace($strip, '', $location);
60 header("Location: $location");
67 if ( !current_user_can('edit_themes') )
68 wp_die('<p>'.__('You do not have sufficient permissions to edit themes for this blog.').'</p>');
70 require_once('admin-header.php');
72 update_recently_edited($file);
74 if (!is_file($real_file))
77 if (!$error && filesize($real_file) > 0) {
78 $f = fopen($real_file, 'r');
79 $content = fread($f, filesize($real_file));
80 $content = htmlspecialchars($content);
84 <?php if (isset($_GET['a'])) : ?>
85 <div id="message" class="updated fade"><p><?php _e('File edited successfully.') ?></p></div>
88 $description = get_file_description($file);
89 $desc_header = ( $description != $file_show ) ? "$description</strong> (%s)" : "%s";
92 <div class="bordertitle">
93 <h2><?php _e('Theme Editor'); ?></h2>
94 <form id="themeselector" name="theme" action="theme-editor.php" method="post">
95 <strong><?php _e('Select theme to edit:'); ?> </strong>
96 <select name="theme" id="theme">
98 foreach ($themes as $a_theme) {
99 $theme_name = $a_theme['Name'];
100 if ($theme_name == $theme) $selected = " selected='selected'";
102 $theme_name = attribute_escape($theme_name);
103 echo "\n\t<option value=\"$theme_name\" $selected>$theme_name</option>";
107 <input type="submit" name="Submit" value="<?php _e('Select') ?>" class="button" />
110 <div class="tablenav">
111 <div class="alignleft">
112 <big><strong><?php echo sprintf($desc_header, $file_show); ?></big>
117 <div id="templateside">
118 <h3 id="bordertitle"><?php _e("Theme Files"); ?></h3>
121 if ($allowed_files) :
123 <h4><?php _e('Templates'); ?></h4>
125 <?php foreach($themes[$theme]['Template Files'] as $template_file) :
126 $description = get_file_description($template_file);
127 $template_show = basename($template_file);
128 $filedesc = ( $description != $template_file ) ? "$description <span class='nonessential'>($template_show)</span>" : "$description";
129 $filedesc = ( $template_file == $file ) ? "<span class='highlight'>$description <span class='nonessential'>($template_show)</span></span>" : $filedesc;
131 <li><a href="theme-editor.php?file=<?php echo "$template_file"; ?>&theme=<?php echo urlencode($theme) ?>"><?php echo $filedesc ?></a></li>
134 <h4><?php echo _c('Styles|Theme stylesheets in theme editor'); ?></h4>
136 <?php foreach($themes[$theme]['Stylesheet Files'] as $style_file) :
137 $description = get_file_description($style_file);
138 $style_show = basename($style_file);
139 $filedesc = ( $description != $style_file ) ? "$description <span class='nonessential'>($style_show)</span>" : "$description";
140 $filedesc = ( $style_file == $file ) ? "<span class='highlight'>$description <span class='nonessential'>($style_show)</span></span>" : $filedesc;
142 <li><a href="theme-editor.php?file=<?php echo "$style_file"; ?>&theme=<?php echo urlencode($theme) ?>"><?php echo $filedesc ?></a></li>
150 <form name="template" id="template" action="theme-editor.php" method="post">
151 <?php wp_nonce_field('edit-theme_' . $file . $theme) ?>
152 <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1"><?php echo $content ?></textarea>
153 <input type="hidden" name="action" value="update" />
154 <input type="hidden" name="file" value="<?php echo $file ?>" />
155 <input type="hidden" name="theme" value="<?php echo $theme ?>" />
159 <?php if ( is_writeable($real_file) ) : ?>
162 echo "<input type='submit' name='submit' value='" . __('Update File') . "' tabindex='2' />";
166 <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>
172 echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>';
175 <div class="clear"> </div>
181 include("admin-footer.php") ?>