| Server IP : 104.21.74.147 / Your IP : 216.73.217.154 Web Server : nginx/1.24.0 System : Linux wordpress-sites 6.8.0-134-generic #134-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 26 18:43:11 UTC 2026 x86_64 User : www-data ( 33) PHP Version : 8.1.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/rebeccaone.com/wp-content/plugins/envira-gallery/src/Utils/ |
Upload File : |
<?php
/**
* Sanitization utility functions for Envira Gallery.
*
* @since 1.13.2
*
* @package Envira_Gallery
* @author Envira Gallery Team <[email protected]>
*/
namespace Envira\Utils;
/**
* Sanitize_Utils class for common sanitization operations.
*
* @since 1.13.2
*/
class Sanitize_Utils {
/**
* Sanitizes a value against an allowlist of valid values.
*
* This is a generic sanitization helper that validates input against a list of allowed values.
* It's designed to prevent XSS attacks by ensuring only known-safe values are returned.
*
* Security Note: When the allowlist is generated via apply_filters, third-party code extending
* those filters must ensure added values are properly sanitized to maintain security.
*
* @since 1.13.2
*
* @param mixed $value The value to sanitize (will be converted to string).
* @param array $valid_values Array of valid values to check against.
* @param string $default_value Default value to return if validation fails.
* @param callable $sanitize_callback Optional. Callback function to sanitize the value before validation.
* Defaults to sanitize_text_field.
* @return string Sanitized value from the allowlist, or default if invalid.
*/
public static function sanitize_against_allowlist( $value, $valid_values, $default_value, $sanitize_callback = null ) {
// Type validation: ensure value can be converted to string
// Arrays, objects, resources cannot be safely converted and should fail validation
if ( is_array( $value ) || is_object( $value ) || is_resource( $value ) ) {
return $default_value;
}
// Handle null values
if ( null === $value ) {
return $default_value;
}
// Convert to string (handles int, float, bool safely)
$value = (string) $value;
// Ensure the sanitize callback is callable; fall back to sanitize_text_field if not.
if ( ! is_callable( $sanitize_callback ) ) {
$sanitize_callback = 'sanitize_text_field';
}
// Sanitize the input - remove any HTML tags and trim whitespace
$sanitized_value = call_user_func( $sanitize_callback, trim( $value ) );
// Check if value is in the list of valid values (strict comparison for security)
if ( in_array( $sanitized_value, $valid_values, true ) ) {
return $sanitized_value;
}
// Return default value if validation fails
return $default_value;
}
/**
* Extracts 'value' field from an array of arrays using wp_list_pluck.
*
* @since 1.13.2
*
* @param array $items Array of arrays containing 'value' keys.
* @return array Array of extracted values.
*/
public static function extract_values( $items ) {
return wp_list_pluck( $items, 'value' );
}
}