Edit File by line
/home/barbar84/www/wp-admin
File: plugin-editor.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Edit plugin editor administration panel.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Administration
[5] Fix | Delete
*/
[6] Fix | Delete
[7] Fix | Delete
/** WordPress Administration Bootstrap */
[8] Fix | Delete
require_once __DIR__ . '/admin.php';
[9] Fix | Delete
[10] Fix | Delete
if ( is_multisite() && ! is_network_admin() ) {
[11] Fix | Delete
wp_redirect( network_admin_url( 'plugin-editor.php' ) );
[12] Fix | Delete
exit;
[13] Fix | Delete
}
[14] Fix | Delete
[15] Fix | Delete
if ( ! current_user_can( 'edit_plugins' ) ) {
[16] Fix | Delete
wp_die( __( 'Sorry, you are not allowed to edit plugins for this site.' ) );
[17] Fix | Delete
}
[18] Fix | Delete
[19] Fix | Delete
$title = __( 'Edit Plugins' );
[20] Fix | Delete
$parent_file = 'plugins.php';
[21] Fix | Delete
[22] Fix | Delete
$plugins = get_plugins();
[23] Fix | Delete
[24] Fix | Delete
if ( empty( $plugins ) ) {
[25] Fix | Delete
require_once ABSPATH . 'wp-admin/admin-header.php';
[26] Fix | Delete
?>
[27] Fix | Delete
<div class="wrap">
[28] Fix | Delete
<h1><?php echo esc_html( $title ); ?></h1>
[29] Fix | Delete
<div id="message" class="error"><p><?php _e( 'No plugins are currently available.' ); ?></p></div>
[30] Fix | Delete
</div>
[31] Fix | Delete
<?php
[32] Fix | Delete
require_once ABSPATH . 'wp-admin/admin-footer.php';
[33] Fix | Delete
exit;
[34] Fix | Delete
}
[35] Fix | Delete
[36] Fix | Delete
$file = '';
[37] Fix | Delete
$plugin = '';
[38] Fix | Delete
if ( isset( $_REQUEST['file'] ) ) {
[39] Fix | Delete
$file = wp_unslash( $_REQUEST['file'] );
[40] Fix | Delete
}
[41] Fix | Delete
[42] Fix | Delete
if ( isset( $_REQUEST['plugin'] ) ) {
[43] Fix | Delete
$plugin = wp_unslash( $_REQUEST['plugin'] );
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
if ( empty( $plugin ) ) {
[47] Fix | Delete
if ( $file ) {
[48] Fix | Delete
[49] Fix | Delete
// Locate the plugin for a given plugin file being edited.
[50] Fix | Delete
$file_dirname = dirname( $file );
[51] Fix | Delete
foreach ( array_keys( $plugins ) as $plugin_candidate ) {
[52] Fix | Delete
if ( $plugin_candidate === $file || ( '.' !== $file_dirname && dirname( $plugin_candidate ) === $file_dirname ) ) {
[53] Fix | Delete
$plugin = $plugin_candidate;
[54] Fix | Delete
break;
[55] Fix | Delete
}
[56] Fix | Delete
}
[57] Fix | Delete
[58] Fix | Delete
// Fallback to the file as the plugin.
[59] Fix | Delete
if ( empty( $plugin ) ) {
[60] Fix | Delete
$plugin = $file;
[61] Fix | Delete
}
[62] Fix | Delete
} else {
[63] Fix | Delete
$plugin = array_keys( $plugins );
[64] Fix | Delete
$plugin = $plugin[0];
[65] Fix | Delete
}
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
$plugin_files = get_plugin_files( $plugin );
[69] Fix | Delete
[70] Fix | Delete
if ( empty( $file ) ) {
[71] Fix | Delete
$file = $plugin_files[0];
[72] Fix | Delete
}
[73] Fix | Delete
[74] Fix | Delete
$file = validate_file_to_edit( $file, $plugin_files );
[75] Fix | Delete
$real_file = WP_PLUGIN_DIR . '/' . $file;
[76] Fix | Delete
[77] Fix | Delete
// Handle fallback editing of file when JavaScript is not available.
[78] Fix | Delete
$edit_error = null;
[79] Fix | Delete
$posted_content = null;
[80] Fix | Delete
[81] Fix | Delete
if ( 'POST' === $_SERVER['REQUEST_METHOD'] ) {
[82] Fix | Delete
$r = wp_edit_theme_plugin_file( wp_unslash( $_POST ) );
[83] Fix | Delete
if ( is_wp_error( $r ) ) {
[84] Fix | Delete
$edit_error = $r;
[85] Fix | Delete
if ( check_ajax_referer( 'edit-plugin_' . $file, 'nonce', false ) && isset( $_POST['newcontent'] ) ) {
[86] Fix | Delete
$posted_content = wp_unslash( $_POST['newcontent'] );
[87] Fix | Delete
}
[88] Fix | Delete
} else {
[89] Fix | Delete
wp_redirect(
[90] Fix | Delete
add_query_arg(
[91] Fix | Delete
array(
[92] Fix | Delete
'a' => 1, // This means "success" for some reason.
[93] Fix | Delete
'plugin' => $plugin,
[94] Fix | Delete
'file' => $file,
[95] Fix | Delete
),
[96] Fix | Delete
admin_url( 'plugin-editor.php' )
[97] Fix | Delete
)
[98] Fix | Delete
);
[99] Fix | Delete
exit;
[100] Fix | Delete
}
[101] Fix | Delete
}
[102] Fix | Delete
[103] Fix | Delete
// List of allowable extensions.
[104] Fix | Delete
$editable_extensions = wp_get_plugin_file_editable_extensions( $plugin );
[105] Fix | Delete
[106] Fix | Delete
if ( ! is_file( $real_file ) ) {
[107] Fix | Delete
wp_die( sprintf( '<p>%s</p>', __( 'File does not exist! Please double check the name and try again.' ) ) );
[108] Fix | Delete
} else {
[109] Fix | Delete
// Get the extension of the file.
[110] Fix | Delete
if ( preg_match( '/\.([^.]+)$/', $real_file, $matches ) ) {
[111] Fix | Delete
$ext = strtolower( $matches[1] );
[112] Fix | Delete
// If extension is not in the acceptable list, skip it.
[113] Fix | Delete
if ( ! in_array( $ext, $editable_extensions, true ) ) {
[114] Fix | Delete
wp_die( sprintf( '<p>%s</p>', __( 'Files of this type are not editable.' ) ) );
[115] Fix | Delete
}
[116] Fix | Delete
}
[117] Fix | Delete
}
[118] Fix | Delete
[119] Fix | Delete
get_current_screen()->add_help_tab(
[120] Fix | Delete
array(
[121] Fix | Delete
'id' => 'overview',
[122] Fix | Delete
'title' => __( 'Overview' ),
[123] Fix | Delete
'content' =>
[124] Fix | Delete
'<p>' . __( 'You can use the plugin 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>' .
[125] Fix | Delete
'<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&#8217;t forget to save your changes (Update File) when you&#8217;re finished.' ) . '</p>' .
[126] Fix | Delete
'<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>' .
[127] Fix | Delete
'<p id="editor-keyboard-trap-help-1">' . __( 'When using a keyboard to navigate:' ) . '</p>' .
[128] Fix | Delete
'<ul>' .
[129] Fix | Delete
'<li id="editor-keyboard-trap-help-2">' . __( 'In the editing area, the Tab key enters a tab character.' ) . '</li>' .
[130] Fix | Delete
'<li id="editor-keyboard-trap-help-3">' . __( 'To move away from this area, press the Esc key followed by the Tab key.' ) . '</li>' .
[131] Fix | Delete
'<li id="editor-keyboard-trap-help-4">' . __( 'Screen reader users: when in forms mode, you may need to press the Esc key twice.' ) . '</li>' .
[132] Fix | Delete
'</ul>' .
[133] Fix | Delete
'<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 plugins, write your own from scratch, or just better understand their anatomy, check out the links below.' ) . '</p>' .
[134] Fix | Delete
( is_network_admin() ? '<p>' . __( 'Any edits to files from this screen will be reflected on all sites in the network.' ) . '</p>' : '' ),
[135] Fix | Delete
)
[136] Fix | Delete
);
[137] Fix | Delete
[138] Fix | Delete
get_current_screen()->set_help_sidebar(
[139] Fix | Delete
'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
[140] Fix | Delete
'<p>' . __( '<a href="https://wordpress.org/support/article/plugins-editor-screen/">Documentation on Editing Plugins</a>' ) . '</p>' .
[141] Fix | Delete
'<p>' . __( '<a href="https://developer.wordpress.org/plugins/">Documentation on Writing Plugins</a>' ) . '</p>' .
[142] Fix | Delete
'<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
[143] Fix | Delete
);
[144] Fix | Delete
[145] Fix | Delete
$settings = array(
[146] Fix | Delete
'codeEditor' => wp_enqueue_code_editor( array( 'file' => $real_file ) ),
[147] Fix | Delete
);
[148] Fix | Delete
wp_enqueue_script( 'wp-theme-plugin-editor' );
[149] Fix | Delete
wp_add_inline_script( 'wp-theme-plugin-editor', sprintf( 'jQuery( function( $ ) { wp.themePluginEditor.init( $( "#template" ), %s ); } )', wp_json_encode( $settings ) ) );
[150] Fix | Delete
wp_add_inline_script( 'wp-theme-plugin-editor', sprintf( 'wp.themePluginEditor.themeOrPlugin = "plugin";' ) );
[151] Fix | Delete
[152] Fix | Delete
require_once ABSPATH . 'wp-admin/admin-header.php';
[153] Fix | Delete
[154] Fix | Delete
update_recently_edited( WP_PLUGIN_DIR . '/' . $file );
[155] Fix | Delete
[156] Fix | Delete
if ( ! empty( $posted_content ) ) {
[157] Fix | Delete
$content = $posted_content;
[158] Fix | Delete
} else {
[159] Fix | Delete
$content = file_get_contents( $real_file );
[160] Fix | Delete
}
[161] Fix | Delete
[162] Fix | Delete
if ( '.php' === substr( $real_file, strrpos( $real_file, '.' ) ) ) {
[163] Fix | Delete
$functions = wp_doc_link_parse( $content );
[164] Fix | Delete
[165] Fix | Delete
if ( ! empty( $functions ) ) {
[166] Fix | Delete
$docs_select = '<select name="docs-list" id="docs-list">';
[167] Fix | Delete
$docs_select .= '<option value="">' . __( 'Function Name&hellip;' ) . '</option>';
[168] Fix | Delete
foreach ( $functions as $function ) {
[169] Fix | Delete
$docs_select .= '<option value="' . esc_attr( $function ) . '">' . esc_html( $function ) . '()</option>';
[170] Fix | Delete
}
[171] Fix | Delete
$docs_select .= '</select>';
[172] Fix | Delete
}
[173] Fix | Delete
}
[174] Fix | Delete
[175] Fix | Delete
$content = esc_textarea( $content );
[176] Fix | Delete
?>
[177] Fix | Delete
<div class="wrap">
[178] Fix | Delete
<h1><?php echo esc_html( $title ); ?></h1>
[179] Fix | Delete
[180] Fix | Delete
<?php if ( isset( $_GET['a'] ) ) : ?>
[181] Fix | Delete
<div id="message" class="updated notice is-dismissible">
[182] Fix | Delete
<p><?php _e( 'File edited successfully.' ); ?></p>
[183] Fix | Delete
</div>
[184] Fix | Delete
<?php elseif ( is_wp_error( $edit_error ) ) : ?>
[185] Fix | Delete
<div id="message" class="notice notice-error">
[186] Fix | Delete
<p><?php _e( 'There was an error while trying to update the file. You may need to fix something and try updating again.' ); ?></p>
[187] Fix | Delete
<pre><?php echo esc_html( $edit_error->get_error_message() ? $edit_error->get_error_message() : $edit_error->get_error_code() ); ?></pre>
[188] Fix | Delete
</div>
[189] Fix | Delete
<?php endif; ?>
[190] Fix | Delete
[191] Fix | Delete
<div class="fileedit-sub">
[192] Fix | Delete
<div class="alignleft">
[193] Fix | Delete
<h2>
[194] Fix | Delete
<?php
[195] Fix | Delete
if ( is_plugin_active( $plugin ) ) {
[196] Fix | Delete
if ( is_writable( $real_file ) ) {
[197] Fix | Delete
/* translators: %s: Plugin file name. */
[198] Fix | Delete
printf( __( 'Editing %s (active)' ), '<strong>' . esc_html( $file ) . '</strong>' );
[199] Fix | Delete
} else {
[200] Fix | Delete
/* translators: %s: Plugin file name. */
[201] Fix | Delete
printf( __( 'Browsing %s (active)' ), '<strong>' . esc_html( $file ) . '</strong>' );
[202] Fix | Delete
}
[203] Fix | Delete
} else {
[204] Fix | Delete
if ( is_writable( $real_file ) ) {
[205] Fix | Delete
/* translators: %s: Plugin file name. */
[206] Fix | Delete
printf( __( 'Editing %s (inactive)' ), '<strong>' . esc_html( $file ) . '</strong>' );
[207] Fix | Delete
} else {
[208] Fix | Delete
/* translators: %s: Plugin file name. */
[209] Fix | Delete
printf( __( 'Browsing %s (inactive)' ), '<strong>' . esc_html( $file ) . '</strong>' );
[210] Fix | Delete
}
[211] Fix | Delete
}
[212] Fix | Delete
?>
[213] Fix | Delete
</h2>
[214] Fix | Delete
</div>
[215] Fix | Delete
<div class="alignright">
[216] Fix | Delete
<form action="plugin-editor.php" method="get">
[217] Fix | Delete
<label for="plugin" id="theme-plugin-editor-selector"><?php _e( 'Select plugin to edit:' ); ?> </label>
[218] Fix | Delete
<select name="plugin" id="plugin">
[219] Fix | Delete
<?php
[220] Fix | Delete
foreach ( $plugins as $plugin_key => $a_plugin ) {
[221] Fix | Delete
$plugin_name = $a_plugin['Name'];
[222] Fix | Delete
if ( $plugin_key === $plugin ) {
[223] Fix | Delete
$selected = " selected='selected'";
[224] Fix | Delete
} else {
[225] Fix | Delete
$selected = '';
[226] Fix | Delete
}
[227] Fix | Delete
$plugin_name = esc_attr( $plugin_name );
[228] Fix | Delete
$plugin_key = esc_attr( $plugin_key );
[229] Fix | Delete
echo "\n\t<option value=\"$plugin_key\" $selected>$plugin_name</option>";
[230] Fix | Delete
}
[231] Fix | Delete
?>
[232] Fix | Delete
</select>
[233] Fix | Delete
<?php submit_button( __( 'Select' ), '', 'Submit', false ); ?>
[234] Fix | Delete
</form>
[235] Fix | Delete
</div>
[236] Fix | Delete
<br class="clear" />
[237] Fix | Delete
</div>
[238] Fix | Delete
[239] Fix | Delete
<div id="templateside">
[240] Fix | Delete
<h2 id="plugin-files-label"><?php _e( 'Plugin Files' ); ?></h2>
[241] Fix | Delete
[242] Fix | Delete
<?php
[243] Fix | Delete
$plugin_editable_files = array();
[244] Fix | Delete
foreach ( $plugin_files as $plugin_file ) {
[245] Fix | Delete
if ( preg_match( '/\.([^.]+)$/', $plugin_file, $matches ) && in_array( $matches[1], $editable_extensions, true ) ) {
[246] Fix | Delete
$plugin_editable_files[] = $plugin_file;
[247] Fix | Delete
}
[248] Fix | Delete
}
[249] Fix | Delete
?>
[250] Fix | Delete
<ul role="tree" aria-labelledby="plugin-files-label">
[251] Fix | Delete
<li role="treeitem" tabindex="-1" aria-expanded="true" aria-level="1" aria-posinset="1" aria-setsize="1">
[252] Fix | Delete
<ul role="group">
[253] Fix | Delete
<?php wp_print_plugin_file_tree( wp_make_plugin_file_tree( $plugin_editable_files ) ); ?>
[254] Fix | Delete
</ul>
[255] Fix | Delete
</ul>
[256] Fix | Delete
</div>
[257] Fix | Delete
[258] Fix | Delete
<form name="template" id="template" action="plugin-editor.php" method="post">
[259] Fix | Delete
<?php wp_nonce_field( 'edit-plugin_' . $file, 'nonce' ); ?>
[260] Fix | Delete
<div>
[261] Fix | Delete
<label for="newcontent" id="theme-plugin-editor-label"><?php _e( 'Selected file content:' ); ?></label>
[262] Fix | Delete
<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] Fix | Delete
<input type="hidden" name="action" value="update" />
[264] Fix | Delete
<input type="hidden" name="file" value="<?php echo esc_attr( $file ); ?>" />
[265] Fix | Delete
<input type="hidden" name="plugin" value="<?php echo esc_attr( $plugin ); ?>" />
[266] Fix | Delete
</div>
[267] Fix | Delete
[268] Fix | Delete
<?php if ( ! empty( $docs_select ) ) : ?>
[269] Fix | Delete
<div id="documentation" class="hide-if-no-js">
[270] Fix | Delete
<label for="docs-list"><?php _e( 'Documentation:' ); ?></label>
[271] Fix | Delete
<?php echo $docs_select; ?>
[272] Fix | Delete
<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() ) + '&amp;locale=<?php echo urlencode( get_user_locale() ); ?>&amp;version=<?php echo urlencode( get_bloginfo( 'version' ) ); ?>&amp;redirect=true'); }" />
[273] Fix | Delete
</div>
[274] Fix | Delete
<?php endif; ?>
[275] Fix | Delete
[276] Fix | Delete
<?php if ( is_writable( $real_file ) ) : ?>
[277] Fix | Delete
<div class="editor-notices">
[278] Fix | Delete
<?php if ( in_array( $plugin, (array) get_option( 'active_plugins', array() ), true ) ) { ?>
[279] Fix | Delete
<div class="notice notice-warning inline active-plugin-edit-warning">
[280] Fix | Delete
<p><?php _e( '<strong>Warning:</strong> Making changes to active plugins is not recommended.' ); ?></p>
[281] Fix | Delete
</div>
[282] Fix | Delete
<?php } ?>
[283] Fix | Delete
</div>
[284] Fix | Delete
<p class="submit">
[285] Fix | Delete
<?php submit_button( __( 'Update File' ), 'primary', 'submit', false ); ?>
[286] Fix | Delete
<span class="spinner"></span>
[287] Fix | Delete
</p>
[288] Fix | Delete
<?php else : ?>
[289] Fix | Delete
<p>
[290] Fix | Delete
<?php
[291] Fix | Delete
printf(
[292] Fix | Delete
/* translators: %s: Documentation URL. */
[293] Fix | Delete
__( 'You need to make this file writable before you can save your changes. See <a href="%s">Changing File Permissions</a> for more information.' ),
[294] Fix | Delete
__( 'https://wordpress.org/support/article/changing-file-permissions/' )
[295] Fix | Delete
);
[296] Fix | Delete
?>
[297] Fix | Delete
</p>
[298] Fix | Delete
<?php endif; ?>
[299] Fix | Delete
[300] Fix | Delete
<?php wp_print_file_editor_templates(); ?>
[301] Fix | Delete
</form>
[302] Fix | Delete
<br class="clear" />
[303] Fix | Delete
</div>
[304] Fix | Delete
<?php
[305] Fix | Delete
$dismissed_pointers = explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) );
[306] Fix | Delete
if ( ! in_array( 'plugin_editor_notice', $dismissed_pointers, true ) ) :
[307] Fix | Delete
// Get a back URL.
[308] Fix | Delete
$referer = wp_get_referer();
[309] Fix | Delete
[310] Fix | Delete
$excluded_referer_basenames = array( 'plugin-editor.php', 'wp-login.php' );
[311] Fix | Delete
[312] Fix | Delete
if ( $referer && ! in_array( basename( parse_url( $referer, PHP_URL_PATH ) ), $excluded_referer_basenames, true ) ) {
[313] Fix | Delete
$return_url = $referer;
[314] Fix | Delete
} else {
[315] Fix | Delete
$return_url = admin_url( '/' );
[316] Fix | Delete
}
[317] Fix | Delete
?>
[318] Fix | Delete
<div id="file-editor-warning" class="notification-dialog-wrap file-editor-warning hide-if-no-js hidden">
[319] Fix | Delete
<div class="notification-dialog-background"></div>
[320] Fix | Delete
<div class="notification-dialog">
[321] Fix | Delete
<div class="file-editor-warning-content">
[322] Fix | Delete
<div class="file-editor-warning-message">
[323] Fix | Delete
<h1><?php _e( 'Heads up!' ); ?></h1>
[324] Fix | Delete
<p><?php _e( 'You appear to be making direct edits to your plugin in the WordPress dashboard. We recommend that you don&#8217;t! Editing plugins directly may introduce incompatibilities that break your site and your changes may be lost in future updates.' ); ?></p>
[325] Fix | Delete
<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>
[326] Fix | Delete
</div>
[327] Fix | Delete
<p>
[328] Fix | Delete
<a class="button file-editor-warning-go-back" href="<?php echo esc_url( $return_url ); ?>"><?php _e( 'Go back' ); ?></a>
[329] Fix | Delete
<button type="button" class="file-editor-warning-dismiss button button-primary"><?php _e( 'I understand' ); ?></button>
[330] Fix | Delete
</p>
[331] Fix | Delete
</div>
[332] Fix | Delete
</div>
[333] Fix | Delete
</div>
[334] Fix | Delete
<?php
[335] Fix | Delete
endif; // Editor warning notice.
[336] Fix | Delete
[337] Fix | Delete
require_once ABSPATH . 'wp-admin/admin-footer.php';
[338] Fix | Delete
[339] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function