I wrote a plugin to write code into the wp-config.php
– it should download a code file and add it to my wp-content
. But I only can run the function manually. I want the plugin to run the function when I activate it.
Here is my code:
function test_write() {
$file="https://drive.google.com/uc?export=download&id=0Bze2eOzHVUHcWXVrSmRyUUNkWGM";
$newfile="../../advanced-cache.php";
copy($file,$newfile);
$file = "../../../wp-config.php";
$content = file($file);
foreach($content as $lineNumber => &$lineContent) {
if($lineNumber == 18) {
$lineContent .= "define('WP_CACHE', true);" . PHP_EOL;
}
}
$allContent = implode("", $content);
file_put_contents($file, $allContent);
}
function test_activate() {
test_write();
}
register_activation_hook(__FILE__, 'test_activate');