On this page
validate_file_to_edit( string $file, string[] $allowed_files = array() ): string|void
Makes sure that the file that was requested to be edited is allowed to be edited.
Description
Function will die if you are not allowed to edit the file.
Parameters
$filestring Required-
File the user is attempting to edit.
$allowed_filesstring[] Optional-
Array of allowed files to edit.
$filemust match an entry exactly.Default:
array()
Return
string|void Returns the file name on success, dies on failure.
Source
File: wp-admin/includes/file.php. View all references
function validate_file_to_edit( $file, $allowed_files = array() ) {
$code = validate_file( $file, $allowed_files );
if ( ! $code ) {
return $file;
}
switch ( $code ) {
case 1:
wp_die( __( 'Sorry, that file cannot be edited.' ) );
// case 2 :
// wp_die( __('Sorry, cannot call files with their real path.' ));
case 3:
wp_die( __( 'Sorry, that file cannot be edited.' ) );
}
}
Related
Uses
| Uses | Description |
|---|---|
| validate_file() wp-includes/functions.php | Validates a file name and path against an allowed set of rules. |
| __() wp-includes/l10n.php | Retrieves the translation of $text. |
| wp_die() wp-includes/functions.php | Kills WordPress execution and displays HTML page with an error message. |
Changelog
| Version | Description |
|---|---|
| 1.5.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/validate_file_to_edit