<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre, #msg p { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[11788] trunk/wp-admin:
  Scroll back to the same location after saving a file in the Plugin and Theme editors</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/11788">11788</a></dd>
<dt>Author</dt> <dd>azaozz</dd>
<dt>Date</dt> <dd>2009-08-08 07:22:19 +0000 (Sat, 08 Aug 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>Scroll back to the same location after saving a file in the Plugin and Theme editors</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminplugineditorphp">trunk/wp-admin/plugin-editor.php</a></li>
<li><a href="#trunkwpadminthemeeditorphp">trunk/wp-admin/theme-editor.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminplugineditorphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/plugin-editor.php (11787 => 11788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/plugin-editor.php        2009-08-07 17:17:40 UTC (rev 11787)
+++ trunk/wp-admin/plugin-editor.php        2009-08-08 07:22:19 UTC (rev 11788)
</span><span class="lines">@@ -9,6 +9,9 @@
</span><span class="cx"> /** WordPress Administration Bootstrap */
</span><span class="cx"> require_once('admin.php');
</span><span class="cx"> 
</span><ins>+if ( !current_user_can('edit_plugins') )
+        wp_die('&lt;p&gt;'.__('You do not have sufficient permissions to edit plugins for this blog.').'&lt;/p&gt;');
+
</ins><span class="cx"> $title = __(&quot;Edit Plugins&quot;);
</span><span class="cx"> $parent_file = 'plugins.php';
</span><span class="cx"> 
</span><span class="lines">@@ -33,6 +36,7 @@
</span><span class="cx"> 
</span><span class="cx"> $file = validate_file_to_edit($file, $plugin_files);
</span><span class="cx"> $real_file = WP_PLUGIN_DIR . '/' . $file;
</span><ins>+$scrollto = isset($_REQUEST['scrollto']) ? (int) $_REQUEST['scrollto'] : 0;
</ins><span class="cx"> 
</span><span class="cx"> switch ( $action ) {
</span><span class="cx"> 
</span><span class="lines">@@ -40,9 +44,6 @@
</span><span class="cx"> 
</span><span class="cx">         check_admin_referer('edit-plugin_' . $file);
</span><span class="cx"> 
</span><del>-        if ( !current_user_can('edit_plugins') )
-                wp_die('&lt;p&gt;'.__('You do not have sufficient permissions to edit templates for this blog.').'&lt;/p&gt;');
-
</del><span class="cx">         $newcontent = stripslashes($_POST['newcontent']);
</span><span class="cx">         if ( is_writeable($real_file) ) {
</span><span class="cx">                 $f = fopen($real_file, 'w+');
</span><span class="lines">@@ -53,12 +54,12 @@
</span><span class="cx">                 if ( is_plugin_active($file) || isset($_POST['phperror']) ) {
</span><span class="cx">                         if ( is_plugin_active($file) )
</span><span class="cx">                                 deactivate_plugins($file, true);
</span><del>-                        wp_redirect(add_query_arg('_wpnonce', wp_create_nonce('edit-plugin-test_' . $file), &quot;plugin-editor.php?file=$file&amp;liveupdate=1&quot;));
</del><ins>+                        wp_redirect(add_query_arg('_wpnonce', wp_create_nonce('edit-plugin-test_' . $file), &quot;plugin-editor.php?file=$file&amp;liveupdate=1&amp;scrollto=$scrollto&quot;));
</ins><span class="cx">                         exit;
</span><span class="cx">                 }
</span><del>-                wp_redirect(&quot;plugin-editor.php?file=$file&amp;a=te&quot;);
</del><ins>+                wp_redirect(&quot;plugin-editor.php?file=$file&amp;a=te&amp;scrollto=$scrollto&quot;);
</ins><span class="cx">         } else {
</span><del>-                wp_redirect(&quot;plugin-editor.php?file=$file&quot;);
</del><ins>+                wp_redirect(&quot;plugin-editor.php?file=$file&amp;scrollto=$scrollto&quot;);
</ins><span class="cx">         }
</span><span class="cx">         exit;
</span><span class="cx"> 
</span><span class="lines">@@ -66,9 +67,6 @@
</span><span class="cx"> 
</span><span class="cx"> default:
</span><span class="cx"> 
</span><del>-        if ( !current_user_can('edit_plugins') )
-                wp_die('&lt;p&gt;'.__('You do not have sufficient permissions to edit plugins for this blog.').'&lt;/p&gt;');
-
</del><span class="cx">         if ( isset($_GET['liveupdate']) ) {
</span><span class="cx">                 check_admin_referer('edit-plugin-test_' . $file);
</span><span class="cx"> 
</span><span class="lines">@@ -79,7 +77,7 @@
</span><span class="cx">                 if ( ! is_plugin_active($file) )
</span><span class="cx">                         activate_plugin($file, &quot;plugin-editor.php?file=$file&amp;phperror=1&quot;); // we'll override this later if the plugin can be included without fatal error
</span><span class="cx"> 
</span><del>-                wp_redirect(&quot;plugin-editor.php?file=$file&amp;a=te&quot;);
</del><ins>+                wp_redirect(&quot;plugin-editor.php?file=$file&amp;a=te&amp;scrollto=$scrollto&quot;);
</ins><span class="cx">                 exit;
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -205,6 +203,7 @@
</span><span class="cx">                 &lt;input type=&quot;hidden&quot; name=&quot;action&quot; value=&quot;update&quot; /&gt;
</span><span class="cx">                 &lt;input type=&quot;hidden&quot; name=&quot;file&quot; value=&quot;&lt;?php echo esc_attr($file) ?&gt;&quot; /&gt;
</span><span class="cx">                 &lt;input type=&quot;hidden&quot; name=&quot;plugin&quot; value=&quot;&lt;?php echo esc_attr($plugin) ?&gt;&quot; /&gt;
</span><ins>+                &lt;input type=&quot;hidden&quot; name=&quot;scrollto&quot; id=&quot;scrollto&quot; value=&quot;&lt;?php echo $scrollto; ?&gt;&quot; /&gt;
</ins><span class="cx">                 &lt;/div&gt;
</span><span class="cx">                 &lt;?php if ( !empty( $docs_select ) ) : ?&gt;
</span><span class="cx">                 &lt;div id=&quot;documentation&quot;&gt;&lt;label for=&quot;docs-list&quot;&gt;&lt;?php _e('Documentation:') ?&gt;&lt;/label&gt; &lt;?php echo $docs_select ?&gt; &lt;input type=&quot;button&quot; class=&quot;button&quot; value=&quot;&lt;?php esc_attr_e( 'Lookup' ) ?&gt; &quot; onclick=&quot;if ( '' != jQuery('#docs-list').val() ) { window.open( 'http://api.wordpress.org/core/handbook/1.0/?function=' + escape( jQuery( '#docs-list' ).val() ) + '&amp;amp;locale=&lt;?php echo urlencode( get_locale() ) ?&gt;&amp;amp;version=&lt;?php echo urlencode( $wp_version ) ?&gt;&amp;amp;redirect=true'); }&quot; /&gt;&lt;/div&gt;
</span><span class="lines">@@ -227,6 +226,14 @@
</span><span class="cx"> &lt;/form&gt;
</span><span class="cx"> &lt;br class=&quot;clear&quot; /&gt;
</span><span class="cx"> &lt;/div&gt;
</span><ins>+&lt;script type=&quot;text/javascript&quot;&gt;
+/* &lt;![CDATA[ */
+jQuery(document).ready(function($){
+        $('#template').submit(function(){ $('#scrollto').val( $('#newcontent').scrollTop() ); });
+        $('#newcontent').scrollTop( $('#scrollto').val() );
+});
+/* ]]&gt; */
+&lt;/script&gt;
</ins><span class="cx"> &lt;?php
</span><span class="cx">         break;
</span><span class="cx"> }
</span></span></pre></div>
<a id="trunkwpadminthemeeditorphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/theme-editor.php (11787 => 11788)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/theme-editor.php        2009-08-07 17:17:40 UTC (rev 11787)
+++ trunk/wp-admin/theme-editor.php        2009-08-08 07:22:19 UTC (rev 11788)
</span><span class="lines">@@ -9,6 +9,9 @@
</span><span class="cx"> /** WordPress Administration Bootstrap */
</span><span class="cx"> require_once('admin.php');
</span><span class="cx"> 
</span><ins>+if ( !current_user_can('edit_themes') )
+        wp_die('&lt;p&gt;'.__('You do not have sufficient permissions to edit templates for this blog.').'&lt;/p&gt;');
+
</ins><span class="cx"> $title = __(&quot;Edit Themes&quot;);
</span><span class="cx"> $parent_file = 'themes.php';
</span><span class="cx"> 
</span><span class="lines">@@ -36,6 +39,7 @@
</span><span class="cx"> 
</span><span class="cx"> $file = validate_file_to_edit($file, $allowed_files);
</span><span class="cx"> $real_file = get_real_file_to_edit($file);
</span><ins>+$scrollto = isset($_REQUEST['scrollto']) ? (int) $_REQUEST['scrollto'] : 0;
</ins><span class="cx"> 
</span><span class="cx"> $file_show = basename( $file );
</span><span class="cx"> 
</span><span class="lines">@@ -45,9 +49,6 @@
</span><span class="cx"> 
</span><span class="cx">         check_admin_referer('edit-theme_' . $file . $theme);
</span><span class="cx"> 
</span><del>-        if ( !current_user_can('edit_themes') )
-                wp_die('&lt;p&gt;'.__('You do not have sufficient permissions to edit templates for this blog.').'&lt;/p&gt;');
-
</del><span class="cx">         $newcontent = stripslashes($_POST['newcontent']);
</span><span class="cx">         $theme = urlencode($theme);
</span><span class="cx">         if (is_writeable($real_file)) {
</span><span class="lines">@@ -56,12 +57,12 @@
</span><span class="cx">                 if ($f !== FALSE) {
</span><span class="cx">                         fwrite($f, $newcontent);
</span><span class="cx">                         fclose($f);
</span><del>-                        $location = &quot;theme-editor.php?file=$file&amp;theme=$theme&amp;a=te&quot;;
</del><ins>+                        $location = &quot;theme-editor.php?file=$file&amp;theme=$theme&amp;a=te&amp;scrollto=$scrollto&quot;;
</ins><span class="cx">                 } else {
</span><del>-                        $location = &quot;theme-editor.php?file=$file&amp;theme=$theme&quot;;
</del><ins>+                        $location = &quot;theme-editor.php?file=$file&amp;theme=$theme&amp;scrollto=$scrollto&quot;;
</ins><span class="cx">                 }
</span><span class="cx">         } else {
</span><del>-                $location = &quot;theme-editor.php?file=$file&amp;theme=$theme&quot;;
</del><ins>+                $location = &quot;theme-editor.php?file=$file&amp;theme=$theme&amp;scrollto=$scrollto&quot;;
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         $location = wp_kses_no_null($location);
</span><span class="lines">@@ -74,9 +75,6 @@
</span><span class="cx"> 
</span><span class="cx"> default:
</span><span class="cx"> 
</span><del>-        if ( !current_user_can('edit_themes') )
-                wp_die('&lt;p&gt;'.__('You do not have sufficient permissions to edit themes for this blog.').'&lt;/p&gt;');
-
</del><span class="cx">         if ( use_codepress() )
</span><span class="cx">                 wp_enqueue_script( 'codepress' );
</span><span class="cx"> 
</span><span class="lines">@@ -201,6 +199,7 @@
</span><span class="cx">                  &lt;input type=&quot;hidden&quot; name=&quot;action&quot; value=&quot;update&quot; /&gt;
</span><span class="cx">                  &lt;input type=&quot;hidden&quot; name=&quot;file&quot; value=&quot;&lt;?php echo esc_attr($file) ?&gt;&quot; /&gt;
</span><span class="cx">                  &lt;input type=&quot;hidden&quot; name=&quot;theme&quot; value=&quot;&lt;?php echo esc_attr($theme) ?&gt;&quot; /&gt;
</span><ins>+                 &lt;input type=&quot;hidden&quot; name=&quot;scrollto&quot; id=&quot;scrollto&quot; value=&quot;&lt;?php echo $scrollto; ?&gt;&quot; /&gt;
</ins><span class="cx">                  &lt;/div&gt;
</span><span class="cx">         &lt;?php if ( isset($functions ) &amp;&amp; count($functions) ) { ?&gt;
</span><span class="cx">                 &lt;div id=&quot;documentation&quot;&gt;
</span><span class="lines">@@ -229,6 +228,14 @@
</span><span class="cx"> ?&gt;
</span><span class="cx"> &lt;br class=&quot;clear&quot; /&gt;
</span><span class="cx"> &lt;/div&gt;
</span><ins>+&lt;script type=&quot;text/javascript&quot;&gt;
+/* &lt;![CDATA[ */
+jQuery(document).ready(function($){
+        $('#template').submit(function(){ $('#scrollto').val( $('#newcontent').scrollTop() ); });
+        $('#newcontent').scrollTop( $('#scrollto').val() );
+});
+/* ]]&gt; */
+&lt;/script&gt;
</ins><span class="cx"> &lt;?php
</span><span class="cx"> break;
</span><span class="cx"> }
</span></span></pre>
</div>
</div>

</body>
</html>