Noptin_Form::sanitize_form_data( array $data )

Sanitizes form data


Parameters Parameters

$data

(array) (Required) the unsanitized data.


Top ↑

Return Return

(array) the sanitized data


Top ↑

Source Source

File: includes/class-noptin-form.php

	public function sanitize_form_data( $data ) {

		$defaults = $this->get_defaults();

		// Arrays only please.
		if ( ! is_array( $data ) ) {
			return $defaults;
		}

		$data   = array_merge( $defaults, $data );
		$return = array();

		foreach ( $data as $key => $value ) {

			// convert 'true' to a boolean true.
			if ( 'false' === $value ) {
				$return[ $key ] = false;
				continue;
			}

			// convert 'false' to a boolean false.
			if ( 'true' === $value ) {
				$return[ $key ] = true;
				continue;
			}

			if ( ! isset( $defaults[ $key ] ) || ! is_array( $defaults[ $key ] ) ) {
				$return[ $key ] = $value;
				continue;
			}

			// Ensure props that expect array always receive arrays.
			if( is_scalar( $data[ $key ] ) ) {
				$return[ $key ] = noptin_parse_list( $data[ $key ] );
				continue;
			}

			if ( ! is_array( $data[ $key ] ) ) {
				$return[ $key ] = $defaults[ $key ];
				continue;
			}

			$return[ $key ] = $value;
		}

		if ( empty( $return['optinType'] ) ) {
			$return['optinType'] = 'inpost';
		}

		return $return;
	}


Top ↑

Changelog Changelog

Changelog
VersionDescription
1.0.5Introduced.

Top ↑

User Contributed Notes User Contributed Notes

30 day money back guarantee
Safe & Secure online payment
Custom CSS Slide Example
Custom Animation Example
Default Animation