0

Hy Guys, I am wanting to copy a folder to activate my plugin, I'm trying this but it does not work.

function hyperbolic_activate() {

    $src = 'includes/myTheme/';
    $dst = '../themes/';

    function recurs_copy($src,$dst) {
        $dir = opendir($src);
        @mkdir($dst);
        while(false !== ( $file = readdir($dir)) ) {
        if (( $file != '.' ) && ( $file != '..' )) {
            if ( is_dir($src . '/' . $file) ) {
                recurse_copy($src . '/' . $file,$dst . '/' . $file);
            } else {
                copy($src . '/' . $file,$dst . '/' . $file);
            }
        }
    }
    closedir($dir);
    }
}
register_activation_hook( __FILE__, 'hyperbolic_activate' );

What is the problem in my code?

6
  • Please turn on debugging and tell us what "it does not work" exactly is.
    – kaiser
    Sep 2, 2013 at 11:39
  • Simply it does not copy the folder '/mytheme/' for the directory indicated.
    – Raank
    Sep 2, 2013 at 12:01
  • No. What your Error message is. And where it is coming from.
    – kaiser
    Sep 2, 2013 at 12:10
  • I solved the problem with the following code: pastebin.com/fVPKQRLB
    – Raank
    Sep 2, 2013 at 12:39
  • 1
    "Users with less than 10 reputation can't answer their own question for 8 hours after asking. You can answer in 4 hours. Until then please use comments, or edit your question instead." I'll post later
    – Raank
    Sep 2, 2013 at 13:16

1 Answer 1

0

You are defining the recurs_copy() function to perform the copy but you never execute it. Try:

function hyperbolic_activate() {

   $src = 'includes/myTheme/';
   $dst = '../themes/';
   recurs_copy($src, $dst);

}
register_activation_hook( __FILE__, 'hyperbolic_activate' );

function recurs_copy($src,$dst) {
    $dir = opendir($src);
    @mkdir($dst);
    while(false !== ( $file = readdir($dir)) ) {
      if (( $file != '.' ) && ( $file != '..' )) {
         if ( is_dir($src . '/' . $file) ) {
            recurse_copy($src . '/' . $file,$dst . '/' . $file);
         } else {
            copy($src . '/' . $file,$dst . '/' . $file);
         }
      }
    }
   closedir($dir);
 }
3
  • This generated a series of errors, 'Could not be activated because it generated a fatal error.', there were so many mistakes that neither of to spend here.
    – Raank
    Sep 2, 2013 at 11:58
  • Check the path to the folder you are trying to copy and the destination.
    – cybmeta
    Sep 2, 2013 at 12:54
  • You should mark my answer as the correct one. I've seen your solution and it is the code I posted with the correct paths to the directories (as I did suggest you to check). Thank you.
    – cybmeta
    Sep 2, 2013 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.