Inventory_Presser_Admin_Options::sanitize_options( array $input )

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


Parameters Parameters

$input

(array) (Required) Array of submitted settings page values.


Top ↑

Return Return

(array)


Top ↑

Source Source

File: includes/admin/class-admin-options.php

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

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

		/**
		 * Backwards compatibility. No s. Will arrive when 14.6.0 and
		 * older-saved settings are saved on newer versions.
		 */
		if ( isset( $input['additional_listings_page'] ) ) {
			$sanitary_values['additional_listings_page'] = filter_var( $input['additional_listings_page'], FILTER_VALIDATE_BOOLEAN );
		}

		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 ( ! empty( $input['additional_listings_pages'] )
			&& 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;
				}

				// Ignore the operator and comparison value if there is no key.
				if ( '' === $additional_listing['key'] ) {
					$additional_listing['operator'] = '';
					$additional_listing['value']    = '';
				}

				/**
				 * Convert the active toggle to a real boolean. If a pre-14.6.0
				 * setting value is still set, this is where we convert all
				 * additional listings pages to active.
				 */
				$additional_listing['active'] = isset( $additional_listing['active'] )
					|| isset( $sanitary_values['additional_listings_page'] ); // No s.

				if ( in_array( $additional_listing['url_path'], $url_paths, true ) ) {
					// 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 );
	}