A simple PHP script that automatically downloads and unzips the latest version of Wordpress in the current directory (./), so that I don't have to download it and upload it to my server through FTP manually.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// список плагинов для установки | |
$pluginsList = [ | |
'contact-form-7', | |
'cyr2lat', | |
'flamingo', | |
'wp-fastest-cache', | |
'wordpress-seo' | |
]; | |
// качаем вордпресс | |
file_put_contents('wp.zip', file_get_contents('https://wordpress.org/latest.zip')); | |
$zip = new ZipArchive(); | |
$res = $zip->open('wp.zip'); | |
if ($res !== TRUE) { | |
die('Не удалось открыть архив WP'); | |
} | |
// распаковываем архив и удаляем его | |
$zip->extractTo('./'); | |
$zip->close(); | |
unlink('wp.zip'); | |
// архив распаковался в папку wordpress | |
// переносим файлы оттуда в корень | |
$files = find_all_files("wordpress"); | |
$source = "wordpress/"; | |
foreach ($files as $file) { | |
$file = substr($file, strlen("wordpress/")); | |
if (in_array($file, array(".", ".."))) | |
continue; | |
if (!is_dir($source . $file)) { | |
rename($source . $file, $file); | |
} else { | |
@mkdir($file); | |
} | |
} | |
// а саму папку удаляем | |
deleteAll('wordpress'); | |
// качаем и устанавливаем плагины | |
foreach ($pluginsList as $plugin) { | |
$pluginZip = $plugin . 'zip'; | |
file_put_contents($pluginZip, file_get_contents('https://downloads.wordpress.org/plugin/' . $plugin . '.latest-stable.zip')); | |
$zip = new ZipArchive(); | |
$res = $zip->open($pluginZip); | |
if ($res !== TRUE) { | |
die('Не удалось открыть архив ' . $pluginZip); | |
} | |
$zip->extractTo('./wp-content/plugins/'); | |
$zip->close(); | |
unlink($pluginZip); | |
} | |
// если индексный файл на месте - запускаем установку | |
if (!file_exists('index.php')) { | |
die('Индексный файл WP не найден'); | |
} else { | |
echo '<meta http-equiv="refresh" content="1;url=index.php">'; | |
unlink(__FILE__); | |
} | |
function find_all_files($dir) | |
{ | |
$root = scandir($dir); | |
foreach ($root as $value) { | |
if ($value === '.' || $value === '..') { | |
continue; | |
} | |
$result[] = "$dir/$value"; | |
if (is_file("$dir/$value")) { | |
continue; | |
} | |
foreach (find_all_files("$dir/$value") as $value) { | |
$result[] = $value; | |
} | |
} | |
return $result; | |
} | |
function deleteAll($dir) | |
{ | |
foreach (glob($dir . '/*') as $file) { | |
if (is_dir($file)) | |
deleteAll($file); | |
else | |
unlink($file); | |
} | |
rmdir($dir); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment