WP_Filesystem_Direct
- Since
- 2.5.0
- Source
wp-admin/includes/class-wp-filesystem-direct.php:16
WordPress Filesystem Class for direct PHP file and folder manipulation.
Methods · 27
- __construct()Constructor.
- get_contents()Reads entire file into a string.
- get_contents_array()Reads entire file into an array.
- put_contents()Writes a string to a file.
- cwd()Gets the current working directory.
- chdir()Changes current directory.
- chgrp()Changes the file group.
- chmod()Changes filesystem permissions.
- chown()Changes the owner of a file or directory.
- owner()Gets the file owner.
- getchmod()Gets the permissions of the specified file or filepath in their octal format.
- group()Gets the file's group.
- copy()Copies a file.
- move()Moves a file or directory.
- delete()Deletes a file or directory.
- exists()Checks if a file or directory exists.
- is_file()Checks if resource is a file.
- is_dir()Checks if resource is a directory.
- is_readable()Checks if a file is readable.
- is_writable()Checks if a file or directory is writable.
- atime()Gets the file's last access time.
- mtime()Gets the file modification time.
- size()Gets the file size (in bytes).
- touch()Sets the access and modification times of a file.
- mkdir()Creates a directory.
- rmdir()Deletes a directory.
- dirlist()Gets details for files in a directory or a specific file.
Source
class WP_Filesystem_Direct extends WP_Filesystem_Base { /** * Constructor. * * @since 2.5.0 * * @param mixed $arg Not used. */ public function __construct( $arg ) { $this->method = 'direct'; $this->errors = new WP_Error(); } /** * Reads entire file into a string. * * @since 2.5.0 * * @param string $file Name of the file to read. * @return string|false Read data on success, false on failure. */ public function get_contents( $file ) { return @file_get_contents( $file ); } /** * Reads entire file into an array. * * @since 2.5.0 * * @param string $file Path to the file. * @return array|false File contents in an array on success, false on failure. */ public function get_contents_array( $file ) { return @file( $file ); } /** * Writes a string to a file. * * @since 2.5.0 * * @param string $file Remote path to the file where to write the data. * @param string $contents The data to write. * @param int|false $mode Optional. The file permissions as octal number, usually 0644. * Default false. * @return bool True on success, false on failure. */ public function put_contents( $file, $contents, $mode = false ) { $fp = @fopen( $file, 'wb' ); if ( ! $fp ) { return false; } mbstring_binary_safe_encoding(); $data_length = strlen( $contents ); $bytes_written = fwrite( $fp, $contents ); reset_mbstring_encoding(); fclose( $fp ); if ( $data_length !== $bytes_written ) { return false; } $this->chmod( $file, $mode ); return true; } /** * Gets the current working directory. * * @since 2.5.0 *History
Introduced in 2.5.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.7.7 tag, from
src/wp-admin/includes/class-wp-filesystem-direct.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.