validate_file_to_edit

The timeline below displays how wordpress function validate_file_to_edit has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.1

/**
 * 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.
 *                                `$file` must match an entry exactly.
 * @return string|void Returns the file name on success, dies on failure.
 */
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.'));
    }
}

WordPress Version: 5.5

/**
 * 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.
 *                                `$file` must match an entry exactly.
 * @return string|void Returns the file name on success, dies on failure.
 */
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, can’t call files with their real path.' ));
        case 3:
            wp_die(__('Sorry, that file cannot be edited.'));
    }
}

WordPress Version: 5.1

/**
 * 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. `$file` must match an entry exactly.
 * @return string|void Returns the file name on success, dies on failure.
 */
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, can’t call files with their real path.' ));
        case 3:
            wp_die(__('Sorry, that file cannot be edited.'));
    }
}

WordPress Version: 4.9

/**
 * 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 array  $allowed_files Optional. Array of allowed files to edit, $file must match an entry exactly.
 * @return string|null
 */
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, can’t call files with their real path.' ));
        case 3:
            wp_die(__('Sorry, that file cannot be edited.'));
    }
}

WordPress Version: 4.5

/**
 * Make sure that the file that was requested to edit, 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 users is attempting to edit
 * @param array $allowed_files Array of allowed files to edit, $file must match an entry exactly
 * @return string|null
 */
function validate_file_to_edit($file, $allowed_files = '')
{
    $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, can’t call files with their real path.' ));
        case 3:
            wp_die(__('Sorry, that file cannot be edited.'));
    }
}

WordPress Version: 4.1

/**
 * Make sure that the file that was requested to edit, is allowed to be edited
 *
 * Function will die if if you are not allowed to edit the file
 *
 * @since 1.5.0
 *
 * @param string $file file the users is attempting to edit
 * @param array $allowed_files Array of allowed files to edit, $file must match an entry exactly
 * @return string|null
 */
function validate_file_to_edit($file, $allowed_files = '')
{
    $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, can’t call files with their real path.' ));
        case 3:
            wp_die(__('Sorry, that file cannot be edited.'));
    }
}

WordPress Version: 4.0

/**
 * Make sure that the file that was requested to edit, is allowed to be edited
 *
 * Function will die if if you are not allowed to edit the file
 *
 * @since 1.5.0
 *
 * @uses wp_die
 * @uses validate_file
 * @param string $file file the users is attempting to edit
 * @param array $allowed_files Array of allowed files to edit, $file must match an entry exactly
 * @return null
 */
function validate_file_to_edit($file, $allowed_files = '')
{
    $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, can’t call files with their real path.' ));
        case 3:
            wp_die(__('Sorry, that file cannot be edited.'));
    }
}

WordPress Version: 3.9

/**
 * Make sure that the file that was requested to edit, is allowed to be edited
 *
 * Function will die if if you are not allowed to edit the file
 *
 * @since 1.5.0
 *
 * @uses wp_die
 * @uses validate_file
 * @param string $file file the users is attempting to edit
 * @param array $allowed_files Array of allowed files to edit, $file must match an entry exactly
 * @return null
 */
function validate_file_to_edit($file, $allowed_files = '')
{
    $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, can’t call files with their real path.' ));
        case 3:
            wp_die(__('Sorry, that file cannot be edited.'));
    }
}

WordPress Version: 3.7

/**
 * Make sure that the file that was requested to edit, is allowed to be edited
 *
 * Function will die if if you are not allowed to edit the file
 *
 * @since 1.5.0
 *
 * @uses wp_die
 * @uses validate_file
 * @param string $file file the users is attempting to edit
 * @param array $allowed_files Array of allowed files to edit, $file must match an entry exactly
 * @return null
 */
function validate_file_to_edit($file, $allowed_files = '')
{
    $code = validate_file($file, $allowed_files);
    if (!$code) {
        return $file;
    }
    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.'));
        //case 2 :
        //	wp_die( __('Sorry, can’t call files with their real path.' ));
        case 3:
            wp_die(__('Sorry, that file cannot be edited.'));
    }
}