-
-
Save boonebgorges/75e3ec70bd5177dab7dd to your computer and use it in GitHub Desktop.
Move files around in WP
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 | |
function bbg_toolbox() { | |
if ( ! is_super_admin() ) { | |
return; | |
} | |
if ( empty( $_GET['bbg-toolbox'] ) ) { | |
return; | |
} | |
global $wpdb; | |
$prd = 614; | |
$stg = 860; | |
switch_to_blog( $prd ); | |
$prd_dir = wp_upload_dir(); | |
$prd_path = $prd_dir['basedir']; | |
restore_current_blog(); | |
switch_to_blog( $stg ); | |
// WP sucks | |
$stg_path = str_replace( $prd, $stg, $prd_path ); | |
restore_current_blog(); | |
echo '<pre>'; | |
print_r( $prd_path ); | |
print_r( "\n\r" ); | |
print_r( $stg_path ); | |
echo '</pre>'; | |
bbg_recurse_copy( $stg_path, str_replace( $stg, '860-bu', $stg_path ) ); | |
bbg_rrmdir( $stg_path ); | |
bbg_recurse_copy( $prd_path, $stg_path ); | |
} | |
add_action( 'admin_init', 'bbg_toolbox' ); | |
function bbg_recurse_copy($src,$dst) { | |
$dir = opendir( $src ); | |
wp_mkdir_p( $dst ); | |
while ( false !== ( $file = readdir( $dir )) ) { | |
if (( $file != '.' ) && ( $file != '..' )) { | |
if ( is_dir($src . '/' . $file) ) { | |
bbg_recurse_copy( $src . '/' . $file, $dst . '/' . $file ); | |
} else { | |
copy( $src . '/' . $file, $dst . '/' . $file ); | |
} | |
} | |
} | |
closedir( $dir ); | |
} | |
function bbg_rrmdir( $dir ) { | |
foreach ( glob( $dir . '/*' ) as $file ) { | |
if ( is_dir( $file ) ) { | |
rrmdir( $file ); | |
} else { | |
unlink( $file ); | |
} | |
} | |
rmdir( $dir ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment