Changeset 42343 for trunk/src/wp-admin/plugin-editor.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/plugin-editor.php
r42201 r42343 15 15 } 16 16 17 if ( !current_user_can('edit_plugins') ) 18 wp_die( __('Sorry, you are not allowed to edit plugins for this site.') ); 19 20 $title = __("Edit Plugins"); 17 if ( ! current_user_can( 'edit_plugins' ) ) { 18 wp_die( __( 'Sorry, you are not allowed to edit plugins for this site.' ) ); 19 } 20 21 $title = __( 'Edit Plugins' ); 21 22 $parent_file = 'plugins.php'; 22 23 … … 35 36 } 36 37 37 $file = '';38 $file = ''; 38 39 $plugin = ''; 39 40 if ( isset( $_REQUEST['file'] ) ) { … … 67 68 } 68 69 69 $plugin_files = get_plugin_files( $plugin);70 $plugin_files = get_plugin_files( $plugin ); 70 71 71 72 if ( empty( $file ) ) { … … 73 74 } 74 75 75 $file = validate_file_to_edit($file, $plugin_files);76 $file = validate_file_to_edit( $file, $plugin_files ); 76 77 $real_file = WP_PLUGIN_DIR . '/' . $file; 77 78 78 79 // Handle fallback editing of file when JavaScript is not available. 79 $edit_error = null;80 $edit_error = null; 80 81 $posted_content = null; 81 82 if ( 'POST' === $_SERVER['REQUEST_METHOD'] ) { … … 87 88 } 88 89 } else { 89 wp_redirect( add_query_arg( 90 array( 91 'a' => 1, // This means "success" for some reason. 92 'plugin' => $plugin, 93 'file' => $file, 94 ), 95 admin_url( 'plugin-editor.php' ) 96 ) ); 90 wp_redirect( 91 add_query_arg( 92 array( 93 'a' => 1, // This means "success" for some reason. 94 'plugin' => $plugin, 95 'file' => $file, 96 ), 97 admin_url( 'plugin-editor.php' ) 98 ) 99 ); 97 100 exit; 98 101 } … … 102 105 $editable_extensions = wp_get_plugin_file_editable_extensions( $plugin ); 103 106 104 if ( ! is_file($real_file) ) { 105 wp_die(sprintf('<p>%s</p>', __('No such file exists! Double check the name and try again.'))); 106 } else { 107 // Get the extension of the file 108 if ( preg_match('/\.([^.]+)$/', $real_file, $matches) ) { 109 $ext = strtolower($matches[1]); 110 // If extension is not in the acceptable list, skip it 111 if ( !in_array( $ext, $editable_extensions) ) 112 wp_die(sprintf('<p>%s</p>', __('Files of this type are not editable.'))); 113 } 114 } 115 116 get_current_screen()->add_help_tab( array( 117 'id' => 'overview', 118 'title' => __('Overview'), 119 'content' => 120 '<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>' . 121 '<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>' . 122 '<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>' . 123 '<p id="editor-keyboard-trap-help-1">' . __( 'When using a keyboard to navigate:' ) . '</p>' . 124 '<ul>' . 125 '<li id="editor-keyboard-trap-help-2">' . __( 'In the editing area, the Tab key enters a tab character.' ) . '</li>' . 126 '<li id="editor-keyboard-trap-help-3">' . __( 'To move away from this area, press the Esc key followed by the Tab key.' ) . '</li>' . 127 '<li id="editor-keyboard-trap-help-4">' . __( 'Screen reader users: when in forms mode, you may need to press the Esc key twice.' ) . '</li>' . 128 '</ul>' . 129 '<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>' . 130 ( is_network_admin() ? '<p>' . __('Any edits to files from this screen will be reflected on all sites in the network.') . '</p>' : '' ) 131 ) ); 107 if ( ! is_file( $real_file ) ) { 108 wp_die( sprintf( '<p>%s</p>', __( 'No such file exists! Double check the name and try again.' ) ) ); 109 } else { 110 // Get the extension of the file 111 if ( preg_match( '/\.([^.]+)$/', $real_file, $matches ) ) { 112 $ext = strtolower( $matches[1] ); 113 // If extension is not in the acceptable list, skip it 114 if ( ! in_array( $ext, $editable_extensions ) ) { 115 wp_die( sprintf( '<p>%s</p>', __( 'Files of this type are not editable.' ) ) ); 116 } 117 } 118 } 119 120 get_current_screen()->add_help_tab( 121 array( 122 'id' => 'overview', 123 'title' => __( 'Overview' ), 124 'content' => 125 '<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>' . 126 '<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>' . 127 '<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>' . 128 '<p id="editor-keyboard-trap-help-1">' . __( 'When using a keyboard to navigate:' ) . '</p>' . 129 '<ul>' . 130 '<li id="editor-keyboard-trap-help-2">' . __( 'In the editing area, the Tab key enters a tab character.' ) . '</li>' . 131 '<li id="editor-keyboard-trap-help-3">' . __( 'To move away from this area, press the Esc key followed by the Tab key.' ) . '</li>' . 132 '<li id="editor-keyboard-trap-help-4">' . __( 'Screen reader users: when in forms mode, you may need to press the Esc key twice.' ) . '</li>' . 133 '</ul>' . 134 '<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>' . 135 ( is_network_admin() ? '<p>' . __( 'Any edits to files from this screen will be reflected on all sites in the network.' ) . '</p>' : '' ), 136 ) 137 ); 132 138 133 139 get_current_screen()->set_help_sidebar( 134 '<p><strong>' . __( 'For more information:') . '</strong></p>' .135 '<p>' . __( '<a href="https://codex.wordpress.org/Plugins_Editor_Screen">Documentation on Editing Plugins</a>') . '</p>' .136 '<p>' . __( '<a href="https://codex.wordpress.org/Writing_a_Plugin">Documentation on Writing Plugins</a>') . '</p>' .137 '<p>' . __( '<a href="https://wordpress.org/support/">Support Forums</a>') . '</p>'140 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . 141 '<p>' . __( '<a href="https://codex.wordpress.org/Plugins_Editor_Screen">Documentation on Editing Plugins</a>' ) . '</p>' . 142 '<p>' . __( '<a href="https://codex.wordpress.org/Writing_a_Plugin">Documentation on Writing Plugins</a>' ) . '</p>' . 143 '<p>' . __( '<a href="https://wordpress.org/support/">Support Forums</a>' ) . '</p>' 138 144 ); 139 145 … … 145 151 wp_add_inline_script( 'wp-theme-plugin-editor', sprintf( 'wp.themePluginEditor.themeOrPlugin = "plugin";' ) ); 146 152 147 require_once( ABSPATH . 'wp-admin/admin-header.php');148 149 update_recently_edited( WP_PLUGIN_DIR . '/' . $file);153 require_once( ABSPATH . 'wp-admin/admin-header.php' ); 154 155 update_recently_edited( WP_PLUGIN_DIR . '/' . $file ); 150 156 151 157 if ( ! empty( $posted_content ) ) { … … 158 164 $functions = wp_doc_link_parse( $content ); 159 165 160 if ( ! empty($functions) ) {161 $docs_select = '<select name="docs-list" id="docs-list">';166 if ( ! empty( $functions ) ) { 167 $docs_select = '<select name="docs-list" id="docs-list">'; 162 168 $docs_select .= '<option value="">' . __( 'Function Name…' ) . '</option>'; 163 foreach ( $functions as $function ) {169 foreach ( $functions as $function ) { 164 170 $docs_select .= '<option value="' . esc_attr( $function ) . '">' . esc_html( $function ) . '()</option>'; 165 171 } … … 210 216 <div class="alignright"> 211 217 <form action="plugin-editor.php" method="get"> 212 <strong><label for="plugin"><?php _e( 'Select plugin to edit:'); ?> </label></strong>218 <strong><label for="plugin"><?php _e( 'Select plugin to edit:' ); ?> </label></strong> 213 219 <select name="plugin" id="plugin"> 214 220 <?php 215 foreach ( $plugins as $plugin_key => $a_plugin ) { 216 $plugin_name = $a_plugin['Name']; 217 if ( $plugin_key == $plugin ) 218 $selected = " selected='selected'"; 219 else 220 $selected = ''; 221 $plugin_name = esc_attr($plugin_name); 222 $plugin_key = esc_attr($plugin_key); 223 echo "\n\t<option value=\"$plugin_key\" $selected>$plugin_name</option>"; 224 } 221 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 } 225 232 ?> 226 233 </select> … … 237 244 $plugin_editable_files = array(); 238 245 foreach ( $plugin_files as $plugin_file ) { 239 if ( preg_match( '/\.([^.]+)$/', $plugin_file, $matches ) && in_array( $matches[1], $editable_extensions ) ) {246 if ( preg_match( '/\.([^.]+)$/', $plugin_file, $matches ) && in_array( $matches[1], $editable_extensions ) ) { 240 247 $plugin_editable_files[] = $plugin_file; 241 248 } … … 258 265 <input type="hidden" name="plugin" value="<?php echo esc_attr( $plugin ); ?>" /> 259 266 </div> 260 <?php if ( ! empty( $docs_select ) ) : ?>261 <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( '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>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 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> 262 269 <?php endif; ?> 263 <?php if ( is_writeable( $real_file) ) : ?>270 <?php if ( is_writeable( $real_file ) ) : ?> 264 271 <div class="editor-notices"> 265 272 <?php if ( in_array( $plugin, (array) get_option( 'active_plugins', array() ) ) ) { ?> 266 273 <div class="notice notice-warning inline active-plugin-edit-warning"> 267 <p><?php _e( '<strong>Warning:</strong> Making changes to active plugins is not recommended.'); ?></p>274 <p><?php _e( '<strong>Warning:</strong> Making changes to active plugins is not recommended.' ); ?></p> 268 275 </div> 269 276 <?php } ?> … … 274 281 </p> 275 282 <?php else : ?> 276 <p><em><?php _e( 'You need to make this file writable before you can save your changes. See <a href="https://codex.wordpress.org/Changing_File_Permissions">the Codex</a> for more information.'); ?></em></p>283 <p><em><?php _e( 'You need to make this file writable before you can save your changes. See <a href="https://codex.wordpress.org/Changing_File_Permissions">the Codex</a> for more information.' ); ?></em></p> 277 284 <?php endif; ?> 278 285 <?php wp_print_file_editor_templates(); ?> … … 284 291 if ( ! in_array( 'plugin_editor_notice', $dismissed_pointers, true ) ) : 285 292 // Get a back URL 286 $referer = wp_get_referer();293 $referer = wp_get_referer(); 287 294 $excluded_referer_basenames = array( 'plugin-editor.php', 'wp-login.php' ); 288 295 … … 312 319 endif; // editor warning notice 313 320 314 include( ABSPATH . "wp-admin/admin-footer.php");321 include( ABSPATH . 'wp-admin/admin-footer.php' );
Note: See TracChangeset
for help on using the changeset viewer.