raw
mp-wp_genesis           1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * Edit plugin editor administration panel.
mp-wp_genesis 4 *
mp-wp_genesis 5 * @package WordPress
mp-wp_genesis 6 * @subpackage Administration
mp-wp_genesis 7 */
mp-wp_genesis 8
mp-wp_genesis 9 /** WordPress Administration Bootstrap */
mp-wp_genesis 10 require_once('admin.php');
mp-wp_genesis 11
mp-wp_genesis 12 $title = __("Edit Plugins");
mp-wp_genesis 13 $parent_file = 'plugins.php';
mp-wp_genesis 14
mp-wp_genesis 15 wp_reset_vars(array('action', 'redirect', 'profile', 'error', 'warning', 'a', 'file'));
mp-wp_genesis 16
mp-wp_genesis 17 wp_admin_css( 'theme-editor' );
mp-wp_genesis 18
mp-wp_genesis 19 $plugins = get_plugins();
mp-wp_genesis 20 $plugin_files = array_keys($plugins);
mp-wp_genesis 21
mp-wp_genesis 22 if (empty($file))
mp-wp_genesis 23 $file = $plugin_files[0];
mp-wp_genesis 24
mp-wp_genesis 25 $file = validate_file_to_edit($file, $plugin_files);
mp-wp_genesis 26 $real_file = WP_PLUGIN_DIR . '/' . $file;
mp-wp_genesis 27
mp-wp_genesis 28 switch($action) {
mp-wp_genesis 29
mp-wp_genesis 30 case 'update':
mp-wp_genesis 31
mp-wp_genesis 32 check_admin_referer('edit-plugin_' . $file);
mp-wp_genesis 33
mp-wp_genesis 34 if ( !current_user_can('edit_plugins') )
mp-wp_genesis 35 wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this blog.').'</p>');
mp-wp_genesis 36
mp-wp_genesis 37 $newcontent = stripslashes($_POST['newcontent']);
mp-wp_genesis 38 if ( is_writeable($real_file) ) {
mp-wp_genesis 39 $f = fopen($real_file, 'w+');
mp-wp_genesis 40 fwrite($f, $newcontent);
mp-wp_genesis 41 fclose($f);
mp-wp_genesis 42
mp-wp_genesis 43 // Deactivate so we can test it.
mp-wp_genesis 44 if ( is_plugin_active($file) || isset($_POST['phperror']) ) {
mp-wp_genesis 45 if ( is_plugin_active($file) )
mp-wp_genesis 46 deactivate_plugins($file, true);
mp-wp_genesis 47 wp_redirect(add_query_arg('_wpnonce', wp_create_nonce('edit-plugin-test_' . $file), "plugin-editor.php?file=$file&liveupdate=1"));
mp-wp_genesis 48 exit;
mp-wp_genesis 49 }
mp-wp_genesis 50 wp_redirect("plugin-editor.php?file=$file&a=te");
mp-wp_genesis 51 } else {
mp-wp_genesis 52 wp_redirect("plugin-editor.php?file=$file");
mp-wp_genesis 53 }
mp-wp_genesis 54 exit;
mp-wp_genesis 55
mp-wp_genesis 56 break;
mp-wp_genesis 57
mp-wp_genesis 58 default:
mp-wp_genesis 59
mp-wp_genesis 60 if ( !current_user_can('edit_plugins') )
mp-wp_genesis 61 wp_die('<p>'.__('You do not have sufficient permissions to edit plugins for this blog.').'</p>');
mp-wp_genesis 62
mp-wp_genesis 63 if ( isset($_GET['liveupdate']) ) {
mp-wp_genesis 64 check_admin_referer('edit-plugin-test_' . $file);
mp-wp_genesis 65
mp-wp_genesis 66 $error = validate_plugin($file);
mp-wp_genesis 67 if( is_wp_error($error) )
mp-wp_genesis 68 wp_die( $error );
mp-wp_genesis 69
mp-wp_genesis 70 if ( ! is_plugin_active($file) )
mp-wp_genesis 71 activate_plugin($file, "plugin-editor.php?file=$file&phperror=1");// we'll override this later if the plugin can be included without fatal error
mp-wp_genesis 72
mp-wp_genesis 73 wp_redirect("plugin-editor.php?file=$file&a=te");
mp-wp_genesis 74 exit;
mp-wp_genesis 75 }
mp-wp_genesis 76
mp-wp_genesis 77 require_once('admin-header.php');
mp-wp_genesis 78
mp-wp_genesis 79 update_recently_edited(WP_PLUGIN_DIR . '/' . $file);
mp-wp_genesis 80
mp-wp_genesis 81 if ( ! is_file($real_file) )
mp-wp_genesis 82 $error = 1;
mp-wp_genesis 83
mp-wp_genesis 84 if ( ! $error )
mp-wp_genesis 85 $content = htmlspecialchars(file_get_contents($real_file));
mp-wp_genesis 86
mp-wp_genesis 87 ?>
mp-wp_genesis 88 <?php if (isset($_GET['a'])) : ?>
mp-wp_genesis 89 <div id="message" class="updated fade"><p><?php _e('File edited successfully.') ?></p></div>
mp-wp_genesis 90 <?php elseif (isset($_GET['phperror'])) : ?>
mp-wp_genesis 91 <div id="message" class="updated fade"><p><?php _e('This plugin has been deactivated because your changes resulted in a <strong>fatal error</strong>.') ?></p>
mp-wp_genesis 92 <?php
mp-wp_genesis 93 if ( wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $file) ) { ?>
mp-wp_genesis 94 <iframe style="border:0" width="100%" height="70px" src="<?php bloginfo('wpurl'); ?>/wp-admin/plugins.php?action=error_scrape&amp;plugin=<?php echo attribute_escape($file); ?>&amp;_wpnonce=<?php echo attribute_escape($_GET['_error_nonce']); ?>"></iframe>
mp-wp_genesis 95 <?php } ?>
mp-wp_genesis 96 </div>
mp-wp_genesis 97 <?php endif; ?>
mp-wp_genesis 98 <div class="wrap">
mp-wp_genesis 99 <?php screen_icon(); ?>
mp-wp_genesis 100 <h2><?php echo wp_specialchars( $title ); ?></h2>
mp-wp_genesis 101
mp-wp_genesis 102 <div class="tablenav">
mp-wp_genesis 103 <div class="alignleft">
mp-wp_genesis 104 <big><?php
mp-wp_genesis 105 if ( is_plugin_active($file) ) {
mp-wp_genesis 106 if ( is_writeable($real_file) )
mp-wp_genesis 107 echo sprintf(__('Editing <strong>%s</strong> (active)'), $file);
mp-wp_genesis 108 else
mp-wp_genesis 109 echo sprintf(__('Browsing <strong>%s</strong> (active)'), $file);
mp-wp_genesis 110 } else {
mp-wp_genesis 111 if ( is_writeable($real_file) )
mp-wp_genesis 112 echo sprintf(__('Editing <strong>%s</strong> (inactive)'), $file);
mp-wp_genesis 113 else
mp-wp_genesis 114 echo sprintf(__('Browsing <strong>%s</strong> (inactive)'), $file);
mp-wp_genesis 115 }
mp-wp_genesis 116 ?></big>
mp-wp_genesis 117 </div>
mp-wp_genesis 118 <br class="clear" />
mp-wp_genesis 119 </div>
mp-wp_genesis 120 <br class="clear" />
mp-wp_genesis 121 <div id="templateside">
mp-wp_genesis 122 <h3 id="bordertitle"><?php _e('Plugin Files'); ?></h3>
mp-wp_genesis 123
mp-wp_genesis 124 <h4><?php _e('Plugins'); ?></h4>
mp-wp_genesis 125 <ul>
mp-wp_genesis 126 <?php foreach($plugin_files as $plugin_file) : ?>
mp-wp_genesis 127 <li><a href="plugin-editor.php?file=<?php echo $plugin_file; ?>"><?php echo $plugins[$plugin_file]['Name']; ?></a></li>
mp-wp_genesis 128 <?php endforeach; ?>
mp-wp_genesis 129 </ul>
mp-wp_genesis 130 </div>
mp-wp_genesis 131 <?php if ( ! $error ) { ?>
mp-wp_genesis 132 <form name="template" id="template" action="plugin-editor.php" method="post">
mp-wp_genesis 133 <?php wp_nonce_field('edit-plugin_' . $file) ?>
mp-wp_genesis 134 <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1"><?php echo $content ?></textarea>
mp-wp_genesis 135 <input type="hidden" name="action" value="update" />
mp-wp_genesis 136 <input type="hidden" name="file" value="<?php echo $file ?>" />
mp-wp_genesis 137 </div>
mp-wp_genesis 138 <?php if ( is_writeable($real_file) ) : ?>
mp-wp_genesis 139 <?php if ( in_array($file, (array) get_option('active_plugins')) ) { ?>
mp-wp_genesis 140 <p><?php _e('<strong>Warning:</strong> Making changes to active plugins is not recommended. If your changes cause a fatal error, the plugin will be automatically deactivated.'); ?></p>
mp-wp_genesis 141 <?php } ?>
mp-wp_genesis 142 <p class="submit">
mp-wp_genesis 143 <?php
mp-wp_genesis 144 if ( isset($_GET['phperror']) )
mp-wp_genesis 145 echo "<input type='hidden' name='phperror' value='1' /><input type='submit' name='submit' class='button-primary' value='" . __('Update File and Attempt to Reactivate') . "' tabindex='2' />";
mp-wp_genesis 146 else
mp-wp_genesis 147 echo "<input type='submit' name='submit' class='button-primary' value='" . __('Update File') . "' tabindex='2' />";
mp-wp_genesis 148 ?>
mp-wp_genesis 149 </p>
mp-wp_genesis 150 <?php else : ?>
mp-wp_genesis 151 <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>
mp-wp_genesis 152 <?php endif; ?>
mp-wp_genesis 153 </form>
mp-wp_genesis 154 <?php
mp-wp_genesis 155 } else {
mp-wp_genesis 156 echo '<div class="error"><p>' . __('Oops, no such file exists! Double check the name and try again, merci.') . '</p></div>';
mp-wp_genesis 157 }
mp-wp_genesis 158 ?>
mp-wp_genesis 159 <div class="clear"> &nbsp; </div>
mp-wp_genesis 160 </div>
mp-wp_genesis 161 <?php
mp-wp_genesis 162 break;
mp-wp_genesis 163 }
mp-wp_genesis 164 include("admin-footer.php") ?>