Changeset 47122 for trunk/src/wp-admin/plugin-editor.php
- Timestamp:
- 01/29/2020 12:43:23 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/plugin-editor.php
r45932 r47122 80 80 $edit_error = null; 81 81 $posted_content = null; 82 82 83 if ( 'POST' === $_SERVER['REQUEST_METHOD'] ) { 83 84 $r = wp_edit_theme_plugin_file( wp_unslash( $_POST ) ); … … 102 103 } 103 104 104 // List of allowable extensions 105 105 // List of allowable extensions. 106 $editable_extensions = wp_get_plugin_file_editable_extensions( $plugin ); 106 107 107 108 if ( ! is_file( $real_file ) ) { 108 109 wp_die( sprintf( '<p>%s</p>', __( 'File does not exist! Please double check the name and try again.' ) ) ); 109 110 } else { 110 // Get the extension of the file 111 // Get the extension of the file. 111 112 if ( preg_match( '/\.([^.]+)$/', $real_file, $matches ) ) { 112 113 $ext = strtolower( $matches[1] ); 113 // If extension is not in the acceptable list, skip it 114 // If extension is not in the acceptable list, skip it. 114 115 if ( ! in_array( $ext, $editable_extensions ) ) { 115 116 wp_die( sprintf( '<p>%s</p>', __( 'Files of this type are not editable.' ) ) ); … … 118 119 } 119 120 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 121 get_current_screen()->add_help_tab( 122 array( 123 'id' => 'overview', 124 'title' => __( 'Overview' ), 125 'content' => 126 '<p>' . __( 'You can use the plugin 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>' . 127 '<p>' . __( 'Choose a plugin to edit from the dropdown menu 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>' . 128 '<p>' . __( 'The Documentation menu below the editor lists the PHP functions recognized in the plugin file. Clicking Look Up takes you to a web page about that particular function.' ) . '</p>' . 129 '<p id="editor-keyboard-trap-help-1">' . __( 'When using a keyboard to navigate:' ) . '</p>' . 130 '<ul>' . 131 '<li id="editor-keyboard-trap-help-2">' . __( 'In the editing area, the Tab key enters a tab character.' ) . '</li>' . 132 '<li id="editor-keyboard-trap-help-3">' . __( 'To move away from this area, press the Esc key followed by the Tab key.' ) . '</li>' . 133 '<li id="editor-keyboard-trap-help-4">' . __( 'Screen reader users: when in forms mode, you may need to press the Esc key twice.' ) . '</li>' . 134 '</ul>' . 135 '<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 plugins, write your own from scratch, or just better understand their anatomy, check out the links below.' ) . '</p>' . 136 ( is_network_admin() ? '<p>' . __( 'Any edits to files from this screen will be reflected on all sites in the network.' ) . '</p>' : '' ), 137 ) 138 ); 139 140 get_current_screen()->set_help_sidebar( 141 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . 142 '<p>' . __( '<a href="https://wordpress.org/support/article/plugins-editor-screen/">Documentation on Editing Plugins</a>' ) . '</p>' . 143 '<p>' . __( '<a href="https://developer.wordpress.org/plugins/">Documentation on Writing Plugins</a>' ) . '</p>' . 144 '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>' 145 ); 146 147 $settings = array( 148 'codeEditor' => wp_enqueue_code_editor( array( 'file' => $real_file ) ), 149 ); 150 wp_enqueue_script( 'wp-theme-plugin-editor' ); 151 wp_add_inline_script( 'wp-theme-plugin-editor', sprintf( 'jQuery( function( $ ) { wp.themePluginEditor.init( $( "#template" ), %s ); } )', wp_json_encode( $settings ) ) ); 152 wp_add_inline_script( 'wp-theme-plugin-editor', sprintf( 'wp.themePluginEditor.themeOrPlugin = "plugin";' ) ); 153 154 require_once( ABSPATH . 'wp-admin/admin-header.php' ); 155 156 update_recently_edited( WP_PLUGIN_DIR . '/' . $file ); 157 158 if ( ! empty( $posted_content ) ) { 159 $content = $posted_content; 160 } else { 161 $content = file_get_contents( $real_file ); 162 } 163 164 if ( '.php' == substr( $real_file, strrpos( $real_file, '.' ) ) ) { 165 $functions = wp_doc_link_parse( $content ); 166 167 if ( ! empty( $functions ) ) { 168 $docs_select = '<select name="docs-list" id="docs-list">'; 169 $docs_select .= '<option value="">' . __( 'Function Name…' ) . '</option>'; 170 foreach ( $functions as $function ) { 171 $docs_select .= '<option value="' . esc_attr( $function ) . '">' . esc_html( $function ) . '()</option>'; 172 } 173 $docs_select .= '</select>'; 174 } 175 } 176 177 $content = esc_textarea( $content ); 178 ?> 178 179 <div class="wrap"> 179 180 <h1><?php echo esc_html( $title ); ?></h1> … … 218 219 <strong><label for="plugin"><?php _e( 'Select plugin to edit:' ); ?> </label></strong> 219 220 <select name="plugin" id="plugin"> 220 <?php221 foreach ( $plugins as $plugin_key => $a_plugin ) {222 $plugin_name = $a_plugin['Name'];223 if ( $plugin_key == $plugin ) {224 $selected = " selected='selected'";225 } else {226 $selected = '';227 }228 $plugin_name = esc_attr( $plugin_name );229 $plugin_key = esc_attr( $plugin_key );230 echo "\n\t<option value=\"$plugin_key\" $selected>$plugin_name</option>";231 }232 ?>221 <?php 222 foreach ( $plugins as $plugin_key => $a_plugin ) { 223 $plugin_name = $a_plugin['Name']; 224 if ( $plugin_key == $plugin ) { 225 $selected = " selected='selected'"; 226 } else { 227 $selected = ''; 228 } 229 $plugin_name = esc_attr( $plugin_name ); 230 $plugin_key = esc_attr( $plugin_key ); 231 echo "\n\t<option value=\"$plugin_key\" $selected>$plugin_name</option>"; 232 } 233 ?> 233 234 </select> 234 235 <?php submit_button( __( 'Select' ), '', 'Submit', false ); ?> … … 256 257 </ul> 257 258 </div> 259 258 260 <form name="template" id="template" action="plugin-editor.php" method="post"> 259 261 <?php wp_nonce_field( 'edit-plugin_' . $file, 'nonce' ); ?> 260 <div> 261 <label for="newcontent" id="theme-plugin-editor-label"><?php _e( 'Selected file content:' ); ?></label> 262 <textarea cols="70" rows="25" name="newcontent" id="newcontent" aria-describedby="editor-keyboard-trap-help-1 editor-keyboard-trap-help-2 editor-keyboard-trap-help-3 editor-keyboard-trap-help-4"><?php echo $content; ?></textarea> 263 <input type="hidden" name="action" value="update" /> 264 <input type="hidden" name="file" value="<?php echo esc_attr( $file ); ?>" /> 265 <input type="hidden" name="plugin" value="<?php echo esc_attr( $plugin ); ?>" /> 262 <div> 263 <label for="newcontent" id="theme-plugin-editor-label"><?php _e( 'Selected file content:' ); ?></label> 264 <textarea cols="70" rows="25" name="newcontent" id="newcontent" aria-describedby="editor-keyboard-trap-help-1 editor-keyboard-trap-help-2 editor-keyboard-trap-help-3 editor-keyboard-trap-help-4"><?php echo $content; ?></textarea> 265 <input type="hidden" name="action" value="update" /> 266 <input type="hidden" name="file" value="<?php echo esc_attr( $file ); ?>" /> 267 <input type="hidden" name="plugin" value="<?php echo esc_attr( $plugin ); ?>" /> 268 </div> 269 270 <?php if ( ! empty( $docs_select ) ) : ?> 271 <div id="documentation" class="hide-if-no-js"> 272 <label for="docs-list"><?php _e( 'Documentation:' ); ?></label> 273 <?php echo $docs_select; ?> 274 <input disabled id="docs-lookup" type="button" class="button" value="<?php esc_attr_e( 'Look Up' ); ?>" onclick="if ( '' != jQuery('#docs-list').val() ) { window.open( 'https://api.wordpress.org/core/handbook/1.0/?function=' + escape( jQuery( '#docs-list' ).val() ) + '&locale=<?php echo urlencode( get_user_locale() ); ?>&version=<?php echo urlencode( get_bloginfo( 'version' ) ); ?>&redirect=true'); }" /> 266 275 </div> 267 <?php if ( ! empty( $docs_select ) ) : ?> 268 <div id="documentation" class="hide-if-no-js"><label for="docs-list"><?php _e( 'Documentation:' ); ?></label> <?php echo $docs_select; ?> <input disabled id="docs-lookup" type="button" class="button" value="<?php esc_attr_e( 'Look Up' ); ?> " onclick="if ( '' != jQuery('#docs-list').val() ) { window.open( 'https://api.wordpress.org/core/handbook/1.0/?function=' + escape( jQuery( '#docs-list' ).val() ) + '&locale=<?php echo urlencode( get_user_locale() ); ?>&version=<?php echo urlencode( get_bloginfo( 'version' ) ); ?>&redirect=true'); }" /></div> 269 <?php endif; ?> 270 <?php if ( is_writeable( $real_file ) ) : ?> 271 <div class="editor-notices"> 276 <?php endif; ?> 277 278 <?php if ( is_writeable( $real_file ) ) : ?> 279 <div class="editor-notices"> 272 280 <?php if ( in_array( $plugin, (array) get_option( 'active_plugins', array() ) ) ) { ?> 273 281 <div class="notice notice-warning inline active-plugin-edit-warning"> 274 <p><?php _e( '<strong>Warning:</strong> Making changes to active plugins is not recommended.' ); ?></p> 282 <p><?php _e( '<strong>Warning:</strong> Making changes to active plugins is not recommended.' ); ?></p> 283 </div> 284 <?php } ?> 275 285 </div> 276 <?php } ?> 277 </div> 278 <p class="submit"> 279 <?php submit_button( __( 'Update File' ), 'primary', 'submit', false ); ?> 280 <span class="spinner"></span> 281 </p> 282 <?php else : ?> 283 <p><em> 284 <?php 285 printf( 286 /* translators: %s: Documentation URL. */ 287 __( 'You need to make this file writable before you can save your changes. See <a href="%s">Changing File Permissions</a> for more information.' ), 288 __( 'https://wordpress.org/support/article/changing-file-permissions/' ) 289 ); 290 ?> 291 </em></p> 292 <?php endif; ?> 293 <?php wp_print_file_editor_templates(); ?> 286 <p class="submit"> 287 <?php submit_button( __( 'Update File' ), 'primary', 'submit', false ); ?> 288 <span class="spinner"></span> 289 </p> 290 <?php else : ?> 291 <p><em> 292 <?php 293 printf( 294 /* translators: %s: Documentation URL. */ 295 __( 'You need to make this file writable before you can save your changes. See <a href="%s">Changing File Permissions</a> for more information.' ), 296 __( 'https://wordpress.org/support/article/changing-file-permissions/' ) 297 ); 298 ?> 299 </em></p> 300 <?php endif; ?> 301 302 <?php wp_print_file_editor_templates(); ?> 294 303 </form> 295 304 <br class="clear" /> … … 298 307 $dismissed_pointers = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ); 299 308 if ( ! in_array( 'plugin_editor_notice', $dismissed_pointers, true ) ) : 300 // Get a back URL 301 $referer = wp_get_referer(); 309 // Get a back URL. 310 $referer = wp_get_referer(); 311 302 312 $excluded_referer_basenames = array( 'plugin-editor.php', 'wp-login.php' ); 303 313 … … 308 318 } 309 319 ?> 310 <div id="file-editor-warning" class="notification-dialog-wrap file-editor-warning hide-if-no-js hidden"> 311 <div class="notification-dialog-background"></div> 312 <div class="notification-dialog"> 313 <div class="file-editor-warning-content"> 314 <div class="file-editor-warning-message"> 315 <h1><?php _e( 'Heads up!' ); ?></h1> 316 <p><?php _e( 'You appear to be making direct edits to your plugin in the WordPress dashboard. We recommend that you don’t! Editing plugins directly may introduce incompatibilities that break your site and your changes may be lost in future updates.' ); ?></p> 317 <p><?php _e( 'If you absolutely have to make direct edits to this plugin, use a file manager to create a copy with a new name and hang on to the original. That way, you can re-enable a functional version if something goes wrong.' ); ?></p> 320 <div id="file-editor-warning" class="notification-dialog-wrap file-editor-warning hide-if-no-js hidden"> 321 <div class="notification-dialog-background"></div> 322 <div class="notification-dialog"> 323 <div class="file-editor-warning-content"> 324 <div class="file-editor-warning-message"> 325 <h1><?php _e( 'Heads up!' ); ?></h1> 326 <p><?php _e( 'You appear to be making direct edits to your plugin in the WordPress dashboard. We recommend that you don’t! Editing plugins directly may introduce incompatibilities that break your site and your changes may be lost in future updates.' ); ?></p> 327 <p><?php _e( 'If you absolutely have to make direct edits to this plugin, use a file manager to create a copy with a new name and hang on to the original. That way, you can re-enable a functional version if something goes wrong.' ); ?></p> 328 </div> 329 <p> 330 <a class="button file-editor-warning-go-back" href="<?php echo esc_url( $return_url ); ?>"><?php _e( 'Go back' ); ?></a> 331 <button type="button" class="file-editor-warning-dismiss button button-primary"><?php _e( 'I understand' ); ?></button> 332 </p> 318 333 </div> 319 <p>320 <a class="button file-editor-warning-go-back" href="<?php echo esc_url( $return_url ); ?>"><?php _e( 'Go back' ); ?></a>321 <button type="button" class="file-editor-warning-dismiss button button-primary"><?php _e( 'I understand' ); ?></button>322 </p>323 334 </div> 324 335 </div> 325 </div>326 336 <?php 327 337 endif; // Editor warning notice.
Note: See TracChangeset
for help on using the changeset viewer.