validate_file_to_edit

Make sure that the file that was requested to edit, is allowed to be edited.

Description

(string|null) validate_file_to_edit( (string) $file, (string) $allowed_files = '' ); 

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

Returns (string|null)

Parameters (2)

0. $file (string)
File the users is attempting to edit
1. $allowed_files — Optional. (string) => ''
Array of allowed files to edit, $file must match an entry exactly

Usage

  1. if ( !function_exists( 'validate_file_to_edit' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/file.php'; 
  3.  
  4. // file the users is attempting to edit 
  5. $file = ''; 
  6.  
  7. // Array of allowed files to edit, $file must match an entry exactly 
  8. $allowed_files = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = validate_file_to_edit($file, $allowed_files); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/file.php  
  1. function validate_file_to_edit( $file, $allowed_files = '' ) { 
  2. $code = validate_file( $file, $allowed_files ); 
  3.  
  4. if (!$code ) 
  5. return $file; 
  6.  
  7. switch ( $code ) { 
  8. case 1 : 
  9. wp_die( __( 'Sorry, that file cannot be edited.' ) ); 
  10.  
  11. // case 2 : 
  12. // wp_die( __('Sorry, can’t call files with their real path.' )); 
  13.  
  14. case 3 : 
  15. wp_die( __( 'Sorry, that file cannot be edited.' ) );