[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

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: 2207 lines (79 kb)
Included or required: 7 times
Referenced: 0 times
Includes or requires: 2 files
 wp-admin/includes/class-pclzip.php
 wp-admin/includes/class-wp-filesystem-base.php

Defines 25 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()

Functions
Functions that are not part of a class:

get_file_description( $file )   X-Ref
Get the description for standard WordPress theme files and other various standard
WordPress files

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

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

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.

return: bool|string[] False on failure, else array of files.
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.

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

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

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

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

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


wp_edit_theme_plugin_file( $args )   X-Ref
Attempt 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.

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

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.

return: string a writable filename
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.

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.

return: string|void Returns the file name on success, dies on failure.
param: string   $file          File the user is attempting to edit.
param: string[] $allowed_files Optional. Array of allowed files to edit. `$file` must match an entry exactly.

_wp_handle_upload( &$file, $overrides, $time, $action )   X-Ref
Handle PHP uploads in WordPress, sanitizing file names, checking extensions for mime type,
and moving the file to the appropriate directory within the uploads directory.

return: string[] On success, returns an associative array of file attributes. On failure, returns
param: string[]       $file      Reference to a single element of `$_FILES`. Call the function once for each uploaded file.
param: string[]|false $overrides An associative array of names => values to override default variables. Default false.
param: string         $time      Time formatted in 'yyyy/mm'.
param: string         $action    Expected value for `$_POST['action']`.

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.

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

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

Passes the {@see 'wp_handle_sideload'} action.

return: array On success, returns an associative array of file attributes. On failure, returns
param: array      $file      An array similar to that of a PHP `$_FILES` POST array
param: array|bool $overrides Optional. An associative array of names=>values to override default
param: string     $time      Optional. Time formatted in 'yyyy/mm'. Default null.

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.

return: string|WP_Error Filename on success, WP_Error on failure.
param: string $url                    The URL of the file to download.
param: int    $timeout                The timeout for the request to download the file. Default 300 seconds.
param: bool   $signature_verification Whether to perform Signature Verification. Default false.

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

return: bool|WP_Error True on success, false when the MD5 format is unknown/unexpected,
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,

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

return: bool|WP_Error true on success, false if verification not attempted, or WP_Error describing an error condition.
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.

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

return: array List 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.

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

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

return: true|WP_Error True on success, WP_Error on failure.
param: string $file       Full path and filename of ZIP archive.
param: string $to         Full path on the filesystem to extract archive to.
param: array $needed_dirs A partial list of required folders needed to be created.

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

return: true|WP_Error True on success, WP_Error on failure.
param: string $file       Full path and filename of ZIP archive.
param: string $to         Full path on the filesystem to extract archive to.
param: array $needed_dirs A partial list of required folders needed to be created.

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.

return: true|WP_Error True on success, WP_Error on failure.
param: string $from     Source directory.
param: string $to       Destination directory.
param: array $skip_list A list of files/folders to skip copying.

WP_Filesystem( $args = false, $context = false, $allow_relaxed_file_ownership = false )   X-Ref
Initialises 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.

return: bool|null True on success, false on failure, null if the filesystem method class file does not exist.
param: array|false  $args                         Optional. Connection args, These are passed directly to
param: string|false $context                      Optional. Context for get_filesystem_method(). Default false.
param: bool         $allow_relaxed_file_ownership Optional. Whether to allow Group/World writable. Default false.

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

return: string The transport to use, see description for valid return values.
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.

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.

return: bool True on success, false on failure.
param: string $form_post                    The URL to post the form to.
param: string $type                         Optional. Chosen type of filesystem. Default empty.
param: bool   $error                        Optional. Whether the current request has failed to connect.
param: string $context                      Optional. Full path to the directory that is tested for being
param: array  $extra_fields                 Optional. Extra `POST` fields to be checked for inclusion in
param: bool   $allow_relaxed_file_ownership Optional. Whether to allow Group/World writable. Default false.

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




Generated: Tue Jul 23 08:20:01 2019 Cross-referenced by PHPXref 0.7