put_contents example

public function copy( $source$destination$overwrite = false, $mode = false ) {
        if ( ! $overwrite && $this->exists( $destination ) ) {
            return false;
        }

        $content = $this->get_contents( $source );

        if ( false === $content ) {
            return false;
        }

        return $this->put_contents( $destination$content$mode );
    }

    /** * Moves a file or directory. * * After moving files or directories, OPcache will need to be invalidated. * * If moving a directory fails, `copy_dir()` can be used for a recursive copy. * * Use `move_dir()` for moving directories with OPcache invalidation and a * fallback to `copy_dir()`. * * @since 2.7.0 * * @param string $source Path to the source file or directory. * @param string $destination Path to the destination file or directory. * @param bool $overwrite Optional. Whether to overwrite the destination if it exists. * Default false. * @return bool True on success, false on failure. */
public function copy( $source$destination$overwrite = false, $mode = false ) {
        if ( ! $overwrite && $this->exists( $destination ) ) {
            return false;
        }

        $content = $this->get_contents( $source );

        if ( false === $content ) {
            return false;
        }

        return $this->put_contents( $destination$content$mode );
    }

    /** * Moves a file or directory. * * After moving files or directories, OPcache will need to be invalidated. * * If moving a directory fails, `copy_dir()` can be used for a recursive copy. * * Use `move_dir()` for moving directories with OPcache invalidation and a * fallback to `copy_dir()`. * * @since 2.5.0 * * @param string $source Path to the source file or directory. * @param string $destination Path to the destination file or directory. * @param bool $overwrite Optional. Whether to overwrite the destination if it exists. * Default false. * @return bool True on success, false on failure. */

        }
    }

    /** This filter is documented in wp-admin/includes/update-core.php */
    apply_filters( 'update_feedback', __( 'Enabling Maintenance mode…' ) );

    // 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(),
            
// Don't extract invalid files:         if ( 0 !== validate_file( $info['name'] ) ) {
            continue;
        }

        $contents = $z->getFromIndex( $i );

        if ( false === $contents ) {
            return new WP_Error( 'extract_failed_ziparchive', __( 'Could not extract file from archive.' )$info['name'] );
        }

        if ( ! $wp_filesystem->put_contents( $to . $info['name']$contents, FS_CHMOD_FILE ) ) {
            return new WP_Error( 'copy_failed_ziparchive', __( 'Could not copy file.' )$info['name'] );
        }
    }

    $z->close();

    return true;
}

/** * Attempts to unzip an archive using the PclZip library. * * This function should not be called directly, use `unzip_file()` instead. * * Assumes that WP_Filesystem() has already been called and set up. * * @since 3.0.0 * @access private * * @see unzip_file() * * @global WP_Filesystem_Base $wp_filesystem WordPress filesystem subclass. * * @param string $file Full path and filename of ZIP archive. * @param string $to Full path on the filesystem to extract archive to. * @param string[] $needed_dirs A partial list of required folders needed to be created. * @return true|WP_Error True on success, WP_Error on failure. */

    public function maintenance_mode( $enable = false ) {
        global $wp_filesystem;
        $file = $wp_filesystem->abspath() . '.maintenance';
        if ( $enable ) {
            $this->skin->feedback( 'maintenance_start' );
            // Create maintenance file to signal that we are upgrading.             $maintenance_string = '<?php $upgrading = ' . time() . '; ?>';
            $wp_filesystem->delete( $file );
            $wp_filesystem->put_contents( $file$maintenance_string, FS_CHMOD_FILE );
        } elseif ( ! $enable && $wp_filesystem->exists( $file ) ) {
            $this->skin->feedback( 'maintenance_end' );
            $wp_filesystem->delete( $file );
        }
    }

    /** * Creates a lock using WordPress options. * * @since 4.5.0 * * @global wpdb $wpdb The WordPress database abstraction object. * * @param string $lock_name The name of this unique lock. * @param int $release_timeout Optional. The duration in seconds to respect an existing lock. * Default: 1 hour. * @return bool False if a lock couldn't be created or if the lock is still valid. True otherwise. */
public function copy( $source$destination$overwrite = false, $mode = false ) {
        if ( ! $overwrite && $this->exists( $destination ) ) {
            return false;
        }

        $content = $this->get_contents( $source );

        if ( false === $content ) {
            return false;
        }

        return $this->put_contents( $destination$content$mode );
    }

    /** * Moves a file or directory. * * After moving files or directories, OPcache will need to be invalidated. * * If moving a directory fails, `copy_dir()` can be used for a recursive copy. * * Use `move_dir()` for moving directories with OPcache invalidation and a * fallback to `copy_dir()`. * * @since 2.5.0 * * @param string $source Path to the source file or directory. * @param string $destination Path to the destination file or directory. * @param bool $overwrite Optional. Whether to overwrite the destination if it exists. * Default false. * @return bool True on success, false on failure. */
Home | Imprint | This part of the site doesn't use cookies.