PageRenderTime 25ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-admin/plugin-editor.php

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