Last active
October 5, 2021 01:50
-
-
Save shazdeh/48272f470efd68a293eced2f90dbacee to your computer and use it in GitHub Desktop.
Run install.php to download and install latest version of WP
This file contains hidden or 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 | |
$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