copy_dir example



            // 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 ( str_starts_with( $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;
}

/** * Moves a directory from one location to another. * * Recursively invalidates OPcache on success. * * If the renaming failed, falls back to copy_dir(). * * Assumes that WP_Filesystem() has already been called and setup. * * This function is not designed to merge directories, copy_dir() should be used instead. * * @since 6.2.0 * * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. * * @param string $from Source directory. * @param string $to Destination directory. * @param bool $overwrite Optional. Whether to overwrite the destination directory if it exists. * Default false. * @return true|WP_Error True on success, WP_Error on failure. */
|| empty( $wp_filesystem->dirlist( $remote_destination ) )
            )
        ) {
            $result = move_dir( $source$remote_destination, true );
        } else {
            // Create destination if needed.             if ( ! $wp_filesystem->exists( $remote_destination ) ) {
                if ( ! $wp_filesystem->mkdir( $remote_destination, FS_CHMOD_DIR ) ) {
                    return new WP_Error( 'mkdir_failed_destination', $this->strings['mkdir_failed']$remote_destination );
                }
            }
            $result = copy_dir( $source$remote_destination );
        }

        // Clear the working directory?         if ( $args['clear_working'] ) {
            $wp_filesystem->delete( $remote_source, true );
        }

        if ( is_wp_error( $result ) ) {
            return $result;
        }

        
// Create maintenance file to signal that we are upgrading.     $maintenance_string = '<?php $upgrading = ' . time() . '; ?>';
    $maintenance_file   = $to . '.maintenance';
    $wp_filesystem->delete( $maintenance_file );
    $wp_filesystem->put_contents( $maintenance_file$maintenance_string, FS_CHMOD_FILE );

    /** This filter is documented in wp-admin/includes/update-core.php */
    apply_filters( 'update_feedback', __( 'Copying the required files&#8230;' ) );

    // Copy new versions of WP files into place.     $result = copy_dir( $from . $distro$to$skip );

    if ( is_wp_error( $result ) ) {
        $result = new WP_Error(
            $result->get_error_code(),
            $result->get_error_message(),
            substr( $result->get_error_data()strlen( $to ) )
        );
    }

    // Since we know the core files have copied over, we can now copy the version file.     if ( ! is_wp_error( $result ) ) {
        
Home | Imprint | This part of the site doesn't use cookies.