HEX
Server: Apache
System: Linux vps-cdc32557.vps.ovh.ca 5.15.0-156-generic #166-Ubuntu SMP Sat Aug 9 00:02:46 UTC 2025 x86_64
User: hanode (1017)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /home/hanode/public_html/wp-content/plugins/sitepress-multilingual-cms/inc/functions-sanitation.php
<?php
/**
 * @param string $input
 * @param string $default_if_invalid
 *
 * @return string
 */
function wpml_sanitize_hex_color( $input, $default_if_invalid = '' ) {
	$input  = sanitize_text_field( $input );
	$result = $input;
	if ( ! is_string( $input ) || ! wpml_is_valid_hex_color( $input ) ) {
		$result = $default_if_invalid;
	}

	return $result;
}

function wpml_sanitize_hex_color_array( $input, $default_if_invalid = '', $bypass_non_strings = true, $recursive = false ) {
	$result = $input;
	if ( is_array( $input ) ) {
		$result = array();
		foreach ( $input as $key => $value ) {
			if ( is_array( $value ) && $recursive ) {
				$result[ $key ] = wpml_sanitize_hex_color_array( $value, $default_if_invalid, $recursive );
			} elseif ( is_string( $value ) ) {
				$result[ $key ] = wpml_sanitize_hex_color( $value, $default_if_invalid );
			} elseif ( $bypass_non_strings ) {
				$result[ $key ] = $value;
			}
		}
	}

	return $result;
}

/**
 * @param string|array $input
 *
 * @return bool
 */
function wpml_is_valid_hex_color( $input ) {
	if (
		'transparent' === $input ||
		( is_string( $input ) && preg_match( '/' . wpml_get_valid_hex_color_pattern() . '/i', $input ) )
	) {
		$is_valid = true;
	} else {
		$try_rgb2hex = is_array( $input ) ? wpml_rgb_to_hex( $input ) : false;
		$is_valid    = $try_rgb2hex ? preg_match( '/' . wpml_get_valid_hex_color_pattern() . '/i', $try_rgb2hex ) : false;
	}

	return $is_valid;
}

function wpml_get_valid_hex_color_pattern() {
	return '(^#[a-fA-F0-9]{6}$)|(^#[a-fA-F0-9]{3}$)';
}

/**
 * Convert RGB color code to HEX code.
 *
 * @param array $rgb
 *
 * @return string|false
 */
function wpml_rgb_to_hex( $rgb ) {
	if ( ! is_array( $rgb ) || count( $rgb ) < 3 ) {
		return false;
	}

	$hex  = '#';
	$hex .= str_pad( dechex( $rgb[0] ), 2, '0', STR_PAD_LEFT );
	$hex .= str_pad( dechex( $rgb[1] ), 2, '0', STR_PAD_LEFT );
	$hex .= str_pad( dechex( $rgb[2] ), 2, '0', STR_PAD_LEFT );

	return $hex;
}