WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

wpcf7_file_validation_filter() CF7 1.0

Хуки из функции
Возвращает

Null. Ничего.

Использование

wpcf7_file_validation_filter( $result, $tag );

Код wpcf7_file_validation_filter() CF7 5.3.2

<?php
function wpcf7_file_validation_filter( $result, $tag ) {
	$name = $tag->name;
	$id = $tag->get_id_option();

	$file = isset( $_FILES[$name] ) ? $_FILES[$name] : null;

	if ( ! empty( $file['error'] ) and UPLOAD_ERR_NO_FILE !== $file['error'] ) {
		$result->invalidate( $tag, wpcf7_get_message( 'upload_failed_php_error' ) );
		return $result;
	}

	if ( empty( $file['tmp_name'] ) and $tag->is_required() ) {
		$result->invalidate( $tag, wpcf7_get_message( 'invalid_required' ) );
		return $result;
	}

	if ( empty( $file['tmp_name'] )
	or ! is_uploaded_file( $file['tmp_name'] ) ) {
		return $result;
	}

	/* File type validation */

	$file_type_pattern = wpcf7_acceptable_filetypes(
		$tag->get_option( 'filetypes' ), 'regex'
	);

	$file_type_pattern = '/\.(' . $file_type_pattern . ')$/i';

	if ( empty( $file['name'] )
	or ! preg_match( $file_type_pattern, $file['name'] ) ) {
		$result->invalidate( $tag,
			wpcf7_get_message( 'upload_file_type_invalid' )
		);

		return $result;
	}

	/* File size validation */

	$allowed_size = $tag->get_limit_option();

	if ( ! empty( $file['size'] ) and $allowed_size < $file['size'] ) {
		$result->invalidate( $tag, wpcf7_get_message( 'upload_file_too_large' ) );
		return $result;
	}

	wpcf7_init_uploads(); // Confirm upload dir
	$uploads_dir = wpcf7_upload_tmp_dir();
	$uploads_dir = wpcf7_maybe_add_random_dir( $uploads_dir );

	$filename = $file['name'];
	$filename = wpcf7_canonicalize( $filename, 'as-is' );
	$filename = wpcf7_antiscript_file_name( $filename );

	$filename = apply_filters( 'wpcf7_upload_file_name', $filename,
		$file['name'], $tag
	);

	$filename = wp_unique_filename( $uploads_dir, $filename );
	$new_file = path_join( $uploads_dir, $filename );

	if ( false === @move_uploaded_file( $file['tmp_name'], $new_file ) ) {
		$result->invalidate( $tag, wpcf7_get_message( 'upload_failed' ) );
		return $result;
	}

	// Make sure the uploaded file is only readable for the owner process
	chmod( $new_file, 0400 );

	if ( $submission = WPCF7_Submission::get_instance() ) {
		$submission->add_uploaded_file( $name, $new_file );
	}

	return $result;
}