Skip to content

Instantly share code, notes, and snippets.

@shazdeh
Last active October 5, 2021 01:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shazdeh/48272f470efd68a293eced2f90dbacee to your computer and use it in GitHub Desktop.
Save shazdeh/48272f470efd68a293eced2f90dbacee to your computer and use it in GitHub Desktop.
Run install.php to download and install latest version of WP
<?php
$ch = curl_init();
$source = "https://wordpress.org/latest.zip";
curl_setopt( $ch, CURLOPT_URL, $source );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
$data = curl_exec ( $ch );
curl_close ( $ch );
/* save as wordpress.zip */
$destination = "wordpress.zip";
$file = fopen( $destination, "w+" );
fputs( $file, $data );
fclose( $file );
/* unzip */
$zip = new ZipArchive;
$res = $zip->open( 'wordpress.zip' );
if ( $res === TRUE ) {
$zip->extractTo( '.' ); // directory to extract contents to
$zip->close();
unlink( 'wordpress.zip' );
}
recurseMove( dirname( __FILE__ ) . '/wordpress', dirname( __FILE__ ) );
rmdir( dirname( __FILE__ ) . '/wordpress' );
function recurseMove(
string $sourceDirectory,
string $destinationDirectory,
string $childFolder = ''
): void {
$directory = opendir( $sourceDirectory );
if ( is_dir($destinationDirectory) === false ) {
mkdir( $destinationDirectory );
}
if ( $childFolder !== '' ) {
if ( is_dir( "$destinationDirectory/$childFolder" ) === false ) {
mkdir( "$destinationDirectory/$childFolder" );
}
while ( ( $file = readdir( $directory ) ) !== false ) {
if ( $file === '.' || $file === '..' ) {
continue;
}
if ( is_dir( "$sourceDirectory/$file") === true ) {
recurseMove( "$sourceDirectory/$file", "$destinationDirectory/$childFolder/$file" );
rmdir( "$sourceDirectory/$file" );
} else {
copy( "$sourceDirectory/$file", "$destinationDirectory/$childFolder/$file" );
unlink( "$sourceDirectory/$file" );
}
}
closedir( $directory );
return;
}
while ( ( $file = readdir( $directory ) ) !== false ) {
if ( $file === '.' || $file === '..' ) {
continue;
}
if ( is_dir( "$sourceDirectory/$file" ) === true) {
recurseMove( "$sourceDirectory/$file", "$destinationDirectory/$file" );
rmdir( "$sourceDirectory/$file" );
}
else {
copy( "$sourceDirectory/$file", "$destinationDirectory/$file" );
unlink( "$sourceDirectory/$file" );
}
}
closedir( $directory );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment