validate_file_to_edit( string $file, string[] $allowed_files = array() ): string|null

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

$filestringrequired
File the user is attempting to edit.
$allowed_filesstring[]optional
Array of allowed files to edit.
$file must match an entry exactly.

Default:array()

Return

string|null Returns the file name on success, null in case of absolute Windows drive paths, and dies on failure.

Source

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.' ) );
	}
	return null;
}

Changelog

VersionDescription
1.5.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.