Home / APIs / _copy_dir() – Copies a directory from one location to another via the WordPress Filesystem Abstraction.

You appear to be a bot. Output may be restricted

Description

Copies a directory from one location to another via the WordPress Filesystem Abstraction.

Assumes that WP_Filesystem() has already been called and setup. This is a temporary function for the 3.1 -> 3.2 upgrade, as well as for those upgrading to

  1. +
  2. Usage

    $mixed = _copy_dir( $from, $to, $skip_list );

    Parameters

    $from
    ( string ) required – source directory
    $to
    ( string ) required – destination directory
    $skip_list
    ( array ) optional – a list of files/folders to skip copying

    Returns

    mixed WP_Error on failure, True on success.

    Source

    File name: wordpress/wp-admin/includes/update-core.php
    Lines: 1 to 42 of 42

    function _copy_dir($from, $to, $skip_list = array() ) {
      global $wp_filesystem;
    
      $dirlist = $wp_filesystem->dirlist($from);
    
      $from = trailingslashit($from);
      $to = trailingslashit($to);
    
      foreach ( (array) $dirlist as $filename => $fileinfo ) {
        if ( in_array( $filename, $skip_list ) )
          continue;
    
        if ( 'f' == $fileinfo['type'] ) {
          if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) ) {
            // If copy failed, chmod file to 0644 and try again.
            $wp_filesystem->chmod( $to . $filename, FS_CHMOD_FILE );
            if ( ! $wp_filesystem->copy($from . $filename, $to . $filename, true, FS_CHMOD_FILE) )
              return new WP_Error( 'copy_failed__copy_dir', __( 'Could not copy file.' ), $to . $filename );
          }
        } elseif ( 'd' == $fileinfo['type'] ) {
          if ( !$wp_filesystem->is_dir($to . $filename) ) {
            if ( !$wp_filesystem->mkdir($to . $filename, FS_CHMOD_DIR) )
              return new WP_Error( 'mkdir_failed__copy_dir', __( 'Could not create directory.' ), $to . $filename );
          }
    
          /*
    			 * Generate the $sub_skip_list for the subdirectory as a sub-set
    			 * of the existing $skip_list.
    			 */
          $sub_skip_list = array();
          foreach ( $skip_list as $skip_item ) {
            if ( 0 === strpos( $skip_item, $filename . '/' ) )
              $sub_skip_list[] = preg_replace( '!^' . preg_quote( $filename, '!' ) . '/!i', '', $skip_item );
          }
    
          $result = _copy_dir($from . $filename, $to . $filename, $sub_skip_list);
          if ( is_wp_error($result) )
            return $result;
        }
      }
      return true;
    }
     

     View on GitHub View on Trac

Published: 13th March 2017 | Last updated: 13th March 2017

Information

Function name: _copy_dir
Plugin ref: WordPress
Version: 5.0.3
Sourcefile: wp-admin/includes/update-core.php
File ref: wp-admin/includes/update-core.php
API type: private
Deprecated?: No
API Letters: _,C,D

  • Plugins
  • Themes
  • Blocks
  • Shortcodes
  • APIs
  • Files
  • Hooks
  • Classes
  • Sites
  • Sitemap
  • Blog
WP-a2z Yoast SEO a2z
WordPress SEO a2z

Site:  wordpress-seo.wp-a2z.org
© Copyright WP-a2z 2017-2019. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins