[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-admin/includes/ -> file.php (summary)

Filesystem API: Top-level functionality Functions for reading, writing, modifying, and deleting files on the file system. Includes functionality for theme-specific files as well as operations for uploading, archiving, and rendering output when necessary.

File Size: 2376 lines (84 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 26 functions

  get_file_description()
  get_home_path()
  list_files()
  wp_get_plugin_file_editable_extensions()
  wp_get_theme_file_editable_extensions()
  wp_print_file_editor_templates()
  wp_edit_theme_plugin_file()
  wp_tempnam()
  validate_file_to_edit()
  _wp_handle_upload()
  wp_handle_upload_error()
  wp_handle_upload()
  wp_handle_sideload()
  download_url()
  verify_file_md5()
  verify_file_signature()
  wp_trusted_keys()
  unzip_file()
  _unzip_file_ziparchive()
  _unzip_file_pclzip()
  copy_dir()
  WP_Filesystem()
  get_filesystem_method()
  request_filesystem_credentials()
  wp_print_request_filesystem_credentials_modal()
  wp_opcache_invalidate()

Functions
Functions that are not part of a class:

get_file_description( $file )   X-Ref
Gets the description for standard WordPress theme files.

since: 1.5.0
param: string $file Filesystem path or filename.
return: string Description of file from $wp_file_descriptions or basename of $file if description doesn't exist.

get_home_path()   X-Ref
Gets the absolute filesystem path to the root of the WordPress installation.

since: 1.5.0
return: string Full filesystem path to the root of the WordPress installation.

list_files( $folder = '', $levels = 100, $exclusions = array()   X-Ref
Returns a listing of all files in the specified folder and all subdirectories up to 100 levels deep.

The depth of the recursiveness can be controlled by the $levels param.

since: 2.6.0
since: 4.9.0 Added the `$exclusions` parameter.
param: string   $folder     Optional. Full path to folder. Default empty.
param: int      $levels     Optional. Levels of folders to follow, Default 100 (PHP Loop limit).
param: string[] $exclusions Optional. List of folders and files to skip.
return: bool|string[] False on failure, else array of files.

wp_get_plugin_file_editable_extensions( $plugin )   X-Ref
Gets the list of file extensions that are editable in plugins.

since: 4.9.0
param: string $plugin Path to the plugin file relative to the plugins directory.
return: string[] Array of editable file extensions.

wp_get_theme_file_editable_extensions( $theme )   X-Ref
Gets the list of file extensions that are editable for a given theme.

since: 4.9.0
param: WP_Theme $theme Theme object.
return: string[] Array of editable file extensions.

wp_print_file_editor_templates()   X-Ref
Prints file editor templates (for plugins and themes).

since: 4.9.0

wp_edit_theme_plugin_file( $args )   X-Ref
Attempts to edit a file for a theme or plugin.

When editing a PHP file, loopback requests will be made to the admin and the homepage
to attempt to see if there is a fatal error introduced. If so, the PHP change will be
reverted.

since: 4.9.0
param: string[] $args {
return: true|WP_Error True on success or `WP_Error` on failure.

wp_tempnam( $filename = '', $dir = '' )   X-Ref
Returns a filename of a temporary unique file.

Please note that the calling function must unlink() this itself.

The filename is based off the passed parameter or defaults to the current unix timestamp,
while the directory can either be passed as well, or by leaving it blank, default to a writable
temporary directory.

since: 2.6.0
param: string $filename Optional. Filename to base the Unique file off. Default empty.
param: string $dir      Optional. Directory to store the file in. Default empty.
return: string A writable filename.

validate_file_to_edit( $file, $allowed_files = array()   X-Ref
Makes sure that the file that was requested to be edited is allowed to be edited.

Function will die if you are not allowed to edit the file.

since: 1.5.0
param: string   $file          File the user is attempting to edit.
param: string[] $allowed_files Optional. Array of allowed files to edit.
return: string|void Returns the file name on success, dies on failure.

_wp_handle_upload( &$file, $overrides, $time, $action )   X-Ref
Handles PHP uploads in WordPress.

Sanitizes file names, checks extensions for mime type, and moves the file
to the appropriate directory within the uploads directory.

since: 4.0.0
param: string[]       $file      Reference to a single element of `$_FILES`.
param: string[]|false $overrides An associative array of names => values
param: string         $time      Time formatted in 'yyyy/mm'.
param: string         $action    Expected value for `$_POST['action']`.
return: string[] On success, returns an associative array of file attributes.

wp_handle_upload_error( &$file, $message )   X-Ref
No description

wp_handle_upload( &$file, $overrides = false, $time = null )   X-Ref
Wrapper for _wp_handle_upload().

Passes the {@see 'wp_handle_upload'} action.

since: 2.0.0
param: array      $file      Reference to a single element of `$_FILES`.
param: array|bool $overrides Optional. An associative array of names => values
param: string     $time      Optional. Time formatted in 'yyyy/mm'. Default null.
return: array On success, returns an associative array of file attributes.

wp_handle_sideload( &$file, $overrides = false, $time = null )   X-Ref
Wrapper for _wp_handle_upload().

Passes the {@see 'wp_handle_sideload'} action.

since: 2.6.0
param: array      $file      Reference to a single element of `$_FILES`.
param: array|bool $overrides Optional. An associative array of names => values
param: string     $time      Optional. Time formatted in 'yyyy/mm'. Default null.
return: array On success, returns an associative array of file attributes.

download_url( $url, $timeout = 300, $signature_verification = false )   X-Ref
Downloads a URL to a local temporary file using the WordPress HTTP API.

Please note that the calling function must unlink() the file.

since: 2.5.0
since: 5.2.0 Signature Verification with SoftFail was added.
param: string $url                    The URL of the file to download.
param: int    $timeout                The timeout for the request to download the file.
param: bool   $signature_verification Whether to perform Signature Verification.
return: string|WP_Error Filename on success, WP_Error on failure.

verify_file_md5( $filename, $expected_md5 )   X-Ref
Calculates and compares the MD5 of a file to its expected value.

since: 3.7.0
param: string $filename     The filename to check the MD5 of.
param: string $expected_md5 The expected MD5 of the file, either a base64-encoded raw md5,
return: bool|WP_Error True on success, false when the MD5 format is unknown/unexpected,

verify_file_signature( $filename, $signatures, $filename_for_errors = false )   X-Ref
Verifies the contents of a file against its ED25519 signature.

since: 5.2.0
param: string       $filename            The file to validate.
param: string|array $signatures          A Signature provided for the file.
param: string       $filename_for_errors A friendly filename for errors. Optional.
return: bool|WP_Error True on success, false if verification not attempted,

wp_trusted_keys()   X-Ref
Retrieves the list of signing keys trusted by WordPress.

since: 5.2.0
return: string[] Array of base64-encoded signing keys.

unzip_file( $file, $to )   X-Ref
Unzips a specified ZIP file to a location on the filesystem via the WordPress
Filesystem Abstraction.

Assumes that WP_Filesystem() has already been called and set up. Does not extract
a root-level __MACOSX directory, if present.

Attempts to increase the PHP memory limit to 256M before uncompressing. However,
the most memory required shouldn't be much larger than the archive itself.

since: 2.5.0
param: string $file Full path and filename of ZIP archive.
param: string $to   Full path on the filesystem to extract archive to.
return: true|WP_Error True on success, WP_Error on failure.

_unzip_file_ziparchive( $file, $to, $needed_dirs = array()   X-Ref
Attempts to unzip an archive using the ZipArchive class.

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
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.

_unzip_file_pclzip( $file, $to, $needed_dirs = array()   X-Ref
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
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.

copy_dir( $from, $to, $skip_list = array()   X-Ref
Copies a directory from one location to another via the WordPress Filesystem
Abstraction.

Assumes that WP_Filesystem() has already been called and setup.

since: 2.5.0
param: string   $from      Source directory.
param: string   $to        Destination directory.
param: string[] $skip_list An array of files/folders to skip copying.
return: true|WP_Error True on success, WP_Error on failure.

WP_Filesystem( $args = false, $context = false, $allow_relaxed_file_ownership = false )   X-Ref
Initializes and connects the WordPress Filesystem Abstraction classes.

This function will include the chosen transport and attempt connecting.

Plugins may add extra transports, And force WordPress to use them by returning
the filename via the {@see 'filesystem_method_file'} filter.

since: 2.5.0
param: array|false  $args                         Optional. Connection args, These are passed
param: string|false $context                      Optional. Context for get_filesystem_method().
param: bool         $allow_relaxed_file_ownership Optional. Whether to allow Group/World writable.
return: bool|null True on success, false on failure,

get_filesystem_method( $args = array()   X-Ref
Determines which method to use for reading, writing, modifying, or deleting
files on the filesystem.

The priority of the transports are: Direct, SSH2, FTP PHP Extension, FTP Sockets
(Via Sockets class, or `fsockopen()`). Valid values for these are: 'direct', 'ssh2',
'ftpext' or 'ftpsockets'.

The return value can be overridden by defining the `FS_METHOD` constant in `wp-config.php`,
or filtering via {@see 'filesystem_method'}.

since: 2.5.0
param: array  $args                         Optional. Connection details. Default empty array.
param: string $context                      Optional. Full path to the directory that is tested
param: bool   $allow_relaxed_file_ownership Optional. Whether to allow Group/World writable.
return: string The transport to use, see description for valid return values.

request_filesystem_credentials( $form_post, $type = '', $error = false, $context = '', $extra_fields = null, $allow_relaxed_file_ownership = false )   X-Ref
Displays a form to the user to request for their FTP/SSH details in order
to connect to the filesystem.

All chosen/entered details are saved, excluding the password.

Hostnames may be in the form of hostname:portnumber (eg: wordpress.org:2467)
to specify an alternate FTP/SSH port.

Plugins may override this form by returning true|false via the {@see 'request_filesystem_credentials'} filter.

since: 2.5.0
since: 4.6.0 The `$context` parameter default changed from `false` to an empty string.
param: string        $form_post                    The URL to post the form to.
param: string        $type                         Optional. Chosen type of filesystem. Default empty.
param: bool|WP_Error $error                        Optional. Whether the current request has failed
param: string        $context                      Optional. Full path to the directory that is tested
param: array         $extra_fields                 Optional. Extra `POST` fields to be checked
param: bool          $allow_relaxed_file_ownership Optional. Whether to allow Group/World writable.
return: bool|array True if no filesystem credentials are required,

wp_print_request_filesystem_credentials_modal()   X-Ref
Prints the filesystem credentials modal when needed.

since: 4.2.0

wp_opcache_invalidate( $filepath, $force = false )   X-Ref
Attempts to clear the opcode cache for an individual PHP file.

This function can be called safely without having to check the file extension
or availability of the OPcache extension.

Whether or not invalidation is possible is cached to improve performance.

since: 5.5.0
param: string $filepath Path to the file, including extension, for which the opcode cache is to be cleared.
param: bool   $force    Invalidate even if the modification time is not newer than the file in cache.
return: bool True if opcache was invalidated for `$filepath`, or there was nothing to invalidate.



Generated: Mon Jul 6 01:00:03 2020 Cross-referenced by PHPXref 0.7.1