Validate::sanitize_upload( null|array $value = null, array $upload_options = array() )

Description #

Sanitize upload field.

Parameters #

  • $value
    null | array (Optional) Array of uploads. Default value: null
  • $upload_options
    array (Optional) Upload options. Default value: array()

Source #

File: lib/class-validate.php

	public static function sanitize_upload( $value = null, $upload_options = array() ) {
		if ( ! empty( $value ) && is_array( $value ) && ! empty( $upload_options ) ) {
			if ( true === $upload_options['multiple'] && wp_is_numeric_array( $value ) ) {
				$value = array_slice( $value, 0, $upload_options['max_files'] );

				foreach ( $value as $key => $file ) {
					$value[ $key ]['error'] = (int) $file['error'];
					$value[ $key ]['name']  = sanitize_file_name( $file['name'] );
				}

				return $value;
			} elseif ( false === $upload_options['multiple'] && ! wp_is_numeric_array( $value ) ) {
				$value['error'] = (int) $value['error'];
				$value['name']  = sanitize_file_name( $value['name'] );

				return $value;
			}
		}
	}

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