function wpmlm_copy_themes_to_uploads() { $old_theme_path = WPMLM_CORE_THEME_PATH; $new_theme_path = WPMLM_THEMES_PATH; $new_dir = @opendir($new_theme_path); $num = 0; $file_names = array(); while (($file = @readdir($new_dir)) !== false) { if (is_dir($new_theme_path . $file) && $file != ".." && $file != ".") { $file_names[] = $file; } } if (count($file_names) < 1) { $old_dir = @opendir($old_theme_path); while (($file = @readdir($old_dir)) !== false) { if (is_dir($old_theme_path . $file) && $file != ".." && $file != ".") { @wpmlm_recursive_copy($old_theme_path . $file, $new_theme_path . $file); } } } }
/** * wpmlm_recursive_copy function, copied from here and renamed: http://nz.php.net/copy * Why doesn't PHP have one of these built in? */ function wpmlm_recursive_copy($src, $dst) { $dir = opendir($src); @mkdir($dst); while (false !== ($file = readdir($dir))) { if ($file != '.' && $file != '..') { if (is_dir($src . '/' . $file)) { wpmlm_recursive_copy($src . '/' . $file, $dst . '/' . $file); } else { @copy($src . '/' . $file, $dst . '/' . $file); } } } closedir($dir); }
function wpmlm_backup_theme() { $wp_theme_path = get_stylesheet_directory(); wpmlm_recursive_copy($wp_theme_path, WPMLM_THEME_BACKUP_DIR); $_SESSION['wpmlm_themes_backup'] = true; $sendback = wp_get_referer(); wp_redirect($sendback); exit; }