Thanks very much for your reply. I understand the logic, but not the implementation at this stage.
Would you be able to tell me where the second section of code goes? Is it in the functions.php file?
I’ve also annotated the second section of code (see below) with my guess of what is occurring and what values could be replaced. Does this look about right?
function customfolder_copyr($source, $dest) // <------- defines customfolder copy action
{
// Check for symlinks
if (is_link($source)) {
return symlink(readlink($source), $dest);
}
// Simple copy for a file
if (is_file($source)) {
return copy($source, $dest);
}
// Make destination directory
if (!is_dir($dest)) {
mkdir($dest);
}
// Loop through the folder
$dir = dir($source);
while (false !== $entry = $dir->read()) {
// Skip pointers
if ($entry == '.' || $entry == '..') {
continue;
}
// Deep copy directories
customfolder_copyr("$source/$entry", "$dest/$entry"); // <------- defines customfolder copy action
}
// Clean up
$dir->close();
return true;
}
function customfolder_backup() // <------- customfolder backup
{
$to = dirname(__FILE__)."https://www.mysite-name.com/back-up-directory/"; // <------- this back up directory will be made
$from = dirname(__FILE__)."https://www.mysite-name.com/wp-content/plugins/plugin_name/custom-folder/"; // <------- this is the directory that will be backed up
customfolder_copyr($from, $to); // <------- executes customfolder copy action
}
function customfolder_recover() // <------- customfolder recover
{
$from = dirname(__FILE__)."https://www.mysite-name.com/back-up-directory/"; // <------- recover the files from this back up
$to = dirname(__FILE__)."https://www.mysite-name.com/wp-content/plugins/plugin_name/custom-folder/"; // <------- to this location
customfolder_copyr($from, $to); // <------- executes customfolder copy action
if (is_dir($from)) {
customfolder_rmdirr($from);#https://www.mysite-name.com/back-up-directory/ // <------- deletes the backup directory
}
}
add_filter('upgrader_pre_install', 'customfolder_backup', 10, 2); / <------- adds the customfolder_backup filter
add_filter('upgrader_post_install', 'customfolder_recover', 10, 2); <------- adds the customfolder_recover filter
(initial code source)