Inventory_Presser_Options::sanitize_options( array $input )

sanitize_options


Description Description

Santitizes the user input into the options inputs before they are saved.


Top ↑

Parameters Parameters

$input

(array) (Required)


Top ↑

Return Return

(array)


Top ↑

Source Source

File: includes/class-dealership-options.php

	public function sanitize_options( $input )
	{
		$sanitary_values = array();

		$boolean_settings = array(
			'additional_listings_page',
			'include_sold_vehicles',
			'show_all_taxonomies',
			'skip_trash',
			'use_carfax',
			'use_carfax_provided_buttons',
		);
		foreach( $boolean_settings as $b )
		{
			$sanitary_values[$b] = isset( $input[$b] );
		}

		if ( isset( $input['price_display'] ) )
		{
			$sanitary_values['price_display'] = $input['price_display'];
		}

		if ( isset( $input['mapbox_public_token'] ) )
		{
			$sanitary_values['mapbox_public_token'] = $input['mapbox_public_token'];
		}

		if ( isset( $input['sort_vehicles_by'] ) )
		{
			$sanitary_values['sort_vehicles_by'] = $input['sort_vehicles_by'];
		}

		if ( isset( $input['sort_vehicles_order'] ) )
		{
			$sanitary_values['sort_vehicles_order'] = $input['sort_vehicles_order'];
		}

		if( is_array( $input['additional_listings_pages'] ) )
		{
			/**
			 * array_values() re-indexes the array starting at zero in case the
			 * first rule was deleted and index 0 doesn't exist.
			 */
			$sanitary_values['additional_listings_pages'] = array_values( $input['additional_listings_pages'] );
			/**
			 * This feature doesn't work when two rules have the same URL path.
			 * Drop any duplicates. Also reject any invalid rules.
			 */
			$url_paths = array();
			$unique_rules = array();
			foreach( $sanitary_values['additional_listings_pages'] as $additional_listing )
			{
				//Is this even a valid rule?
				if( ! Inventory_Presser_Additional_Listings_Pages::is_valid_rule( $additional_listing ) )
				{
					//No
					continue;
				}

				if( in_array( $additional_listing['url_path'], $url_paths ) )
				{
					//sorry!
					continue;
				}
				$unique_rules[] = $additional_listing;
				$url_paths[] = $additional_listing['url_path'];
			}
			$sanitary_values['additional_listings_pages'] = $unique_rules;
		}

		return apply_filters( 'invp_options_page_sanitized_values', $sanitary_values, $input );
	}