switch ( $code ) {
case 1 :
- wp_die( __('Sorry, can’t edit files with “..” in the name. If you are trying to edit a file in your WordPress home directory, you can just type the name of the file in.' ));
+ wp_die( __( 'Sorry, that file cannot be edited.' ) );
//case 2 :
// wp_die( __('Sorry, can’t call files with their real path.' ));
case 3 :
- wp_die( __('Sorry, that file cannot be edited.' ));
+ wp_die( __( 'Sorry, that file cannot be edited.' ) );
}
}
* 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.
*
- * @since 2.0
+ * @since 2.0.0
*
* @uses wp_handle_upload_error
- * @uses apply_filters
* @uses is_multisite
* @uses wp_check_filetype_and_ext
* @uses current_user_can
}
}
+ /**
+ * Filter data for the current file to upload.
+ *
+ * @since 2.9.0
+ *
+ * @param array $file An array of data for a single file.
+ */
$file = apply_filters( 'wp_handle_upload_prefilter', $file );
// You may define your own function and pass the name in $overrides['upload_error_handler']
return call_user_func($upload_error_handler, $file, __( 'Invalid form submission.' ));
// A successful upload will pass this test. It makes no sense to override this one.
- if ( $file['error'] > 0 )
- return call_user_func($upload_error_handler, $file, $upload_error_strings[$file['error']] );
+ if ( isset( $file['error'] ) && $file['error'] > 0 ) {
+ return call_user_func( $upload_error_handler, $file, $upload_error_strings[ $file['error'] ] );
+ }
// A non-empty file will pass this test.
if ( $test_size && !($file['size'] > 0 ) ) {
if ( is_multisite() )
delete_transient( 'dirsize_cache' );
+ /**
+ * Filter the data array for the uploaded file.
+ *
+ * @since 2.1.0
+ *
+ * @param array $upload {
+ * Array of upload data.
+ *
+ * @type string $file Filename of the newly-uploaded file.
+ * @type string $url URL of the uploaded file.
+ * @type string $type File type.
+ * }
+ * @param string $context The type of upload action. Accepts 'upload' or 'sideload'.
+ */
return apply_filters( 'wp_handle_upload', array( 'file' => $new_file, 'url' => $url, 'type' => $type ), 'upload' );
}
* @since 2.6.0
*
* @uses wp_handle_upload_error
- * @uses apply_filters
* @uses wp_check_filetype_and_ext
* @uses current_user_can
* @uses wp_upload_dir
// Compute the URL
$url = $uploads['url'] . "/$filename";
+ /** This filter is documented in wp-admin/includes/file.php */
$return = apply_filters( 'wp_handle_upload', array( 'file' => $new_file, 'url' => $url, 'type' => $type ), 'sideload' );
return $return;
}
/**
- * Calculates and compares the MD5 of a file to it's expected value.
+ * Calculates and compares the MD5 of a file to its expected value.
*
* @since 3.7.0
*
return new WP_Error('fs_unavailable', __('Could not access filesystem.'));
// Unzip can use a lot of memory, but not this much hopefully
+ /** This filter is documented in wp-admin/admin.php */
@ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) );
$needed_dirs = array();
}
}
- if ( class_exists('ZipArchive') && apply_filters('unzip_file_use_ziparchive', true ) ) {
+ /**
+ * Filter whether to use ZipArchive to unzip archives.
+ *
+ * @since 3.0.0
+ *
+ * @param bool $ziparchive Whether to use ZipArchive. Default true.
+ */
+ if ( class_exists( 'ZipArchive' ) && apply_filters( 'unzip_file_use_ziparchive', true ) ) {
$result = _unzip_file_ziparchive($file, $to, $needed_dirs);
if ( true === $result ) {
return $result;
return false;
if ( ! class_exists("WP_Filesystem_$method") ) {
- $abstraction_file = apply_filters('filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method);
+
+ /**
+ * Filter the path for a specific filesystem method class file.
+ *
+ * @since 2.6.0
+ *
+ * @see get_filesystem_method()
+ *
+ * @param string $path Path to the specific filesystem method class file.
+ * @param string $method The filesystem method to use.
+ */
+ $abstraction_file = apply_filters( 'filesystem_method_file', ABSPATH . 'wp-admin/includes/class-wp-filesystem-' . $method . '.php', $method );
+
if ( ! file_exists($abstraction_file) )
return;
* Note that the return value of this function can be overridden in 2 ways
* - By defining FS_METHOD in your <code>wp-config.php</code> file
* - By using the filesystem_method filter
- * Valid values for these are: 'direct', 'ssh', 'ftpext' or 'ftpsockets'
+ * Valid values for these are: 'direct', 'ssh2', 'ftpext' or 'ftpsockets'
* Plugins may also define a custom transport handler, See the WP_Filesystem function for more information.
*
* @since 2.5.0
* @return string The transport to use, see description for valid return values.
*/
function get_filesystem_method($args = array(), $context = false) {
- $method = defined('FS_METHOD') ? FS_METHOD : false; //Please ensure that this is either 'direct', 'ssh', 'ftpext' or 'ftpsockets'
+ $method = defined('FS_METHOD') ? FS_METHOD : false; // Please ensure that this is either 'direct', 'ssh2', 'ftpext' or 'ftpsockets'
if ( ! $method && function_exists('getmyuid') && function_exists('fileowner') ){
if ( !$context )
if ( ! $method && isset($args['connection_type']) && 'ssh' == $args['connection_type'] && extension_loaded('ssh2') && function_exists('stream_get_contents') ) $method = 'ssh2';
if ( ! $method && extension_loaded('ftp') ) $method = 'ftpext';
if ( ! $method && ( extension_loaded('sockets') || function_exists('fsockopen') ) ) $method = 'ftpsockets'; //Sockets: Socket extension; PHP Mode: FSockopen / fwrite / fread
- return apply_filters('filesystem_method', $method, $args);
+
+ /**
+ * Filter the filesystem method to use.
+ *
+ * @since 2.6.0
+ *
+ * @param string $method Filesystem method to return.
+ * @param array $args An array of connection details for the method.
+ */
+ return apply_filters( 'filesystem_method', $method, $args );
}
/**
* @return boolean False on failure. True on success.
*/
function request_filesystem_credentials($form_post, $type = '', $error = false, $context = false, $extra_fields = null) {
+
+ /**
+ * Filter the filesystem credentials form output.
+ *
+ * Returning anything other than an empty string will effectively short-circuit
+ * output of the filesystem credentials form, returning that value instead.
+ *
+ * @since 2.5.0
+ *
+ * @param mixed $output Form output to return instead. Default empty.
+ * @param string $form_post URL to POST the form to.
+ * @param string $type Chosen type of filesystem.
+ * @param bool $error Whether the current request has failed to connect.
+ * Default false.
+ * @param string $context Full path to the directory that is tested for
+ * being writable.
+ * @param array $extra_fields Extra POST fields.
+ */
$req_cred = apply_filters( 'request_filesystem_credentials', '', $form_post, $type, $error, $context, $extra_fields );
if ( '' !== $req_cred )
return $req_cred;
unset($credentials['port']);
}
- if ( (defined('FTP_SSH') && FTP_SSH) || (defined('FS_METHOD') && 'ssh' == FS_METHOD) )
+ if ( ( defined('FTP_SSH') && FTP_SSH ) || ( defined('FS_METHOD') && 'ssh2' == FS_METHOD ) )
$credentials['connection_type'] = 'ssh';
else if ( (defined('FTP_SSL') && FTP_SSL) && 'ftpext' == $type ) //Only the FTP Extension understands SSL
$credentials['connection_type'] = 'ftps';
if ( extension_loaded('ssh2') && function_exists('stream_get_contents') )
$types[ 'ssh' ] = __('SSH2');
- $types = apply_filters('fs_ftp_connection_types', $types, $credentials, $type, $error, $context);
+ /**
+ * Filter the connection types to output to the filesystem credentials form.
+ *
+ * @since 2.9.0
+ *
+ * @param array $types Types of connections.
+ * @param array $credentials Credentials to connect with.
+ * @param string $type Chosen filesystem method.
+ * @param object $error Error object.
+ * @param string $context Full path to the directory that is tested
+ * for being writable.
+ */
+ $types = apply_filters( 'fs_ftp_connection_types', $types, $credentials, $type, $error, $context );
?>
<script type="text/javascript">
_e('If you do not remember your credentials, you should contact your web host.');
?></p>
<table class="form-table">
-<tr valign="top">
+<tr>
<th scope="row"><label for="hostname"><?php _e('Hostname') ?></label></th>
<td><input name="hostname" type="text" id="hostname" value="<?php echo esc_attr($hostname); if ( !empty($port) ) echo ":$port"; ?>"<?php disabled( defined('FTP_HOST') ); ?> size="40" /></td>
</tr>
-<tr valign="top">
+<tr>
<th scope="row"><label for="username"><?php echo $label_user; ?></label></th>
<td><input name="username" type="text" id="username" value="<?php echo esc_attr($username) ?>"<?php disabled( defined('FTP_USER') ); ?> size="40" /></td>
</tr>
-<tr valign="top">
+<tr>
<th scope="row"><label for="password"><?php echo $label_pass; ?></label></th>
<td><div><input name="password" type="password" id="password" value="<?php if ( defined('FTP_PASS') ) echo '*****'; ?>"<?php disabled( defined('FTP_PASS') ); ?> size="40" /></div>
<div><em><?php if ( ! defined('FTP_PASS') ) _e( 'This password will not be stored on the server.' ); ?></em></div></td>
</tr>
<?php if ( isset($types['ssh']) ) : ?>
-<tr id="ssh_keys" valign="top" style="<?php if ( 'ssh' != $connection_type ) echo 'display:none' ?>">
+<tr id="ssh_keys" style="<?php if ( 'ssh' != $connection_type ) echo 'display:none' ?>">
<th scope="row"><?php _e('Authentication Keys') ?>
<div class="key-labels textright">
<label for="public_key"><?php _e('Public Key:') ?></label ><br />
</tr>
<?php endif; ?>
-<tr valign="top">
+<tr>
<th scope="row"><?php _e('Connection Type') ?></th>
<td>
<fieldset><legend class="screen-reader-text"><span><?php _e('Connection Type') ?></span></legend>