Validate::file_valid_type( object $field )

Description #

Check file array contain allowed mime types.

Parameters #

  • $field
    object (Required) Instance of @see AP_Field object.

Source #

File: lib/class-validate.php

	private static function file_valid_type( $field ) {
		$args       = $field->get( 'upload_options' );
		$value      = $field->value();
		$have_error = true;
		$is_numeric = wp_is_numeric_array( $value );

		if ( true === $args['multiple'] && $is_numeric ) {
			foreach ( $value as $key => $file ) {
				$actual_mime = wp_check_filetype_and_ext( $file['tmp_name'], $file['name'] );

				if ( false !== $actual_mime && in_array( $actual_mime['type'], $args['allowed_mimes'], true ) ) {
					$have_error = false;
				}
			}
		} elseif ( ! $is_numeric ) {
			$actual_mime = wp_check_filetype_and_ext( $value['tmp_name'], $value['name'] );

			if ( false !== $actual_mime && in_array( $actual_mime['type'], $args['allowed_mimes'], true ) ) {
				$have_error = false;
			}
		}

		return $have_error;
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment