100) { if (function_exists('set_transient')) { set_transient('wpsc_config_error', 'config_file_not_loaded', 10); } trigger_error("wp_config_file_replace_line: Error - file $my_file could not be loaded."); return false; } } } foreach ((array)$lines as $line) { if (trim($new) != '' && trim($new) == trim($line)) { pressable_cache_extend("wp_config_file_replace_line: setting not changed - $new"); return true; } elseif (preg_match("/$old/", $line)) { pressable_cache_extend("wp_config_file_replace_line: changing line " . trim($line) . " to *$new*"); $found = true; } } global $cache_path; $tmp_config_filename = tempnam($GLOBALS['cache_path'], 'wpsc'); rename($tmp_config_filename, $tmp_config_filename . ".php"); $tmp_config_filename .= ".php"; pressable_cache_extend('wp_config_file_replace_line: writing to ' . $tmp_config_filename); $fd = fopen($tmp_config_filename, 'w'); if (!$fd) { if (function_exists('set_transient')) { set_transient('wpsc_config_error', 'config_file_ro', 10); } trigger_error("wp_config_file_replace_line: Error - could not write to $my_file"); return false; } if ($found) { foreach ((array)$lines as $line) { if (!preg_match("/$old/", $line)) { fputs($fd, $line); } elseif ($new != '') { fputs($fd, "$new\n"); } } } else { $done = false; foreach ((array)$lines as $line) { // if ( $done || ! preg_match( '/\brequire_once\b/i', $line ) ) { if ($done || !preg_match('/\b(require_once)\b/', $line)) { fputs($fd, $line); } else { //add fputs($fd, "$new\n"); here to write function above require_once fputs($fd, $line); //Write function at the button of require_once fputs($fd, "$new\n"); $done = true; } } } fclose($fd); rename($tmp_config_filename, $my_file); pressable_cache_extend('wp_config_file_replace_line: moved ' . $tmp_config_filename . ' to ' . $my_file); // if (function_exists("opcache_invalidate")) // { // @opcache_invalidate($my_file); // } if (function_exists("wp_opcache_invalidate")) { wp_opcache_invalidate($my_file); } return true; }