99 ); |
100 ); |
100 exit; |
101 exit; |
101 } |
102 } |
102 } |
103 } |
103 |
104 |
104 // List of allowable extensions |
105 // List of allowable extensions. |
105 $editable_extensions = wp_get_plugin_file_editable_extensions( $plugin ); |
106 $editable_extensions = wp_get_plugin_file_editable_extensions( $plugin ); |
106 |
107 |
107 if ( ! is_file( $real_file ) ) { |
108 if ( ! is_file( $real_file ) ) { |
108 wp_die( sprintf( '<p>%s</p>', __( 'No such file exists! Double check the name and try again.' ) ) ); |
109 wp_die( sprintf( '<p>%s</p>', __( 'File does not exist! Please double check the name and try again.' ) ) ); |
109 } else { |
110 } else { |
110 // Get the extension of the file |
111 // Get the extension of the file. |
111 if ( preg_match( '/\.([^.]+)$/', $real_file, $matches ) ) { |
112 if ( preg_match( '/\.([^.]+)$/', $real_file, $matches ) ) { |
112 $ext = strtolower( $matches[1] ); |
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 if ( ! in_array( $ext, $editable_extensions ) ) { |
115 if ( ! in_array( $ext, $editable_extensions, true ) ) { |
115 wp_die( sprintf( '<p>%s</p>', __( 'Files of this type are not editable.' ) ) ); |
116 wp_die( sprintf( '<p>%s</p>', __( 'Files of this type are not editable.' ) ) ); |
116 } |
117 } |
117 } |
118 } |
118 } |
119 } |
119 |
120 |
120 get_current_screen()->add_help_tab( |
121 get_current_screen()->add_help_tab( |
121 array( |
122 array( |
122 'id' => 'overview', |
123 'id' => 'overview', |
123 'title' => __( 'Overview' ), |
124 'title' => __( 'Overview' ), |
124 'content' => |
125 'content' => |
125 '<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>' . |
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>' . |
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>' . __( '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>' . __( '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 '<p id="editor-keyboard-trap-help-1">' . __( 'When using a keyboard to navigate:' ) . '</p>' . |
129 '<ul>' . |
130 '<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-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-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 '<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 '</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 '<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 ( is_network_admin() ? '<p>' . __( 'Any edits to files from this screen will be reflected on all sites in the network.' ) . '</p>' : '' ), |
136 ) |
137 ) |
137 ); |
138 ); |
138 |
139 |
139 get_current_screen()->set_help_sidebar( |
140 get_current_screen()->set_help_sidebar( |
140 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . |
141 '<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://wordpress.org/support/article/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://developer.wordpress.org/plugins/">Documentation on Writing Plugins</a>' ) . '</p>' . |
143 '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>' |
144 '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>' |
144 ); |
145 ); |
145 |
146 |
146 $settings = array( |
147 $settings = array( |
147 'codeEditor' => wp_enqueue_code_editor( array( 'file' => $real_file ) ), |
148 'codeEditor' => wp_enqueue_code_editor( array( 'file' => $real_file ) ), |
148 ); |
149 ); |
149 wp_enqueue_script( 'wp-theme-plugin-editor' ); |
150 wp_enqueue_script( 'wp-theme-plugin-editor' ); |
150 wp_add_inline_script( 'wp-theme-plugin-editor', sprintf( 'jQuery( function( $ ) { wp.themePluginEditor.init( $( "#template" ), %s ); } )', wp_json_encode( $settings ) ) ); |
151 wp_add_inline_script( 'wp-theme-plugin-editor', sprintf( 'jQuery( function( $ ) { wp.themePluginEditor.init( $( "#template" ), %s ); } )', wp_json_encode( $settings ) ) ); |
151 wp_add_inline_script( 'wp-theme-plugin-editor', sprintf( 'wp.themePluginEditor.themeOrPlugin = "plugin";' ) ); |
152 wp_add_inline_script( 'wp-theme-plugin-editor', sprintf( 'wp.themePluginEditor.themeOrPlugin = "plugin";' ) ); |
152 |
153 |
153 require_once( ABSPATH . 'wp-admin/admin-header.php' ); |
154 require_once ABSPATH . 'wp-admin/admin-header.php'; |
154 |
155 |
155 update_recently_edited( WP_PLUGIN_DIR . '/' . $file ); |
156 update_recently_edited( WP_PLUGIN_DIR . '/' . $file ); |
156 |
157 |
157 if ( ! empty( $posted_content ) ) { |
158 if ( ! empty( $posted_content ) ) { |
158 $content = $posted_content; |
159 $content = $posted_content; |
159 } else { |
160 } else { |
160 $content = file_get_contents( $real_file ); |
161 $content = file_get_contents( $real_file ); |
161 } |
162 } |
162 |
163 |
163 if ( '.php' == substr( $real_file, strrpos( $real_file, '.' ) ) ) { |
164 if ( '.php' === substr( $real_file, strrpos( $real_file, '.' ) ) ) { |
164 $functions = wp_doc_link_parse( $content ); |
165 $functions = wp_doc_link_parse( $content ); |
165 |
166 |
166 if ( ! empty( $functions ) ) { |
167 if ( ! empty( $functions ) ) { |
167 $docs_select = '<select name="docs-list" id="docs-list">'; |
168 $docs_select = '<select name="docs-list" id="docs-list">'; |
168 $docs_select .= '<option value="">' . __( 'Function Name…' ) . '</option>'; |
169 $docs_select .= '<option value="">' . __( 'Function Name…' ) . '</option>'; |
169 foreach ( $functions as $function ) { |
170 foreach ( $functions as $function ) { |
170 $docs_select .= '<option value="' . esc_attr( $function ) . '">' . esc_html( $function ) . '()</option>'; |
171 $docs_select .= '<option value="' . esc_attr( $function ) . '">' . esc_html( $function ) . '()</option>'; |
171 } |
172 } |
172 $docs_select .= '</select>'; |
173 $docs_select .= '</select>'; |
173 } |
174 } |
174 } |
175 } |
175 |
176 |
176 $content = esc_textarea( $content ); |
177 $content = esc_textarea( $content ); |
177 ?> |
178 ?> |
178 <div class="wrap"> |
179 <div class="wrap"> |
179 <h1><?php echo esc_html( $title ); ?></h1> |
180 <h1><?php echo esc_html( $title ); ?></h1> |
180 |
181 |
181 <?php if ( isset( $_GET['a'] ) ) : ?> |
182 <?php if ( isset( $_GET['a'] ) ) : ?> |
182 <div id="message" class="updated notice is-dismissible"> |
183 <div id="message" class="updated notice is-dismissible"> |
193 <div class="alignleft"> |
194 <div class="alignleft"> |
194 <h2> |
195 <h2> |
195 <?php |
196 <?php |
196 if ( is_plugin_active( $plugin ) ) { |
197 if ( is_plugin_active( $plugin ) ) { |
197 if ( is_writeable( $real_file ) ) { |
198 if ( is_writeable( $real_file ) ) { |
198 /* translators: %s: plugin file name */ |
199 /* translators: %s: Plugin file name. */ |
199 echo sprintf( __( 'Editing %s (active)' ), '<strong>' . esc_html( $file ) . '</strong>' ); |
200 printf( __( 'Editing %s (active)' ), '<strong>' . esc_html( $file ) . '</strong>' ); |
200 } else { |
201 } else { |
201 /* translators: %s: plugin file name */ |
202 /* translators: %s: Plugin file name. */ |
202 echo sprintf( __( 'Browsing %s (active)' ), '<strong>' . esc_html( $file ) . '</strong>' ); |
203 printf( __( 'Browsing %s (active)' ), '<strong>' . esc_html( $file ) . '</strong>' ); |
203 } |
204 } |
204 } else { |
205 } else { |
205 if ( is_writeable( $real_file ) ) { |
206 if ( is_writeable( $real_file ) ) { |
206 /* translators: %s: plugin file name */ |
207 /* translators: %s: Plugin file name. */ |
207 echo sprintf( __( 'Editing %s (inactive)' ), '<strong>' . esc_html( $file ) . '</strong>' ); |
208 printf( __( 'Editing %s (inactive)' ), '<strong>' . esc_html( $file ) . '</strong>' ); |
208 } else { |
209 } else { |
209 /* translators: %s: plugin file name */ |
210 /* translators: %s: Plugin file name. */ |
210 echo sprintf( __( 'Browsing %s (inactive)' ), '<strong>' . esc_html( $file ) . '</strong>' ); |
211 printf( __( 'Browsing %s (inactive)' ), '<strong>' . esc_html( $file ) . '</strong>' ); |
211 } |
212 } |
212 } |
213 } |
213 ?> |
214 ?> |
214 </h2> |
215 </h2> |
215 </div> |
216 </div> |
216 <div class="alignright"> |
217 <div class="alignright"> |
217 <form action="plugin-editor.php" method="get"> |
218 <form action="plugin-editor.php" method="get"> |
218 <strong><label for="plugin"><?php _e( 'Select plugin to edit:' ); ?> </label></strong> |
219 <strong><label for="plugin"><?php _e( 'Select plugin to edit:' ); ?> </label></strong> |
219 <select name="plugin" id="plugin"> |
220 <select name="plugin" id="plugin"> |
220 <?php |
221 <?php |
221 foreach ( $plugins as $plugin_key => $a_plugin ) { |
222 foreach ( $plugins as $plugin_key => $a_plugin ) { |
222 $plugin_name = $a_plugin['Name']; |
223 $plugin_name = $a_plugin['Name']; |
223 if ( $plugin_key == $plugin ) { |
224 if ( $plugin_key === $plugin ) { |
224 $selected = " selected='selected'"; |
225 $selected = " selected='selected'"; |
225 } else { |
226 } else { |
226 $selected = ''; |
227 $selected = ''; |
227 } |
228 } |
228 $plugin_name = esc_attr( $plugin_name ); |
229 $plugin_name = esc_attr( $plugin_name ); |
229 $plugin_key = esc_attr( $plugin_key ); |
230 $plugin_key = esc_attr( $plugin_key ); |
230 echo "\n\t<option value=\"$plugin_key\" $selected>$plugin_name</option>"; |
231 echo "\n\t<option value=\"$plugin_key\" $selected>$plugin_name</option>"; |
231 } |
232 } |
232 ?> |
233 ?> |
233 </select> |
234 </select> |
234 <?php submit_button( __( 'Select' ), '', 'Submit', false ); ?> |
235 <?php submit_button( __( 'Select' ), '', 'Submit', false ); ?> |
235 </form> |
236 </form> |
236 </div> |
237 </div> |
237 <br class="clear" /> |
238 <br class="clear" /> |
253 <ul role="group"> |
254 <ul role="group"> |
254 <?php wp_print_plugin_file_tree( wp_make_plugin_file_tree( $plugin_editable_files ) ); ?> |
255 <?php wp_print_plugin_file_tree( wp_make_plugin_file_tree( $plugin_editable_files ) ); ?> |
255 </ul> |
256 </ul> |
256 </ul> |
257 </ul> |
257 </div> |
258 </div> |
|
259 |
258 <form name="template" id="template" action="plugin-editor.php" method="post"> |
260 <form name="template" id="template" action="plugin-editor.php" method="post"> |
259 <?php wp_nonce_field( 'edit-plugin_' . $file, 'nonce' ); ?> |
261 <?php wp_nonce_field( 'edit-plugin_' . $file, 'nonce' ); ?> |
260 <div> |
262 <div> |
261 <label for="newcontent" id="theme-plugin-editor-label"><?php _e( 'Selected file content:' ); ?></label> |
263 <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> |
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> |
263 <input type="hidden" name="action" value="update" /> |
265 <input type="hidden" name="action" value="update" /> |
264 <input type="hidden" name="file" value="<?php echo esc_attr( $file ); ?>" /> |
266 <input type="hidden" name="file" value="<?php echo esc_attr( $file ); ?>" /> |
265 <input type="hidden" name="plugin" value="<?php echo esc_attr( $plugin ); ?>" /> |
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 </div> |
275 </div> |
267 <?php if ( ! empty( $docs_select ) ) : ?> |
276 <?php endif; ?> |
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> |
277 |
269 <?php endif; ?> |
278 <?php if ( is_writeable( $real_file ) ) : ?> |
270 <?php if ( is_writeable( $real_file ) ) : ?> |
279 <div class="editor-notices"> |
271 <div class="editor-notices"> |
280 <?php if ( in_array( $plugin, (array) get_option( 'active_plugins', array() ), true ) ) { ?> |
272 <?php if ( in_array( $plugin, (array) get_option( 'active_plugins', array() ) ) ) { ?> |
|
273 <div class="notice notice-warning inline active-plugin-edit-warning"> |
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 </div> |
285 </div> |
276 <?php } ?> |
286 <p class="submit"> |
277 </div> |
287 <?php submit_button( __( 'Update File' ), 'primary', 'submit', false ); ?> |
278 <p class="submit"> |
288 <span class="spinner"></span> |
279 <?php submit_button( __( 'Update File' ), 'primary', 'submit', false ); ?> |
289 </p> |
280 <span class="spinner"></span> |
290 <?php else : ?> |
281 </p> |
291 <p><em> |
282 <?php else : ?> |
292 <?php |
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> |
293 printf( |
284 <?php endif; ?> |
294 /* translators: %s: Documentation URL. */ |
285 <?php wp_print_file_editor_templates(); ?> |
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(); ?> |
286 </form> |
303 </form> |
287 <br class="clear" /> |
304 <br class="clear" /> |
288 </div> |
305 </div> |
289 <?php |
306 <?php |
290 $dismissed_pointers = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ); |
307 $dismissed_pointers = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ); |
291 if ( ! in_array( 'plugin_editor_notice', $dismissed_pointers, true ) ) : |
308 if ( ! in_array( 'plugin_editor_notice', $dismissed_pointers, true ) ) : |
292 // Get a back URL |
309 // Get a back URL. |
293 $referer = wp_get_referer(); |
310 $referer = wp_get_referer(); |
|
311 |
294 $excluded_referer_basenames = array( 'plugin-editor.php', 'wp-login.php' ); |
312 $excluded_referer_basenames = array( 'plugin-editor.php', 'wp-login.php' ); |
295 |
313 |
296 if ( $referer && ! in_array( basename( parse_url( $referer, PHP_URL_PATH ) ), $excluded_referer_basenames, true ) ) { |
314 if ( $referer && ! in_array( basename( parse_url( $referer, PHP_URL_PATH ) ), $excluded_referer_basenames, true ) ) { |
297 $return_url = $referer; |
315 $return_url = $referer; |
298 } else { |
316 } else { |
299 $return_url = admin_url( '/' ); |
317 $return_url = admin_url( '/' ); |
300 } |
318 } |
301 ?> |
319 ?> |
302 <div id="file-editor-warning" class="notification-dialog-wrap file-editor-warning hide-if-no-js hidden"> |
320 <div id="file-editor-warning" class="notification-dialog-wrap file-editor-warning hide-if-no-js hidden"> |
303 <div class="notification-dialog-background"></div> |
321 <div class="notification-dialog-background"></div> |
304 <div class="notification-dialog"> |
322 <div class="notification-dialog"> |
305 <div class="file-editor-warning-content"> |
323 <div class="file-editor-warning-content"> |
306 <div class="file-editor-warning-message"> |
324 <div class="file-editor-warning-message"> |
307 <h1><?php _e( 'Heads up!' ); ?></h1> |
325 <h1><?php _e( 'Heads up!' ); ?></h1> |
308 <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> |
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> |
309 <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> |
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> |
310 </div> |
333 </div> |
311 <p> |
|
312 <a class="button file-editor-warning-go-back" href="<?php echo esc_url( $return_url ); ?>"><?php _e( 'Go back' ); ?></a> |
|
313 <button type="button" class="file-editor-warning-dismiss button button-primary"><?php _e( 'I understand' ); ?></button> |
|
314 </p> |
|
315 </div> |
334 </div> |
316 </div> |
335 </div> |
317 </div> |
|
318 <?php |
336 <?php |
319 endif; // Editor warning notice. |
337 endif; // Editor warning notice. |
320 |
338 |
321 include( ABSPATH . 'wp-admin/admin-footer.php' ); |
339 require_once ABSPATH . 'wp-admin/admin-footer.php'; |