WordPress.org

Make WordPress Core

Ticket #3068: normalize_working_directory.patch

File normalize_working_directory.patch, 1.2 KB (added by shadytrees, 15 years ago)

Example patch (just for generating ideas) 3: moving outside the foreach loop

  • wp-includes/plugin.php

     
    3333        if ( !isset($wp_filter[$tag]) ) {
    3434                return $string;
    3535        }
     36       
     37        $wd = getcwd();
     38       
     39        // Normalize the working directory for plug-ins.
     40        // This takes us to Wordpress' root directory.
     41        chdir(dirname(__FILE__) . '/..');
    3642        foreach ($wp_filter[$tag] as $priority => $functions) {
    3743                if ( !is_null($functions) ) {
    3844                        foreach($functions as $function) {
     
    5460                        }
    5561                }
    5662        }
     63        // Un-normalize for everybody else.
     64        chdir($wd);
    5765        return $string;
    5866}
    5967
     
    113121        if ( !isset($wp_filter[$tag]) ) {
    114122                return;
    115123        }
     124
     125        $wd = getcwd();
     126               
     127        // Normalize the working directory for plug-ins.
     128        // This takes us to Wordpress' root directory.
     129        chdir(dirname(__FILE__) . '/..');       
    116130        foreach ($wp_filter[$tag] as $priority => $functions) {
    117131                if ( !is_null($functions) ) {
    118132                        foreach($functions as $function) {
     
    137151                        }
    138152                }
    139153        }
     154        // Un-normalize for everybody else.
     155        chdir($wd);
    140156}
    141157
    142158function remove_action($tag, $function_to_remove, $priority = 10, $accepted_args = 1) {