validate_file_to_edit

函式
validate_file_to_edit ( $file, $allowed_files = array() )
引數
  • (string) $file File the user is attempting to edit.
    Required:
  • (string[]) $allowed_files Optional. Array of allowed files to edit. `$file` must match an entry exactly.
    Required:
    Default: array()
返回值
  • (string|void) Returns the file name on success, dies on failure.
定義位置
相關方法
validate_fileget_real_file_to_editload_image_to_editvalidate_emailwp_validate_redirect
引入
1.5.0
棄用
-

validate_file_to_edit: 這個WordPress函式用於在編輯檔案之前驗證該檔案。它檢查該檔案是否存在,是否可寫,是否是一個系統檔案,如果發現任何錯誤,則返回錯誤資訊。

確保請求編輯的檔案被允許編輯。

如果你不被允許編輯該檔案,該函式將死亡。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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.' ) );
}
}
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.' ) ); } }
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.' ) );
	}
}

常見問題

FAQs
檢視更多 >