| [ Root ] [ Search ] [ Index ] |
PHP Cross Reference of WordPress 3.0.1Provided by Yoast |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Edit plugin editor administration panel. 4 * 5 * @package WordPress 6 * @subpackage Administration 7 */ 8 9 /** WordPress Administration Bootstrap */ 10 require_once ('./admin.php'); 11 12 if ( !current_user_can('edit_plugins') ) 13 wp_die( __('You do not have sufficient permissions to edit plugins for this site.') ); 14 15 $title = __("Edit Plugins"); 16 $parent_file = 'plugins.php'; 17 18 wp_reset_vars(array('action', 'redirect', 'profile', 'error', 'warning', 'a', 'file', 'plugin')); 19 20 wp_admin_css( 'theme-editor' ); 21 22 $plugins = get_plugins(); 23 24 if ( empty($plugins) ) 25 wp_die( __('There are no plugins installed on this site.') ); 26 27 if ( isset($_REQUEST['file']) ) 28 $plugin = stripslashes($_REQUEST['file']); 29 30 if ( empty($plugin) ) { 31 $plugin = array_keys($plugins); 32 $plugin = $plugin[0]; 33 } 34 35 $plugin_files = get_plugin_files($plugin); 36 37 if ( empty($file) ) 38 $file = $plugin_files[0]; 39 else 40 $file = stripslashes($file); 41 42 $file = validate_file_to_edit($file, $plugin_files); 43 $real_file = WP_PLUGIN_DIR . '/' . $file; 44 $scrollto = isset($_REQUEST['scrollto']) ? (int) $_REQUEST['scrollto'] : 0; 45 46 switch ( $action ) { 47 48 case 'update': 49 50 check_admin_referer('edit-plugin_' . $file); 51 52 $newcontent = stripslashes($_POST['newcontent']); 53 if ( is_writeable($real_file) ) { 54 $f = fopen($real_file, 'w+'); 55 fwrite($f, $newcontent); 56 fclose($f); 57 58 $network_wide = is_plugin_active_for_network( $file ); 59 60 // Deactivate so we can test it. 61 if ( is_plugin_active($file) || isset($_POST['phperror']) ) { 62 if ( is_plugin_active($file) ) 63 deactivate_plugins($file, true); 64 65 update_option('recently_activated', array($file => time()) + (array)get_option('recently_activated')); 66 67 wp_redirect(add_query_arg('_wpnonce', wp_create_nonce('edit-plugin-test_' . $file), "plugin-editor.php?file=$file&liveupdate=1&scrollto=$scrollto&networkwide=" . $network_wide)); 68 exit; 69 } 70 wp_redirect("plugin-editor.php?file=$file&a=te&scrollto=$scrollto"); 71 } else { 72 wp_redirect("plugin-editor.php?file=$file&scrollto=$scrollto"); 73 } 74 exit; 75 76 break; 77 78 default: 79 80 if ( isset($_GET['liveupdate']) ) { 81 check_admin_referer('edit-plugin-test_' . $file); 82 83 $error = validate_plugin($file); 84 if ( is_wp_error($error) ) 85 wp_die( $error ); 86 87 if ( ! is_plugin_active($file) ) 88 activate_plugin($file, "plugin-editor.php?file=$file&phperror=1", ! empty( $_GET['networkwide'] ) ); // we'll override this later if the plugin can be included without fatal error 89 90 wp_redirect("plugin-editor.php?file=$file&a=te&scrollto=$scrollto"); 91 exit; 92 } 93 94 // List of allowable extensions 95 $editable_extensions = array('php', 'txt', 'text', 'js', 'css', 'html', 'htm', 'xml', 'inc', 'include'); 96 $editable_extensions = (array) apply_filters('editable_extensions', $editable_extensions); 97 98 if ( ! is_file($real_file) ) { 99 wp_die(sprintf('<p>%s</p>', __('No such file exists! Double check the name and try again.'))); 100 } else { 101 // Get the extension of the file 102 if ( preg_match('/\.([^.]+)$/', $real_file, $matches) ) { 103 $ext = strtolower($matches[1]); 104 // If extension is not in the acceptable list, skip it 105 if ( !in_array( $ext, $editable_extensions) ) 106 wp_die(sprintf('<p>%s</p>', __('Files of this type are not editable.'))); 107 } 108 } 109 110 add_contextual_help($current_screen, 111 '<p>' . __('You can use the editor to make changes to any of your plugins’ individual PHP files. Be aware that if you make changes, plugins updates will overwrite your customizations.') . '</p>' . 112 '<p>' . __('Choose a plugin to edit from the menu in the upper right and click the Select button. Click once on any file name to load it in the editor, and make your changes. Don’t forget to save your changes (Update File) when you’re finished.') . '</p>' . 113 '<p>' . __('The Documentation menu below the editor lists the PHP functions recognized in the plugin file. Clicking Lookup takes you to a web page about that particular function.') . '</p>' . 114 '<p>' . __('If you want to make changes but don’t want them to be overwritten when the plugin is updated, you may be ready to think about writing your own plugin. For information on how to edit a plugin or start from scratch, check out the links below.') . '</p>' . 115 '<p><strong>' . __('For more information:') . '</strong></p>' . 116 '<p>' . __('<a href="http://codex.wordpress.org/Plugins_Editor_SubPanel" target="_blank">Documentation on Editing Plugins</a>') . '</p>' . 117 '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>' 118 ); 119 120 require_once ('./admin-header.php'); 121 122 update_recently_edited(WP_PLUGIN_DIR . '/' . $file); 123 124 $content = file_get_contents( $real_file ); 125 126 if ( '.php' == substr( $real_file, strrpos( $real_file, '.' ) ) ) { 127 $functions = wp_doc_link_parse( $content ); 128 129 if ( !empty($functions) ) { 130 $docs_select = '<select name="docs-list" id="docs-list">'; 131 $docs_select .= '<option value="">' . __( 'Function Name…' ) . '</option>'; 132 foreach ( $functions as $function) { 133 $docs_select .= '<option value="' . esc_attr( $function ) . '">' . esc_html( $function ) . '()</option>'; 134 } 135 $docs_select .= '</select>'; 136 } 137 } 138 139 $content = htmlspecialchars( $content ); 140 ?> 141 <?php if (isset($_GET['a'])) : ?> 142 <div id="message" class="updated"><p><?php _e('File edited successfully.') ?></p></div> 143 <?php elseif (isset($_GET['phperror'])) : ?> 144 <div id="message" class="updated"><p><?php _e('This plugin has been deactivated because your changes resulted in a <strong>fatal error</strong>.') ?></p> 145 <?php 146 if ( wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $file) ) { ?> 147 <iframe style="border:0" width="100%" height="70px" src="<?php bloginfo('wpurl'); ?>/wp-admin/plugins.php?action=error_scrape&plugin=<?php echo esc_attr($file); ?>&_wpnonce=<?php echo esc_attr($_GET['_error_nonce']); ?>"></iframe> 148 <?php } ?> 149 </div> 150 <?php endif; ?> 151 <div class="wrap"> 152 <?php screen_icon(); ?> 153 <h2><?php echo esc_html( $title ); ?></h2> 154 155 <div class="fileedit-sub"> 156 <div class="alignleft"> 157 <big><?php 158 if ( is_plugin_active($plugin) ) { 159 if ( is_writeable($real_file) ) 160 echo sprintf(__('Editing <strong>%s</strong> (active)'), $file); 161 else 162 echo sprintf(__('Browsing <strong>%s</strong> (active)'), $file); 163 } else { 164 if ( is_writeable($real_file) ) 165 echo sprintf(__('Editing <strong>%s</strong> (inactive)'), $file); 166 else 167 echo sprintf(__('Browsing <strong>%s</strong> (inactive)'), $file); 168 } 169 ?></big> 170 </div> 171 <div class="alignright"> 172 <form action="plugin-editor.php" method="post"> 173 <strong><label for="plugin"><?php _e('Select plugin to edit:'); ?> </label></strong> 174 <select name="plugin" id="plugin"> 175 <?php 176 foreach ( $plugins as $plugin_key => $a_plugin ) { 177 $plugin_name = $a_plugin['Name']; 178 if ( $plugin_key == $plugin ) 179 $selected = " selected='selected'"; 180 else 181 $selected = ''; 182 $plugin_name = esc_attr($plugin_name); 183 $plugin_key = esc_attr($plugin_key); 184 echo "\n\t<option value=\"$plugin_key\" $selected>$plugin_name</option>"; 185 } 186 ?> 187 </select> 188 <input type="submit" name="Submit" value="<?php esc_attr_e('Select') ?>" class="button" /> 189 </form> 190 </div> 191 <br class="clear" /> 192 </div> 193 194 <div id="templateside"> 195 <h3><?php _e('Plugin Files'); ?></h3> 196 197 <ul> 198 <?php 199 foreach ( $plugin_files as $plugin_file ) : 200 // Get the extension of the file 201 if ( preg_match('/\.([^.]+)$/', $plugin_file, $matches) ) { 202 $ext = strtolower($matches[1]); 203 // If extension is not in the acceptable list, skip it 204 if ( !in_array( $ext, $editable_extensions ) ) 205 continue; 206 } else { 207 // No extension found 208 continue; 209 } 210 ?> 211 <li<?php echo $file == $plugin_file ? ' class="highlight"' : ''; ?>><a href="plugin-editor.php?file=<?php echo $plugin_file; ?>&plugin=<?php echo $plugin; ?>"><?php echo $plugin_file ?></a></li> 212 <?php endforeach; ?> 213 </ul> 214 </div> 215 <form name="template" id="template" action="plugin-editor.php" method="post"> 216 <?php wp_nonce_field('edit-plugin_' . $file) ?> 217 <div><textarea cols="70" rows="25" name="newcontent" id="newcontent" tabindex="1"><?php echo $content ?></textarea> 218 <input type="hidden" name="action" value="update" /> 219 <input type="hidden" name="file" value="<?php echo esc_attr($file) ?>" /> 220 <input type="hidden" name="plugin" value="<?php echo esc_attr($plugin) ?>" /> 221 <input type="hidden" name="scrollto" id="scrollto" value="<?php echo $scrollto; ?>" /> 222 </div> 223 <?php if ( !empty( $docs_select ) ) : ?> 224 <div id="documentation" class="hide-if-no-js"><label for="docs-list"><?php _e('Documentation:') ?></label> <?php echo $docs_select ?> <input type="button" class="button" value="<?php esc_attr_e( 'Lookup' ) ?> " onclick="if ( '' != jQuery('#docs-list').val() ) { window.open( 'http://api.wordpress.org/core/handbook/1.0/?function=' + escape( jQuery( '#docs-list' ).val() ) + '&locale=<?php echo urlencode( get_locale() ) ?>&version=<?php echo urlencode( $wp_version ) ?>&redirect=true'); }" /></div> 225 <?php endif; ?> 226 <?php if ( is_writeable($real_file) ) : ?> 227 <?php if ( in_array( $file, (array) get_option( 'active_plugins', array() ) ) ) { ?> 228 <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> 229 <?php } ?> 230 <p class="submit"> 231 <?php 232 if ( isset($_GET['phperror']) ) 233 echo "<input type='hidden' name='phperror' value='1' /><input type='submit' name='submit' class='button-primary' value='" . esc_attr__('Update File and Attempt to Reactivate') . "' tabindex='2' />"; 234 else 235 echo "<input type='submit' name='submit' class='button-primary' value='" . esc_attr__('Update File') . "' tabindex='2' />"; 236 ?> 237 </p> 238 <?php else : ?> 239 <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> 240 <?php endif; ?> 241 </form> 242 <br class="clear" /> 243 </div> 244 <script type="text/javascript"> 245 /* <![CDATA[ */ 246 jQuery(document).ready(function($){ 247 $('#template').submit(function(){ $('#scrollto').val( $('#newcontent').scrollTop() ); }); 248 $('#newcontent').scrollTop( $('#scrollto').val() ); 249 }); 250 /* ]]> */ 251 </script> 252 <?php 253 break; 254 } 255 include ("./admin-footer.php");
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Oct 14 05:12:05 2010 | Cross-referenced by PHPXref 0.7 |