wp/wp-admin/plugin-editor.php
author ymh <ymh.work@gmail.com>
Tue, 09 Jun 2015 03:35:32 +0200
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
permissions -rw-r--r--
upgrade wordpress + plugins
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * Edit plugin editor administration panel.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 * @subpackage Administration
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
/** WordPress Administration Bootstrap */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
require_once( dirname( __FILE__ ) . '/admin.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
if ( is_multisite() && ! is_network_admin() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
	wp_redirect( network_admin_url( 'plugin-editor.php' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
	exit();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
if ( !current_user_can('edit_plugins') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
	wp_die( __('You do not have sufficient permissions to edit plugins for this site.') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
$title = __("Edit Plugins");
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
$parent_file = 'plugins.php';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
wp_reset_vars( array( 'action', 'error', 'file', 'plugin' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
$plugins = get_plugins();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    27
if ( empty( $plugins ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    28
	include( ABSPATH . 'wp-admin/admin-header.php' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    29
	?>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    30
	<div class="wrap">
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    31
		<h2><?php echo esc_html( $title ); ?></h2>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    32
		<div id="message" class="error"><p><?php _e( 'You do not appear to have any plugins available at this time.' ); ?></p></div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    33
	</div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    34
	<?php
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    35
	include( ABSPATH . 'wp-admin/admin-footer.php' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    36
	exit;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    37
}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
if ( $file ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
	$plugin = $file;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
} elseif ( empty( $plugin ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
	$plugin = array_keys($plugins);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
	$plugin = $plugin[0];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
$plugin_files = get_plugin_files($plugin);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
if ( empty($file) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
	$file = $plugin_files[0];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
$file = validate_file_to_edit($file, $plugin_files);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
$real_file = WP_PLUGIN_DIR . '/' . $file;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
$scrollto = isset($_REQUEST['scrollto']) ? (int) $_REQUEST['scrollto'] : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
switch ( $action ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
case 'update':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
	check_admin_referer('edit-plugin_' . $file);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
	$newcontent = wp_unslash( $_POST['newcontent'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
	if ( is_writeable($real_file) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
		$f = fopen($real_file, 'w+');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
		fwrite($f, $newcontent);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
		fclose($f);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
		$network_wide = is_plugin_active_for_network( $file );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
		// Deactivate so we can test it.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
		if ( is_plugin_active($file) || isset($_POST['phperror']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
			if ( is_plugin_active($file) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
				deactivate_plugins($file, true);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
			if ( ! is_network_admin() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
				update_option( 'recently_activated', array( $file => time() ) + (array) get_option( 'recently_activated' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
			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));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
			exit;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
		wp_redirect( self_admin_url("plugin-editor.php?file=$file&a=te&scrollto=$scrollto") );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
		wp_redirect( self_admin_url("plugin-editor.php?file=$file&scrollto=$scrollto") );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
	exit;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
default:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
	if ( isset($_GET['liveupdate']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
		check_admin_referer('edit-plugin-test_' . $file);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
		$error = validate_plugin($file);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
		if ( is_wp_error($error) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
			wp_die( $error );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
		if ( ( ! empty( $_GET['networkwide'] ) && ! is_plugin_active_for_network($file) ) || ! is_plugin_active($file) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
			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
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
		wp_redirect( self_admin_url("plugin-editor.php?file=$file&a=te&scrollto=$scrollto") );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
		exit;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
	// List of allowable extensions
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
	$editable_extensions = array('php', 'txt', 'text', 'js', 'css', 'html', 'htm', 'xml', 'inc', 'include');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
	 * Filter file type extensions editable in the plugin editor.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
	 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
	 * @param array $editable_extensions An array of editable plugin file extensions.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
	$editable_extensions = (array) apply_filters( 'editable_extensions', $editable_extensions );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
	if ( ! is_file($real_file) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
		wp_die(sprintf('<p>%s</p>', __('No such file exists! Double check the name and try again.')));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
		// Get the extension of the file
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
		if ( preg_match('/\.([^.]+)$/', $real_file, $matches) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
			$ext = strtolower($matches[1]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
			// If extension is not in the acceptable list, skip it
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
			if ( !in_array( $ext, $editable_extensions) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
				wp_die(sprintf('<p>%s</p>', __('Files of this type are not editable.')));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
	get_current_screen()->add_help_tab( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
	'id'		=> 'overview',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
	'title'		=> __('Overview'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
	'content'	=>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
		'<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>' .
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
		'<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>' .
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
		'<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>' .
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   133
		'<p id="newcontent-description">' . __( 'In the editing area the Tab key enters a tab character. To move below this area by pressing Tab, press the Esc key followed by the Tab key. In some cases the Esc key will need to be pressed twice before the Tab key will allow you to continue.' ) . '</p>' .
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
		'<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>' .
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
		( is_network_admin() ? '<p>' . __('Any edits to files from this screen will be reflected on all sites in the network.') . '</p>' : '' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
	) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
	get_current_screen()->set_help_sidebar(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
		'<p><strong>' . __('For more information:') . '</strong></p>' .
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   140
		'<p>' . __('<a href="https://codex.wordpress.org/Plugins_Editor_Screen" target="_blank">Documentation on Editing Plugins</a>') . '</p>' .
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   141
		'<p>' . __('<a href="https://codex.wordpress.org/Writing_a_Plugin" target="_blank">Documentation on Writing Plugins</a>') . '</p>' .
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   142
		'<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
	);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
	require_once(ABSPATH . 'wp-admin/admin-header.php');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
	update_recently_edited(WP_PLUGIN_DIR . '/' . $file);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
	$content = file_get_contents( $real_file );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
	if ( '.php' == substr( $real_file, strrpos( $real_file, '.' ) ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
		$functions = wp_doc_link_parse( $content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
		if ( !empty($functions) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
			$docs_select = '<select name="docs-list" id="docs-list">';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
			$docs_select .= '<option value="">' . __( 'Function Name&hellip;' ) . '</option>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
			foreach ( $functions as $function) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
				$docs_select .= '<option value="' . esc_attr( $function ) . '">' . esc_html( $function ) . '()</option>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
			$docs_select .= '</select>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
	$content = esc_textarea( $content );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
	?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
<?php if (isset($_GET['a'])) : ?>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   167
 <div id="message" class="updated notice is-dismissible"><p><?php _e('File edited successfully.') ?></p></div>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
<?php elseif (isset($_GET['phperror'])) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
 <div id="message" class="updated"><p><?php _e('This plugin has been deactivated because your changes resulted in a <strong>fatal error</strong>.') ?></p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
		if ( wp_verify_nonce($_GET['_error_nonce'], 'plugin-activation-error_' . $file) ) { ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
	<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>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
	<?php } ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
<?php endif; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
<div class="wrap">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
<h2><?php echo esc_html( $title ); ?></h2>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
<div class="fileedit-sub">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
<div class="alignleft">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
<big><?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
	if ( is_plugin_active($plugin) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
		if ( is_writeable($real_file) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
			echo sprintf(__('Editing <strong>%s</strong> (active)'), $file);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
			echo sprintf(__('Browsing <strong>%s</strong> (active)'), $file);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
		if ( is_writeable($real_file) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
			echo sprintf(__('Editing <strong>%s</strong> (inactive)'), $file);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
			echo sprintf(__('Browsing <strong>%s</strong> (inactive)'), $file);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
	?></big>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
<div class="alignright">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
	<form action="plugin-editor.php" method="post">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
		<strong><label for="plugin"><?php _e('Select plugin to edit:'); ?> </label></strong>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
		<select name="plugin" id="plugin">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
	foreach ( $plugins as $plugin_key => $a_plugin ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
		$plugin_name = $a_plugin['Name'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
		if ( $plugin_key == $plugin )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
			$selected = " selected='selected'";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
			$selected = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
		$plugin_name = esc_attr($plugin_name);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
		$plugin_key = esc_attr($plugin_key);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
		echo "\n\t<option value=\"$plugin_key\" $selected>$plugin_name</option>";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
		</select>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
		<?php submit_button( __( 'Select' ), 'button', 'Submit', false ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
	</form>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
<br class="clear" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
<div id="templateside">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
	<h3><?php _e('Plugin Files'); ?></h3>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
	<ul>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
foreach ( $plugin_files as $plugin_file ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
	// Get the extension of the file
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
	if ( preg_match('/\.([^.]+)$/', $plugin_file, $matches) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
		$ext = strtolower($matches[1]);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
		// If extension is not in the acceptable list, skip it
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
		if ( !in_array( $ext, $editable_extensions ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
			continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
		// No extension found
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
		continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
		<li<?php echo $file == $plugin_file ? ' class="highlight"' : ''; ?>><a href="plugin-editor.php?file=<?php echo urlencode( $plugin_file ) ?>&amp;plugin=<?php echo urlencode( $plugin ) ?>"><?php echo $plugin_file ?></a></li>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
<?php endforeach; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
	</ul>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
<form name="template" id="template" action="plugin-editor.php" method="post">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
	<?php wp_nonce_field('edit-plugin_' . $file) ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
		<div><textarea cols="70" rows="25" name="newcontent" id="newcontent" aria-describedby="newcontent-description"><?php echo $content; ?></textarea>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
		<input type="hidden" name="action" value="update" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
		<input type="hidden" name="file" value="<?php echo esc_attr($file) ?>" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
		<input type="hidden" name="plugin" value="<?php echo esc_attr($plugin) ?>" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
		<input type="hidden" name="scrollto" id="scrollto" value="<?php echo $scrollto; ?>" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
		</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
		<?php if ( !empty( $docs_select ) ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
		<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( '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>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
		<?php endif; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
<?php if ( is_writeable($real_file) ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
	<?php if ( in_array( $file, (array) get_option( 'active_plugins', array() ) ) ) { ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
		<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>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
	<?php } ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
	<p class="submit">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
		if ( isset($_GET['phperror']) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
			echo "<input type='hidden' name='phperror' value='1' />";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
			submit_button( __( 'Update File and Attempt to Reactivate' ), 'primary', 'submit', false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
			submit_button( __( 'Update File' ), 'primary', 'submit', false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
	?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
	</p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
<?php else : ?>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   265
	<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>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
<?php endif; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
</form>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
<br class="clear" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
<script type="text/javascript">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
jQuery(document).ready(function($){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
	$('#template').submit(function(){ $('#scrollto').val( $('#newcontent').scrollTop() ); });
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
	$('#newcontent').scrollTop( $('#scrollto').val() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
</script>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
	break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
include(ABSPATH . "wp-admin/admin-footer.php");