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 $themes = get_themes();
12 $theme = get_current_theme();
14 $theme = stripslashes($theme);
18 if ( ! isset($themes[$theme]) )
19 wp_die(__('The requested theme does not exist.'));
21 $allowed_files = array_merge($themes[$theme]['Stylesheet Files'], $themes[$theme]['Template Files']);
24 $file = $allowed_files[0];
27 $file = validate_file_to_edit($file, $allowed_files);
28 $real_file = get_real_file_to_edit($file);
30 $file_show = basename( $file );
36 check_admin_referer('edit-theme_' . $file . $theme);
38 if ( !current_user_can('edit_themes') )
39 wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this blog.').'</p>');
41 $newcontent = stripslashes($_POST['newcontent']);
42 $theme = urlencode($theme);
43 if (is_writeable($real_file)) {
44 $f = fopen($real_file, 'w+');
45 fwrite($f, $newcontent);
47 $location = "theme-editor.php?file=$file&theme=$theme&a=te";
49 $location = "theme-editor.php?file=$file&theme=$theme";
52 $location = wp_kses_no_null($location);
53 $strip = array('%0d', '%0a');
54 $location = str_replace($strip, '', $location);
55 header("Location: $location");
62 if ( !current_user_can('edit_themes') )
63 wp_die('<p>'.__('You do not have sufficient permissions to edit themes for this blog.').'</p>');
65 require_once('admin-header.php');
67 update_recently_edited($file);
69 if (!is_file($real_file))
72 if (!$error && filesize($real_file) > 0) {
73 $f = fopen($real_file, 'r');
74 $content = fread($f, filesize($real_file));
75 $content = htmlspecialchars($content);
79 <?php if (isset($_GET['a'])) : ?>
80 <div id="message" class="updated fade"><p><?php _e('File edited successfully.') ?></p></div>
83 <form name="theme" action="theme-editor.php" method="post">
84 <?php _e('Select theme to edit:') ?>
85 <select name="theme" id="theme">
87 foreach ($themes as $a_theme) {
88 $theme_name = $a_theme['Name'];
89 if ($theme_name == $theme) $selected = " selected='selected'";
91 $theme_name = attribute_escape($theme_name);
92 echo "\n\t<option value=\"$theme_name\" $selected>$theme_name</option>";
96 <input type="submit" name="Submit" value="<?php _e('Select »') ?>" class="button" />
102 if ( is_writeable($real_file) ) {
103 echo '<h2>' . sprintf(__('Editing <code>%s</code>'), $file_show) . '</h2>';
105 echo '<h2>' . sprintf(__('Browsing <code>%s</code>'), $file_show) . '</h2>';
108 <div id="templateside">
109 <h3><?php printf(__("<strong>'%s'</strong> theme files"), $theme) ?></h3>
112 if ($allowed_files) :
115 <?php foreach($allowed_files as $allowed_file) : ?>
116 <li><a href="theme-editor.php?file=<?php echo "$allowed_file"; ?>&theme=<?php echo urlencode($theme) ?>"><?php echo get_file_description($allowed_file); ?></a></li>
124 <form name="template" id="template" action="theme-editor.php" method="post">
125 <?php wp_nonce_field('edit-theme_' . $file . $theme) ?>
126 <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1"><?php echo $content ?></textarea>
127 <input type="hidden" name="action" value="update" />
128 <input type="hidden" name="file" value="<?php echo $file ?>" />
129 <input type="hidden" name="theme" value="<?php echo $theme ?>" />
131 <?php if ( is_writeable($real_file) ) : ?>
134 echo "<input type='submit' name='submit' value=' " . __('Update File »') . "' tabindex='2' />";
138 <p><em><?php _e('If this file were writable you could edit it.'); ?></em></p>
143 echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>';
146 <div class="clear"> </div>
152 include("admin-footer.php") ?>