Make WordPress Core

Changeset 11788


Ignore:
Timestamp:
08/08/2009 07:22:19 AM (15 years ago)
Author:
azaozz
Message:

Scroll back to the same location after saving a file in the Plugin and Theme editors

Location:
trunk/wp-admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/plugin-editor.php

    r11671 r11788  
    1010require_once('admin.php');
    1111
     12if ( !current_user_can('edit_plugins') )
     13    wp_die('<p>'.__('You do not have sufficient permissions to edit plugins for this blog.').'</p>');
     14
    1215$title = __("Edit Plugins");
    1316$parent_file = 'plugins.php';
     
    3437$file = validate_file_to_edit($file, $plugin_files);
    3538$real_file = WP_PLUGIN_DIR . '/' . $file;
     39$scrollto = isset($_REQUEST['scrollto']) ? (int) $_REQUEST['scrollto'] : 0;
    3640
    3741switch ( $action ) {
     
    4044
    4145    check_admin_referer('edit-plugin_' . $file);
    42 
    43     if ( !current_user_can('edit_plugins') )
    44         wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this blog.').'</p>');
    4546
    4647    $newcontent = stripslashes($_POST['newcontent']);
     
    5455            if ( is_plugin_active($file) )
    5556                deactivate_plugins($file, true);
    56             wp_redirect(add_query_arg('_wpnonce', wp_create_nonce('edit-plugin-test_' . $file), "plugin-editor.php?file=$file&liveupdate=1"));
     57            wp_redirect(add_query_arg('_wpnonce', wp_create_nonce('edit-plugin-test_' . $file), "plugin-editor.php?file=$file&liveupdate=1&scrollto=$scrollto"));
    5758            exit;
    5859        }
    59         wp_redirect("plugin-editor.php?file=$file&a=te");
    60     } else {
    61         wp_redirect("plugin-editor.php?file=$file");
     60        wp_redirect("plugin-editor.php?file=$file&a=te&scrollto=$scrollto");
     61    } else {
     62        wp_redirect("plugin-editor.php?file=$file&scrollto=$scrollto");
    6263    }
    6364    exit;
     
    6667
    6768default:
    68 
    69     if ( !current_user_can('edit_plugins') )
    70         wp_die('<p>'.__('You do not have sufficient permissions to edit plugins for this blog.').'</p>');
    7169
    7270    if ( isset($_GET['liveupdate']) ) {
     
    8078            activate_plugin($file, "plugin-editor.php?file=$file&phperror=1"); // we'll override this later if the plugin can be included without fatal error
    8179
    82         wp_redirect("plugin-editor.php?file=$file&a=te");
     80        wp_redirect("plugin-editor.php?file=$file&a=te&scrollto=$scrollto");
    8381        exit;
    8482    }
     
    206204        <input type="hidden" name="file" value="<?php echo esc_attr($file) ?>" />
    207205        <input type="hidden" name="plugin" value="<?php echo esc_attr($plugin) ?>" />
     206        <input type="hidden" name="scrollto" id="scrollto" value="<?php echo $scrollto; ?>" />
    208207        </div>
    209208        <?php if ( !empty( $docs_select ) ) : ?>
     
    228227<br class="clear" />
    229228</div>
     229<script type="text/javascript">
     230/* <![CDATA[ */
     231jQuery(document).ready(function($){
     232    $('#template').submit(function(){ $('#scrollto').val( $('#newcontent').scrollTop() ); });
     233    $('#newcontent').scrollTop( $('#scrollto').val() );
     234});
     235/* ]]> */
     236</script>
    230237<?php
    231238    break;
  • trunk/wp-admin/theme-editor.php

    r11647 r11788  
    1010require_once('admin.php');
    1111
     12if ( !current_user_can('edit_themes') )
     13    wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this blog.').'</p>');
     14
    1215$title = __("Edit Themes");
    1316$parent_file = 'themes.php';
     
    3740$file = validate_file_to_edit($file, $allowed_files);
    3841$real_file = get_real_file_to_edit($file);
     42$scrollto = isset($_REQUEST['scrollto']) ? (int) $_REQUEST['scrollto'] : 0;
    3943
    4044$file_show = basename( $file );
     
    4549
    4650    check_admin_referer('edit-theme_' . $file . $theme);
    47 
    48     if ( !current_user_can('edit_themes') )
    49         wp_die('<p>'.__('You do not have sufficient permissions to edit templates for this blog.').'</p>');
    5051
    5152    $newcontent = stripslashes($_POST['newcontent']);
     
    5758            fwrite($f, $newcontent);
    5859            fclose($f);
    59             $location = "theme-editor.php?file=$file&theme=$theme&a=te";
     60            $location = "theme-editor.php?file=$file&theme=$theme&a=te&scrollto=$scrollto";
    6061        } else {
    61             $location = "theme-editor.php?file=$file&theme=$theme";
     62            $location = "theme-editor.php?file=$file&theme=$theme&scrollto=$scrollto";
    6263        }
    6364    } else {
    64         $location = "theme-editor.php?file=$file&theme=$theme";
     65        $location = "theme-editor.php?file=$file&theme=$theme&scrollto=$scrollto";
    6566    }
    6667
     
    7475
    7576default:
    76 
    77     if ( !current_user_can('edit_themes') )
    78         wp_die('<p>'.__('You do not have sufficient permissions to edit themes for this blog.').'</p>');
    7977
    8078    if ( use_codepress() )
     
    202200         <input type="hidden" name="file" value="<?php echo esc_attr($file) ?>" />
    203201         <input type="hidden" name="theme" value="<?php echo esc_attr($theme) ?>" />
     202         <input type="hidden" name="scrollto" id="scrollto" value="<?php echo $scrollto; ?>" />
    204203         </div>
    205204    <?php if ( isset($functions ) && count($functions) ) { ?>
     
    230229<br class="clear" />
    231230</div>
     231<script type="text/javascript">
     232/* <![CDATA[ */
     233jQuery(document).ready(function($){
     234    $('#template').submit(function(){ $('#scrollto').val( $('#newcontent').scrollTop() ); });
     235    $('#newcontent').scrollTop( $('#scrollto').val() );
     236});
     237/* ]]> */
     238</script>
    232239<?php
    233240break;
Note: See TracChangeset for help on using the changeset viewer.