2 require_once('admin.php');
3 $title = __('Template & File Editing');
4 $parent_file = 'edit.php';
6 wp_reset_vars(array('action', 'redirect', 'profile', 'error', 'warning', 'a', 'file'));
8 $recents = get_option('recently_edited');
18 $file = validate_file_to_edit($file);
19 $real_file = get_real_file_to_edit($file);
25 check_admin_referer('edit-file_' . $file);
27 if ( ! current_user_can('edit_files') )
28 wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this blog.').'</p>');
30 $newcontent = stripslashes($_POST['newcontent']);
31 if (is_writeable($real_file)) {
32 $f = @ fopen($real_file, 'w+');
34 fwrite($f, $newcontent);
36 wp_redirect("templates.php?file=$file&a=te");
38 wp_redirect("templates.php?file=$file&a=err");
41 wp_redirect("templates.php?file=$file&a=err");
50 require_once('./admin-header.php');
52 if ( ! current_user_can('edit_files') )
53 wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this blog.').'</p>');
55 if (strpos($file, 'wp-config.php') !== false)
56 wp_die('<p>'.__('The config file cannot be edited or viewed through the web interface. Sorry!').'</p>');
58 update_recently_edited($file);
60 if (!is_file($real_file))
64 $f = @ fopen($real_file, 'r');
66 if ( filesize($real_file ) > 0 ) {
67 $content = fread($f, filesize($real_file));
68 $content = htmlspecialchars($content);
78 <?php if (isset($_GET['a'])) : ?>
79 <?php if ( 'err' == $_GET['a'] ) : ?>
80 <div id="message" class="error"><p><?php _e('Could not save file.') ?></p></div>
82 <div id="message" class="updated fade"><p><?php _e('File edited successfully.') ?></p></div>
87 if (is_writeable($real_file)) {
88 echo '<h2>' . sprintf(__('Editing <strong>%s</strong>'), wp_specialchars($file) ) . '</h2>';
90 echo '<h2>' . sprintf(__('Browsing <strong>%s</strong>'), wp_specialchars($file) ) . '</h2>';
93 <div id="templateside">
97 <h3><?php _e('Recent'); ?></h3>
100 foreach ($recents as $recent) :
101 echo "<li><a href='templates.php?file=" . attribute_escape($recent) . "'>" . wp_specialchars(get_file_description(basename($recent))) . "</a></li>";
106 <h3><?php _e('Common'); ?></h3>
107 <?php $common_files = array('index.php', '.htaccess', 'my-hacks.php');
108 $old_files = array('wp-layout.css', 'wp-comments.php', 'wp-comments-popup.php');
109 foreach ($old_files as $old_file) {
110 if (file_exists(ABSPATH . $old_file))
111 $common_files[] = $old_file;
114 <?php foreach ($common_files as $common_file) : ?>
115 <li><a href="templates.php?file=<?php echo $common_file?>"><?php echo get_file_description($common_file); ?></a></li>
119 <?php if (!$error) { ?>
120 <form name="template" id="template" action="templates.php" method="post">
121 <?php wp_nonce_field('edit-file_' . $file) ?>
122 <div><textarea cols="70" rows="25" name="newcontent" id='newcontent' tabindex="1"><?php echo $content ?></textarea>
123 <input type="hidden" name="action" value="update" />
124 <input type="hidden" name="file" value="<?php echo $file ?>" />
126 <?php if ( is_writeable($real_file) ) : ?>
129 echo "<input type='submit' name='submit' value=' " . __('Update File »') . "' tabindex='2' />";
133 <p><em><?php _e('If this file were writable you could edit it.'); ?></em></p>
138 echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>';
141 <div class="clear"> </div>
144 <h2><?php _e('Other Files') ?></h2>
146 <p><?php _e('To edit a file, type its name here. You can edit any file <a href="http://codex.wordpress.org/Changing_File_Permissions" title="Read more about making files writable">writable by the server</a>, e.g. CHMOD 666.') ?></p>
147 <form name="file" action="templates.php" method="get">
148 <input type="text" name="file" />
149 <input type="submit" name="submit" value="<?php _e('Edit file »') ?>" />
152 <p><?php _e('Note: of course, you can also edit the files/templates in your text editor of choice and upload them. This online editor is only meant to be used when you don’t have access to a text editor or FTP client.') ?></p>
159 include("admin-footer.php");